import { SidetreeDocumentModel } from '../operations/types' ; import { writeFixture } from '../test/util' ; import { toKeyPair , computeDidUniqueSuffix , LocalSigner , operations } from '..' ; import { wallet } from '@sidetree/test-vectors' ; const WRITE_FIXTURE_TO_DISK = true ; jest . setTimeout ( 10 * 1000 ) ; it ( 'can generate test fixture' , async ( ) => { const fixture = { operations : [ ] } ; for ( let i = 0 ; i < wallet . mnemonic . length ; i ++ ) { const { mnemonic } = wallet . mnemonic [ i ] ; const keyType = 'secp256k1' ; const key0 = await toKeyPair ( mnemonic , 0 , keyType ) ; const key1 = await toKeyPair ( mnemonic , 1 , keyType ) ; const key2 = await toKeyPair ( mnemonic , 2 , keyType ) ; const document = { publicKeys : [ { id : key0 . id . split ( '#' ) . pop ( ) , type : key0 . type , publicKeyJwk : key0 . publicKeyJwk , purposes : [ 'authentication' , 'assertionMethod' , 'keyAgreement' ] } , ] , services : [ { id : 'example-service' , type : 'ExampleService' , serviceEndpoint : 'https://example.com' } , ] } as any ; const recoveryKey = key1 . publicKeyJwk ; const updateKey = key2 . publicKeyJwk ; const input1 = { recoveryKey , updateKey , document } ; const op0 = await operations . create ( input1 ) ; const didUniqueSuffix = computeDidUniqueSuffix ( op0 . suffixData ) ; const key3 = await toKeyPair ( mnemonic , 3 , keyType ) ; const key4 = await toKeyPair ( mnemonic , 4 , keyType ) ; const input2 = { didSuffix : didUniqueSuffix , updatePublicKey : key2 . publicKeyJwk , nextUpdatePublicKey : key4 . publicKeyJwk , servicesToAdd : [ { id : 'example-service-2' , type : 'ExampleService' , serviceEndpoint : 'https://2.example.com' } , ] , idsOfServicesToRemove : [ 'example-service' ] , publicKeysToAdd : [ { id : key3 . id . split ( '#' ) . pop ( ) , type : key3 . type , publicKeyJwk : key3 . publicKeyJwk , purposes : [ 'authentication' , 'assertionMethod' , 'keyAgreement' ] } , ] , idsOfPublicKeysToRemove : [ key0 . id . split ( '#' ) . pop ( ) ] , signer : LocalSigner . create ( key2 . privateKeyJwk ) } ; const op1 = await operations . update ( input2 ) ; const key5 = await toKeyPair ( mnemonic , 5 , keyType ) ; const key6 = await toKeyPair ( mnemonic , 6 , keyType ) ; const key7 = await toKeyPair ( mnemonic , 7 , keyType ) ; const recoverDocument = { publicKeys : [ { id : key7 . id . split ( '#' ) . pop ( ) , type : key7 . type , publicKeyJwk : key7 . publicKeyJwk , purposes : [ 'authentication' , 'assertionMethod' , 'keyAgreement' ] } as any , ] , services : [ { id : 'example-service-3' , type : 'ExampleService' , serviceEndpoint : 'https://3.example.com' } , ] } ; const op2 = await operations . recover ( { didSuffix : didUniqueSuffix , recoveryPublicKey : key1 . publicKeyJwk , nextRecoveryPublicKey : key5 . publicKeyJwk , nextUpdatePublicKey : key6 . publicKeyJwk , document : recoverDocument , signer : LocalSigner . create ( key1 . privateKeyJwk ) } ) ; const op3 = await operations . deactivate ( { didSuffix : didUniqueSuffix , recoveryPublicKey : key5 . publicKeyJwk , signer : LocalSigner . create ( key5 . privateKeyJwk ) } ) ; fixture . operations . push ( { mnemonic , didUniqueSuffix , op0 , op1 , op2 , op3 } ) ; } expect ( fixture . operations ) . toEqual ( wallet . operations ) ; if ( WRITE_FIXTURE_TO_DISK ) { writeFixture ( 'v1-secp256k1-operations.json' , fixture ) ; } } ) ;