import { signDocument , v3 } from "../../index" ; import { SUPPORTED_SIGNING_ALGORITHM } from "../../shared/@types/sign" ; import rawWrappedDocumentV3 from "../../../test/fixtures/v3/did-wrapped.json" ; import { Wallet } from "ethers" ; const wrappedDocumentV3 = rawWrappedDocumentV3 as v3 . WrappedDocument ; describe ( "v3" , ( ) => { it ( "should sign a document" , async ( ) => { const { proof } = await signDocument ( wrappedDocumentV3 , SUPPORTED_SIGNING_ALGORITHM . Secp256k1VerificationKey2018 , { public : "did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89#controller" , private : "0x497c85ed89f1874ba37532d1e33519aba15bd533cdcb90774cc497bfe3cde655" , } ) ; expect ( Object . keys ( proof ) . length ) . toBe ( 9 ) ; expect ( proof . key ) . toBe ( "did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89#controller" ) ; expect ( proof . signature ) . toBe ( "0x3ce62bb2d6a68f15fabe653dbb71edfaf1e2a00c71c98f71801f3a7438ae477a4cf3dbefaff9359b2d2b97473909ba4b19e9d2ac0c735cec926da0d1025af07b1c" ) ; } ) ; it ( "should sign a document with a wallet" , async ( ) => { const wallet = Wallet . fromMnemonic ( "tourist quality multiply denial diary height funny calm disease buddy speed gold" ) ; const { proof } = await signDocument ( wrappedDocumentV3 , SUPPORTED_SIGNING_ALGORITHM . Secp256k1VerificationKey2018 , wallet ) ; expect ( Object . keys ( proof ) . length ) . toBe ( 9 ) ; expect ( proof . key ) . toBe ( "did:ethr:0x906FB815De8976b1e38D9a4C1014a3acE16Ce53C#controller" ) ; expect ( proof . signature ) . toBe ( "0xdfb8f7b40933d90004d0a94261f0af573702c0040f727ed813273284ef7329cd4420095b28f7d768866556be9d95fd8b89e0ee2bd1f9c589464d3b16d1247d651c" ) ; } ) ; it ( "should throw error if a document was previously signed" , async ( ) => { const signedDocument = await signDocument ( wrappedDocumentV3 , SUPPORTED_SIGNING_ALGORITHM . Secp256k1VerificationKey2018 , { public : "did:ethr:0xb6De3744E1259e1aB692f5a277f053B79429c5a2#controller" , private : "0x812269266b34d2919f737daf22db95f02642f8cdc0ca673bf3f701599f4971f5" , } ) ; await expect ( signDocument ( signedDocument , SUPPORTED_SIGNING_ALGORITHM . Secp256k1VerificationKey2018 , { public : "did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89#controller" , private : "0x497c85ed89f1874ba37532d1e33519aba15bd533cdcb90774cc497bfe3cde655" , } ) ) . rejects . toThrowErrorMatchingInlineSnapshot ( `"Document has been signed"` ) ; } ) ; it ( "should throw error if a key or signer is invalid" , async ( ) => { await expect ( signDocument ( wrappedDocumentV3 , SUPPORTED_SIGNING_ALGORITHM . Secp256k1VerificationKey2018 , { } ) ) . rejects . toThrowErrorMatchingInlineSnapshot ( `"Either a keypair or ethers.js Signer must be provided"` ) ; } ) ; } ) ;