|
| 1 | +import { LitCurve } from '@lit-protocol/constants'; |
| 2 | +import { SigningChainSchema } from '@lit-protocol/schemas'; |
| 3 | +import { z } from 'zod'; |
| 4 | +import { createEnvVars } from '../helper/createEnvVars'; |
| 5 | +import { createTestAccount } from '../helper/createTestAccount'; |
| 6 | +import { createTestEnv } from '../helper/createTestEnv'; |
| 7 | + |
| 8 | +type SigningChain = z.infer<typeof SigningChainSchema>; |
| 9 | + |
| 10 | +type SchemeUnderTest = { |
| 11 | + scheme: LitCurve; |
| 12 | + chain: SigningChain; |
| 13 | +}; |
| 14 | + |
| 15 | +const SIGNING_MATRIX: SchemeUnderTest[] = [ |
| 16 | + // ECDSA variants |
| 17 | + { scheme: 'EcdsaK256Sha256', chain: 'ethereum' }, |
| 18 | + { scheme: 'EcdsaP256Sha256', chain: 'ethereum' }, |
| 19 | + { scheme: 'EcdsaP384Sha384', chain: 'ethereum' }, |
| 20 | + // Schnorr over secp256k1 (Bitcoin / Taproot) |
| 21 | + { scheme: 'SchnorrK256Sha256', chain: 'bitcoin' }, |
| 22 | + { scheme: 'SchnorrK256Taproot', chain: 'bitcoin' }, |
| 23 | + // Schnorr over NIST curves |
| 24 | + { scheme: 'SchnorrP256Sha256', chain: 'cosmos' }, |
| 25 | + { scheme: 'SchnorrP384Sha384', chain: 'cosmos' }, |
| 26 | + // EdDSA-style curves |
| 27 | + { scheme: 'SchnorrEd25519Sha512', chain: 'solana' }, |
| 28 | + { scheme: 'SchnorrEd448Shake256', chain: 'solana' }, |
| 29 | + // ZK / privacy-focused curves |
| 30 | + { scheme: 'SchnorrRistretto25519Sha512', chain: 'solana' }, |
| 31 | + { scheme: 'SchnorrRedJubjubBlake2b512', chain: 'solana' }, |
| 32 | + { scheme: 'SchnorrRedDecaf377Blake2b512', chain: 'solana' }, |
| 33 | + { scheme: 'SchnorrkelSubstrate', chain: 'solana' }, |
| 34 | +]; |
| 35 | + |
| 36 | +export function registerSigningSchemesTicketSuite() { |
| 37 | + describe('pkp signing schemes', () => { |
| 38 | + let testEnv: Awaited<ReturnType<typeof createTestEnv>>; |
| 39 | + let signerAccount: Awaited<ReturnType<typeof createTestAccount>>; |
| 40 | + |
| 41 | + beforeAll(async () => { |
| 42 | + const envVars = createEnvVars(); |
| 43 | + testEnv = await createTestEnv(envVars); |
| 44 | + signerAccount = await createTestAccount(testEnv, { |
| 45 | + label: 'Signing Schemes', |
| 46 | + fundAccount: true, |
| 47 | + fundLedger: true, |
| 48 | + hasEoaAuthContext: true, |
| 49 | + hasPKP: true, |
| 50 | + fundPKP: true, |
| 51 | + fundPKPLedger: true, |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it.each(SIGNING_MATRIX)( |
| 56 | + 'should sign using %s', |
| 57 | + async ({ scheme, chain }) => { |
| 58 | + if (!signerAccount.pkp?.pubkey) { |
| 59 | + throw new Error('Signer PKP was not initialized'); |
| 60 | + } |
| 61 | + if (!signerAccount.eoaAuthContext) { |
| 62 | + throw new Error('Signer account is missing an EOA auth context'); |
| 63 | + } |
| 64 | + |
| 65 | + const toSign = new TextEncoder().encode( |
| 66 | + `Lit signing e2e test using ${scheme}` |
| 67 | + ); |
| 68 | + |
| 69 | + const signature = await testEnv.litClient.chain.raw.pkpSign({ |
| 70 | + authContext: signerAccount.eoaAuthContext, |
| 71 | + pubKey: signerAccount.pkp.pubkey, |
| 72 | + signingScheme: scheme, |
| 73 | + chain, |
| 74 | + toSign, |
| 75 | + userMaxPrice: 100_000_000_000_000_000n, // 0.1 ETH in wei to clear threshold comfortably |
| 76 | + }); |
| 77 | + |
| 78 | + expect(signature.signature).toBeTruthy(); |
| 79 | + expect(signature.sigType).toBe(scheme); |
| 80 | + } |
| 81 | + ); |
| 82 | + }); |
| 83 | +} |
0 commit comments