@aptos-labs/ts-sdk 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.d.ts +1131 -989
- package/dist/browser/index.global.js +30 -30
- package/dist/browser/index.global.js.map +1 -1
- package/dist/common/index.d.ts +1131 -989
- package/dist/common/index.js +25 -25
- package/dist/common/index.js.map +1 -1
- package/dist/esm/api/account.d.mts +12 -6
- package/dist/esm/api/account.mjs +1 -1
- package/dist/esm/api/ans.d.mts +11 -12
- package/dist/esm/api/ans.mjs +1 -1
- package/dist/esm/api/aptos.d.mts +13 -14
- package/dist/esm/api/aptos.mjs +1 -1
- package/dist/esm/api/aptosConfig.mjs +1 -1
- package/dist/esm/api/coin.d.mts +13 -13
- package/dist/esm/api/coin.mjs +1 -1
- package/dist/esm/api/digitalAsset.d.mts +20 -10
- package/dist/esm/api/digitalAsset.mjs +1 -1
- package/dist/esm/api/event.mjs +1 -1
- package/dist/esm/api/faucet.mjs +1 -1
- package/dist/esm/api/fungibleAsset.d.mts +9 -10
- package/dist/esm/api/fungibleAsset.mjs +1 -1
- package/dist/esm/api/general.mjs +1 -1
- package/dist/esm/api/index.d.mts +13 -14
- package/dist/esm/api/index.mjs +1 -1
- package/dist/esm/api/staking.mjs +1 -1
- package/dist/esm/api/transaction.d.mts +5 -6
- package/dist/esm/api/transaction.mjs +1 -1
- package/dist/esm/api/transactionSubmission/build.d.mts +8 -8
- package/dist/esm/api/transactionSubmission/build.mjs +1 -1
- package/dist/esm/api/transactionSubmission/management.d.mts +11 -12
- package/dist/esm/api/transactionSubmission/management.mjs +1 -1
- package/dist/esm/api/transactionSubmission/sign.d.mts +11 -12
- package/dist/esm/api/transactionSubmission/sign.mjs +1 -1
- package/dist/esm/api/transactionSubmission/sign.mjs.map +1 -1
- package/dist/esm/api/transactionSubmission/simulate.d.mts +11 -11
- package/dist/esm/api/transactionSubmission/simulate.mjs +1 -1
- package/dist/esm/api/transactionSubmission/submit.d.mts +6 -6
- package/dist/esm/api/transactionSubmission/submit.mjs +1 -1
- package/dist/esm/api/utils.mjs +1 -1
- package/dist/esm/{chunk-S64WKSMI.mjs → chunk-2E2JOGE5.mjs} +2 -2
- package/dist/esm/chunk-3EUOBVCT.mjs +2 -0
- package/dist/esm/{chunk-SRZTA6QH.mjs.map → chunk-3EUOBVCT.mjs.map} +1 -1
- package/dist/esm/{chunk-4OI7MPFH.mjs → chunk-52RTAMN7.mjs} +2 -2
- package/dist/esm/chunk-7BDYKJXX.mjs +2 -0
- package/dist/esm/chunk-7BDYKJXX.mjs.map +1 -0
- package/dist/esm/{chunk-R56OJ4XC.mjs → chunk-7U36LMP4.mjs} +2 -2
- package/dist/esm/{chunk-NWRKJFHV.mjs → chunk-ARIC32W7.mjs} +2 -2
- package/dist/esm/{chunk-SPOHAEHR.mjs → chunk-B7M3OWHV.mjs} +2 -2
- package/dist/esm/{chunk-6SRENFWH.mjs → chunk-BBUAAJRA.mjs} +2 -2
- package/dist/esm/chunk-C3HM7HQP.mjs +2 -0
- package/dist/esm/chunk-C3HM7HQP.mjs.map +1 -0
- package/dist/esm/{chunk-PMWH5IGI.mjs → chunk-CHA5DSSD.mjs} +2 -2
- package/dist/esm/chunk-DE5OOOVY.mjs +2 -0
- package/dist/esm/{chunk-MEPX7Z2Z.mjs.map → chunk-DE5OOOVY.mjs.map} +1 -1
- package/dist/esm/{chunk-JJ6Y35DF.mjs → chunk-DGOT2VR5.mjs} +2 -2
- package/dist/esm/{chunk-EUHPML5E.mjs → chunk-EF2F7NWO.mjs} +2 -2
- package/dist/esm/{chunk-FRLPX47J.mjs → chunk-EQZ757ES.mjs} +2 -2
- package/dist/esm/{chunk-Y4AKS4CY.mjs → chunk-F67Y7YH6.mjs} +2 -2
- package/dist/esm/{chunk-KJGQ4ILY.mjs → chunk-FVMVV4V3.mjs} +2 -2
- package/dist/esm/chunk-FWDKABRW.mjs +2 -0
- package/dist/esm/chunk-FWDKABRW.mjs.map +1 -0
- package/dist/esm/chunk-G62HQC77.mjs +2 -0
- package/dist/esm/chunk-G62HQC77.mjs.map +1 -0
- package/dist/esm/{chunk-V2FPYAK7.mjs → chunk-GQOOXOTN.mjs} +2 -2
- package/dist/esm/chunk-GRJJBGHT.mjs +2 -0
- package/dist/esm/chunk-GRJJBGHT.mjs.map +1 -0
- package/dist/esm/chunk-HEPV52CH.mjs +2 -0
- package/dist/esm/chunk-HEPV52CH.mjs.map +1 -0
- package/dist/esm/{chunk-GD4ULEBC.mjs → chunk-I3TCHVQQ.mjs} +2 -2
- package/dist/esm/{chunk-JQVT2K7G.mjs → chunk-ILJWEPDW.mjs} +2 -2
- package/dist/esm/{chunk-Q3HAJVCM.mjs → chunk-INORE66K.mjs} +2 -2
- package/dist/esm/{chunk-PIXE7MN5.mjs → chunk-J6MWD4XN.mjs} +2 -2
- package/dist/esm/{chunk-ENKMOALS.mjs → chunk-JEHR6GKW.mjs} +2 -2
- package/dist/esm/chunk-JEHR6GKW.mjs.map +1 -0
- package/dist/esm/chunk-KUX6GQ2E.mjs +1 -0
- package/dist/esm/{chunk-ENDUXRTK.mjs → chunk-KWJTVJ7C.mjs} +2 -2
- package/dist/esm/{chunk-W4UDMBMU.mjs → chunk-LLL2LFYH.mjs} +2 -2
- package/dist/esm/chunk-LMXP3JUU.mjs +2 -0
- package/dist/esm/chunk-LMXP3JUU.mjs.map +1 -0
- package/dist/esm/{chunk-2WFMD6C6.mjs → chunk-N65SOKJQ.mjs} +2 -2
- package/dist/esm/{chunk-Q5HK3U64.mjs → chunk-NL3XVNS5.mjs} +2 -2
- package/dist/esm/{chunk-M3WNE7MU.mjs → chunk-NURFZOR4.mjs} +2 -2
- package/dist/esm/{chunk-AFPJ2XXN.mjs → chunk-OG56TYZE.mjs} +2 -2
- package/dist/esm/chunk-Q6WOHF4A.mjs +2 -0
- package/dist/esm/chunk-Q6WOHF4A.mjs.map +1 -0
- package/dist/esm/chunk-QA4XWNIH.mjs +2 -0
- package/dist/esm/chunk-QA4XWNIH.mjs.map +1 -0
- package/dist/esm/chunk-QE4ASJ5K.mjs +1 -0
- package/dist/esm/chunk-QR72RXBS.mjs +2 -0
- package/dist/esm/chunk-QR72RXBS.mjs.map +1 -0
- package/dist/esm/{chunk-XBVORX5O.mjs → chunk-R4VJDSIP.mjs} +2 -2
- package/dist/esm/{chunk-O57QZZF2.mjs → chunk-S2F6CSH4.mjs} +2 -2
- package/dist/esm/chunk-S2F6CSH4.mjs.map +1 -0
- package/dist/esm/{chunk-2H5Z5EHH.mjs → chunk-TN5BUH4F.mjs} +2 -2
- package/dist/esm/chunk-TNVR7SNR.mjs +2 -0
- package/dist/esm/chunk-TNVR7SNR.mjs.map +1 -0
- package/dist/esm/chunk-TX7UK75Q.mjs +2 -0
- package/dist/esm/chunk-TX7UK75Q.mjs.map +1 -0
- package/dist/esm/{chunk-VPQ46CAO.mjs → chunk-UIUSDBCL.mjs} +2 -2
- package/dist/esm/{chunk-4M46AWXX.mjs → chunk-UMLDKLDL.mjs} +2 -2
- package/dist/esm/chunk-UVSRX4SV.mjs +1 -0
- package/dist/esm/{chunk-2DNPRIS5.mjs → chunk-VEVBHH3M.mjs} +2 -2
- package/dist/esm/{chunk-QGIJNA37.mjs → chunk-VMXBMAYK.mjs} +2 -2
- package/dist/esm/chunk-WKUXBIYB.mjs +2 -0
- package/dist/esm/chunk-WKUXBIYB.mjs.map +1 -0
- package/dist/esm/chunk-WME5D6YR.mjs +2 -0
- package/dist/esm/chunk-WME5D6YR.mjs.map +1 -0
- package/dist/esm/chunk-WTHNSNAX.mjs +2 -0
- package/dist/esm/chunk-WTHNSNAX.mjs.map +1 -0
- package/dist/esm/{chunk-GD5TZLBF.mjs → chunk-X5C3LYI7.mjs} +2 -2
- package/dist/esm/chunk-XKD7W5NO.mjs +2 -0
- package/dist/esm/{chunk-XZYPAQCU.mjs.map → chunk-XKD7W5NO.mjs.map} +1 -1
- package/dist/esm/{chunk-QRQAR6XO.mjs → chunk-XTPFQ4MH.mjs} +2 -2
- package/dist/esm/{chunk-LATJGGVX.mjs → chunk-Y5AJLNUD.mjs} +2 -2
- package/dist/esm/chunk-YDAA4RG4.mjs +2 -0
- package/dist/esm/chunk-YDAA4RG4.mjs.map +1 -0
- package/dist/esm/{chunk-VKZCIGKY.mjs → chunk-YR2R3LW4.mjs} +2 -2
- package/dist/esm/chunk-YZZO6VDC.mjs +2 -0
- package/dist/esm/chunk-YZZO6VDC.mjs.map +1 -0
- package/dist/esm/client/core.mjs +1 -1
- package/dist/esm/client/get.mjs +1 -1
- package/dist/esm/client/index.mjs +1 -1
- package/dist/esm/client/post.mjs +1 -1
- package/dist/esm/core/account/Account.d.mts +20 -0
- package/dist/esm/core/account/Account.mjs +2 -0
- package/dist/esm/core/account/Ed25519Account.d.mts +20 -0
- package/dist/esm/core/account/Ed25519Account.mjs +2 -0
- package/dist/esm/core/account/SingleKeyAccount.d.mts +20 -0
- package/dist/esm/core/account/SingleKeyAccount.mjs +2 -0
- package/dist/esm/core/account/SingleKeyAccount.mjs.map +1 -0
- package/dist/esm/core/account/index.d.mts +305 -0
- package/dist/esm/core/account/index.mjs +2 -0
- package/dist/esm/core/account/index.mjs.map +1 -0
- package/dist/esm/core/authenticationKey.d.mts +7 -68
- package/dist/esm/core/authenticationKey.mjs +1 -1
- package/dist/esm/core/crypto/ed25519.d.mts +49 -61
- package/dist/esm/core/crypto/ed25519.mjs +1 -1
- package/dist/esm/core/crypto/index.d.mts +9 -6
- package/dist/esm/core/crypto/index.mjs +1 -1
- package/dist/esm/core/crypto/multiEd25519.d.mts +17 -14
- package/dist/esm/core/crypto/multiEd25519.mjs +1 -1
- package/dist/esm/core/crypto/multiKey.d.mts +70 -17
- package/dist/esm/core/crypto/multiKey.mjs +1 -1
- package/dist/esm/core/crypto/privateKey.d.mts +35 -0
- package/dist/esm/core/crypto/privateKey.mjs +2 -0
- package/dist/esm/core/crypto/privateKey.mjs.map +1 -0
- package/dist/esm/core/crypto/publicKey.d.mts +13 -0
- package/dist/esm/core/crypto/publicKey.mjs +2 -0
- package/dist/esm/core/crypto/publicKey.mjs.map +1 -0
- package/dist/esm/core/crypto/secp256k1.d.mts +43 -67
- package/dist/esm/core/crypto/secp256k1.mjs +1 -1
- package/dist/esm/core/crypto/signature.d.mts +28 -0
- package/dist/esm/core/crypto/signature.mjs +2 -0
- package/dist/esm/core/crypto/signature.mjs.map +1 -0
- package/dist/esm/core/crypto/singleKey.d.mts +68 -0
- package/dist/esm/core/crypto/singleKey.mjs +2 -0
- package/dist/esm/core/crypto/singleKey.mjs.map +1 -0
- package/dist/esm/core/index.d.mts +9 -8
- package/dist/esm/core/index.mjs +1 -1
- package/dist/esm/index.d.mts +8 -8
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/internal/account.d.mts +10 -4
- package/dist/esm/internal/account.mjs +1 -1
- package/dist/esm/internal/ans.d.mts +11 -12
- package/dist/esm/internal/ans.mjs +1 -1
- package/dist/esm/internal/coin.d.mts +12 -12
- package/dist/esm/internal/coin.mjs +1 -1
- package/dist/esm/internal/digitalAsset.d.mts +17 -14
- package/dist/esm/internal/digitalAsset.mjs +1 -1
- package/dist/esm/internal/event.d.mts +2 -2
- package/dist/esm/internal/event.mjs +1 -1
- package/dist/esm/internal/faucet.d.mts +4 -4
- package/dist/esm/internal/faucet.mjs +1 -1
- package/dist/esm/internal/fungibleAsset.d.mts +10 -11
- package/dist/esm/internal/fungibleAsset.mjs +1 -1
- package/dist/esm/internal/general.mjs +1 -1
- package/dist/esm/internal/staking.d.mts +3 -3
- package/dist/esm/internal/staking.mjs +1 -1
- package/dist/esm/internal/transaction.mjs +1 -1
- package/dist/esm/internal/transactionSubmission.d.mts +12 -13
- package/dist/esm/internal/transactionSubmission.mjs +1 -1
- package/dist/esm/publicKey-lq5djCIY.d.mts +113 -0
- package/dist/esm/transactions/authenticator/account.d.mts +6 -4
- package/dist/esm/transactions/authenticator/account.mjs +1 -1
- package/dist/esm/transactions/authenticator/index.d.mts +6 -6
- package/dist/esm/transactions/authenticator/index.mjs +1 -1
- package/dist/esm/transactions/authenticator/transaction.d.mts +5 -5
- package/dist/esm/transactions/authenticator/transaction.mjs +1 -1
- package/dist/esm/transactions/index.d.mts +6 -7
- package/dist/esm/transactions/index.mjs +1 -1
- package/dist/esm/transactions/instances/index.d.mts +4 -4
- package/dist/esm/transactions/instances/index.mjs +1 -1
- package/dist/esm/transactions/instances/moduleId.d.mts +1 -1
- package/dist/esm/transactions/instances/moduleId.mjs +1 -1
- package/dist/esm/transactions/instances/rawTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/rotationProofChallenge.d.mts +2 -1
- package/dist/esm/transactions/instances/rotationProofChallenge.mjs +1 -1
- package/dist/esm/transactions/instances/signedTransaction.d.mts +8 -8
- package/dist/esm/transactions/instances/signedTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/transactionPayload.d.mts +1 -1
- package/dist/esm/transactions/instances/transactionPayload.mjs +1 -1
- package/dist/esm/transactions/management/accountSequenceNumber.d.mts +11 -5
- package/dist/esm/transactions/management/accountSequenceNumber.mjs +1 -1
- package/dist/esm/transactions/management/index.d.mts +11 -12
- package/dist/esm/transactions/management/index.mjs +1 -1
- package/dist/esm/transactions/management/transactionWorker.d.mts +11 -12
- package/dist/esm/transactions/management/transactionWorker.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/helpers.d.mts +10 -10
- package/dist/esm/transactions/transactionBuilder/helpers.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/index.d.mts +9 -10
- package/dist/esm/transactions/transactionBuilder/index.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/remoteAbi.d.mts +8 -8
- package/dist/esm/transactions/transactionBuilder/remoteAbi.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/transactionBuilder.d.mts +9 -10
- package/dist/esm/transactions/transactionBuilder/transactionBuilder.mjs +1 -1
- package/dist/esm/transactions/typeTag/index.mjs +1 -1
- package/dist/esm/transactions/typeTag/parser.mjs +1 -1
- package/dist/esm/transactions/types.d.mts +9 -9
- package/dist/esm/utils/const.d.mts +1 -2
- package/dist/esm/utils/const.mjs +1 -1
- package/dist/esm/utils/index.d.mts +1 -1
- package/dist/esm/utils/index.mjs +1 -1
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
- package/src/api/aptosConfig.ts +2 -2
- package/src/api/digitalAsset.ts +20 -0
- package/src/core/account/Account.ts +245 -0
- package/src/core/account/Ed25519Account.ts +88 -0
- package/src/core/account/SingleKeyAccount.ts +120 -0
- package/src/core/account/index.ts +3 -0
- package/src/core/authenticationKey.ts +18 -52
- package/src/core/crypto/ed25519.ts +118 -104
- package/src/core/crypto/index.ts +6 -5
- package/src/core/crypto/multiEd25519.ts +98 -44
- package/src/core/crypto/multiKey.ts +192 -34
- package/src/core/crypto/privateKey.ts +25 -0
- package/src/core/crypto/publicKey.ts +52 -0
- package/src/core/crypto/secp256k1.ts +108 -111
- package/src/core/crypto/signature.ts +46 -0
- package/src/core/crypto/singleKey.ts +180 -0
- package/src/internal/account.ts +5 -3
- package/src/internal/digitalAsset.ts +26 -0
- package/src/transactions/authenticator/account.ts +1 -2
- package/src/transactions/instances/rotationProofChallenge.ts +1 -1
- package/src/transactions/transactionBuilder/transactionBuilder.ts +3 -21
- package/src/transactions/types.ts +1 -1
- package/src/utils/const.ts +0 -4
- package/src/version.ts +1 -1
- package/dist/esm/chunk-2QV6HI3M.mjs +0 -2
- package/dist/esm/chunk-2QV6HI3M.mjs.map +0 -1
- package/dist/esm/chunk-7IGH7N52.mjs +0 -2
- package/dist/esm/chunk-7IGH7N52.mjs.map +0 -1
- package/dist/esm/chunk-CCUD52OF.mjs +0 -2
- package/dist/esm/chunk-CCUD52OF.mjs.map +0 -1
- package/dist/esm/chunk-ENKMOALS.mjs.map +0 -1
- package/dist/esm/chunk-ERWQOVBF.mjs +0 -2
- package/dist/esm/chunk-ERWQOVBF.mjs.map +0 -1
- package/dist/esm/chunk-FBFMQZTM.mjs +0 -2
- package/dist/esm/chunk-FBFMQZTM.mjs.map +0 -1
- package/dist/esm/chunk-FP5DPRYL.mjs +0 -2
- package/dist/esm/chunk-FP5DPRYL.mjs.map +0 -1
- package/dist/esm/chunk-HHJBCGAQ.mjs +0 -2
- package/dist/esm/chunk-HHJBCGAQ.mjs.map +0 -1
- package/dist/esm/chunk-I7WRJY7K.mjs +0 -2
- package/dist/esm/chunk-I7WRJY7K.mjs.map +0 -1
- package/dist/esm/chunk-LHJSG5NE.mjs +0 -2
- package/dist/esm/chunk-LHJSG5NE.mjs.map +0 -1
- package/dist/esm/chunk-MEPX7Z2Z.mjs +0 -2
- package/dist/esm/chunk-O57QZZF2.mjs.map +0 -1
- package/dist/esm/chunk-S3FBGS3W.mjs +0 -2
- package/dist/esm/chunk-S3FBGS3W.mjs.map +0 -1
- package/dist/esm/chunk-SBMJNU2O.mjs +0 -2
- package/dist/esm/chunk-SBMJNU2O.mjs.map +0 -1
- package/dist/esm/chunk-SRZTA6QH.mjs +0 -2
- package/dist/esm/chunk-UCHGKGCF.mjs +0 -2
- package/dist/esm/chunk-UCHGKGCF.mjs.map +0 -1
- package/dist/esm/chunk-UIVJXLRM.mjs +0 -1
- package/dist/esm/chunk-V6JFR2CB.mjs +0 -2
- package/dist/esm/chunk-V6JFR2CB.mjs.map +0 -1
- package/dist/esm/chunk-XZYPAQCU.mjs +0 -2
- package/dist/esm/chunk-YL2EDK5M.mjs +0 -2
- package/dist/esm/chunk-YL2EDK5M.mjs.map +0 -1
- package/dist/esm/chunk-ZFIMVSCR.mjs +0 -2
- package/dist/esm/chunk-ZFIMVSCR.mjs.map +0 -1
- package/dist/esm/core/account.d.mts +0 -184
- package/dist/esm/core/account.mjs +0 -2
- package/dist/esm/core/crypto/anyPublicKey.d.mts +0 -59
- package/dist/esm/core/crypto/anyPublicKey.mjs +0 -2
- package/dist/esm/core/crypto/anySignature.d.mts +0 -31
- package/dist/esm/core/crypto/anySignature.mjs +0 -2
- package/dist/esm/core/crypto/asymmetricCrypto.d.mts +0 -74
- package/dist/esm/core/crypto/asymmetricCrypto.mjs +0 -2
- package/src/core/account.ts +0 -282
- package/src/core/crypto/anyPublicKey.ts +0 -92
- package/src/core/crypto/anySignature.ts +0 -56
- package/src/core/crypto/asymmetricCrypto.ts +0 -77
- /package/dist/esm/{chunk-S64WKSMI.mjs.map → chunk-2E2JOGE5.mjs.map} +0 -0
- /package/dist/esm/{chunk-4OI7MPFH.mjs.map → chunk-52RTAMN7.mjs.map} +0 -0
- /package/dist/esm/{chunk-R56OJ4XC.mjs.map → chunk-7U36LMP4.mjs.map} +0 -0
- /package/dist/esm/{chunk-NWRKJFHV.mjs.map → chunk-ARIC32W7.mjs.map} +0 -0
- /package/dist/esm/{chunk-SPOHAEHR.mjs.map → chunk-B7M3OWHV.mjs.map} +0 -0
- /package/dist/esm/{chunk-6SRENFWH.mjs.map → chunk-BBUAAJRA.mjs.map} +0 -0
- /package/dist/esm/{chunk-PMWH5IGI.mjs.map → chunk-CHA5DSSD.mjs.map} +0 -0
- /package/dist/esm/{chunk-JJ6Y35DF.mjs.map → chunk-DGOT2VR5.mjs.map} +0 -0
- /package/dist/esm/{chunk-EUHPML5E.mjs.map → chunk-EF2F7NWO.mjs.map} +0 -0
- /package/dist/esm/{chunk-FRLPX47J.mjs.map → chunk-EQZ757ES.mjs.map} +0 -0
- /package/dist/esm/{chunk-Y4AKS4CY.mjs.map → chunk-F67Y7YH6.mjs.map} +0 -0
- /package/dist/esm/{chunk-KJGQ4ILY.mjs.map → chunk-FVMVV4V3.mjs.map} +0 -0
- /package/dist/esm/{chunk-V2FPYAK7.mjs.map → chunk-GQOOXOTN.mjs.map} +0 -0
- /package/dist/esm/{chunk-GD4ULEBC.mjs.map → chunk-I3TCHVQQ.mjs.map} +0 -0
- /package/dist/esm/{chunk-JQVT2K7G.mjs.map → chunk-ILJWEPDW.mjs.map} +0 -0
- /package/dist/esm/{chunk-Q3HAJVCM.mjs.map → chunk-INORE66K.mjs.map} +0 -0
- /package/dist/esm/{chunk-PIXE7MN5.mjs.map → chunk-J6MWD4XN.mjs.map} +0 -0
- /package/dist/esm/{chunk-UIVJXLRM.mjs.map → chunk-KUX6GQ2E.mjs.map} +0 -0
- /package/dist/esm/{chunk-ENDUXRTK.mjs.map → chunk-KWJTVJ7C.mjs.map} +0 -0
- /package/dist/esm/{chunk-W4UDMBMU.mjs.map → chunk-LLL2LFYH.mjs.map} +0 -0
- /package/dist/esm/{chunk-2WFMD6C6.mjs.map → chunk-N65SOKJQ.mjs.map} +0 -0
- /package/dist/esm/{chunk-Q5HK3U64.mjs.map → chunk-NL3XVNS5.mjs.map} +0 -0
- /package/dist/esm/{chunk-M3WNE7MU.mjs.map → chunk-NURFZOR4.mjs.map} +0 -0
- /package/dist/esm/{chunk-AFPJ2XXN.mjs.map → chunk-OG56TYZE.mjs.map} +0 -0
- /package/dist/esm/{core/account.mjs.map → chunk-QE4ASJ5K.mjs.map} +0 -0
- /package/dist/esm/{chunk-XBVORX5O.mjs.map → chunk-R4VJDSIP.mjs.map} +0 -0
- /package/dist/esm/{chunk-2H5Z5EHH.mjs.map → chunk-TN5BUH4F.mjs.map} +0 -0
- /package/dist/esm/{chunk-VPQ46CAO.mjs.map → chunk-UIUSDBCL.mjs.map} +0 -0
- /package/dist/esm/{chunk-4M46AWXX.mjs.map → chunk-UMLDKLDL.mjs.map} +0 -0
- /package/dist/esm/{core/crypto/anyPublicKey.mjs.map → chunk-UVSRX4SV.mjs.map} +0 -0
- /package/dist/esm/{chunk-2DNPRIS5.mjs.map → chunk-VEVBHH3M.mjs.map} +0 -0
- /package/dist/esm/{chunk-QGIJNA37.mjs.map → chunk-VMXBMAYK.mjs.map} +0 -0
- /package/dist/esm/{chunk-GD5TZLBF.mjs.map → chunk-X5C3LYI7.mjs.map} +0 -0
- /package/dist/esm/{chunk-QRQAR6XO.mjs.map → chunk-XTPFQ4MH.mjs.map} +0 -0
- /package/dist/esm/{chunk-LATJGGVX.mjs.map → chunk-Y5AJLNUD.mjs.map} +0 -0
- /package/dist/esm/{chunk-VKZCIGKY.mjs.map → chunk-YR2R3LW4.mjs.map} +0 -0
- /package/dist/esm/core/{crypto/anySignature.mjs.map → account/Account.mjs.map} +0 -0
- /package/dist/esm/core/{crypto/asymmetricCrypto.mjs.map → account/Ed25519Account.mjs.map} +0 -0
|
@@ -1,12 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HexInput } from "../../types";
|
|
1
|
+
import { SigningScheme as AuthenticationKeyScheme } from "../../types";
|
|
3
2
|
import { Deserializer } from "../../bcs/deserializer";
|
|
4
3
|
import { Serializer } from "../../bcs/serializer";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { AuthenticationKey } from "../authenticationKey";
|
|
5
|
+
import { AccountPublicKey, PublicKey, VerifySignatureArgs } from "./publicKey";
|
|
6
|
+
import { Signature } from "./signature";
|
|
7
|
+
import { AnyPublicKey, AnySignature } from "./singleKey";
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/* eslint-disable no-bitwise */
|
|
10
|
+
|
|
11
|
+
function bitCount(byte: number) {
|
|
12
|
+
let n = byte;
|
|
13
|
+
n -= (n >> 1) & 0x55555555;
|
|
14
|
+
n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
|
|
15
|
+
return (((n + (n >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* eslint-enable no-bitwise */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Represents the public key of a multi-agent account.
|
|
22
|
+
*
|
|
23
|
+
* The public keys of each individual agent can be any type of public key supported by Aptos.
|
|
24
|
+
* Since [AIP-55](https://github.com/aptos-foundation/AIPs/pull/263) Aptos supports
|
|
25
|
+
* `Legacy` and `Unified` authentication keys.
|
|
26
|
+
*/
|
|
27
|
+
export class MultiKey extends AccountPublicKey {
|
|
10
28
|
/**
|
|
11
29
|
* List of any public keys
|
|
12
30
|
*/
|
|
@@ -17,13 +35,15 @@ export class MultiKey extends PublicKey {
|
|
|
17
35
|
*/
|
|
18
36
|
public readonly signaturesRequired: number;
|
|
19
37
|
|
|
20
|
-
|
|
38
|
+
// region Constructors
|
|
39
|
+
|
|
40
|
+
constructor(args: { publicKeys: Array<PublicKey>; signaturesRequired: number }) {
|
|
21
41
|
super();
|
|
22
42
|
const { publicKeys, signaturesRequired } = args;
|
|
23
43
|
|
|
24
44
|
// Validate number of public keys is greater than signature required
|
|
25
45
|
if (signaturesRequired < 1) {
|
|
26
|
-
throw new Error("The number of required signatures needs to be greater
|
|
46
|
+
throw new Error("The number of required signatures needs to be greater than 0");
|
|
27
47
|
}
|
|
28
48
|
|
|
29
49
|
// Validate number of public keys is greater than signature required
|
|
@@ -33,25 +53,52 @@ export class MultiKey extends PublicKey {
|
|
|
33
53
|
);
|
|
34
54
|
}
|
|
35
55
|
|
|
36
|
-
|
|
37
|
-
publicKeys.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} else {
|
|
41
|
-
// if public key is instance of a legacy authentication key, i.e
|
|
42
|
-
// Legacy Ed25519, convert it into AnyPublicKey
|
|
43
|
-
keys.push(new AnyPublicKey(publicKey));
|
|
44
|
-
}
|
|
45
|
-
});
|
|
56
|
+
// Make sure that all keys are normalized to the SingleKey authentication scheme
|
|
57
|
+
this.publicKeys = publicKeys.map((publicKey) =>
|
|
58
|
+
publicKey instanceof AnyPublicKey ? publicKey : new AnyPublicKey(publicKey),
|
|
59
|
+
);
|
|
46
60
|
|
|
47
|
-
this.publicKeys = keys;
|
|
48
61
|
this.signaturesRequired = signaturesRequired;
|
|
49
62
|
}
|
|
50
63
|
|
|
64
|
+
// endregion
|
|
65
|
+
|
|
66
|
+
// region AccountPublicKey
|
|
67
|
+
|
|
68
|
+
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
69
|
+
verifySignature(args: VerifySignatureArgs): boolean {
|
|
70
|
+
throw new Error("not implemented");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
authKey(): AuthenticationKey {
|
|
74
|
+
return AuthenticationKey.fromSchemeAndBytes({
|
|
75
|
+
scheme: AuthenticationKeyScheme.MultiKey,
|
|
76
|
+
input: this.toUint8Array(),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
51
80
|
toUint8Array(): Uint8Array {
|
|
52
81
|
return this.bcsToBytes();
|
|
53
82
|
}
|
|
54
83
|
|
|
84
|
+
// endregion
|
|
85
|
+
|
|
86
|
+
// region Serializable
|
|
87
|
+
|
|
88
|
+
serialize(serializer: Serializer): void {
|
|
89
|
+
serializer.serializeVector(this.publicKeys);
|
|
90
|
+
serializer.serializeU8(this.signaturesRequired);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static deserialize(deserializer: Deserializer): MultiKey {
|
|
94
|
+
const keys = deserializer.deserializeVector(AnyPublicKey);
|
|
95
|
+
const signaturesRequired = deserializer.deserializeU8();
|
|
96
|
+
|
|
97
|
+
return new MultiKey({ publicKeys: keys, signaturesRequired });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// endregion
|
|
101
|
+
|
|
55
102
|
/**
|
|
56
103
|
* Create a bitmap that holds the mapping from the original public keys
|
|
57
104
|
* to the signatures passed in
|
|
@@ -92,31 +139,142 @@ export class MultiKey extends PublicKey {
|
|
|
92
139
|
|
|
93
140
|
return bitmap;
|
|
94
141
|
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export class MultiKeySignature extends Signature {
|
|
145
|
+
/**
|
|
146
|
+
* Number of bytes in the bitmap representing who signed the transaction (32-bits)
|
|
147
|
+
*/
|
|
148
|
+
static BITMAP_LEN: number = 4;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Maximum number of Ed25519 signatures supported
|
|
152
|
+
*/
|
|
153
|
+
static MAX_SIGNATURES_SUPPORTED = MultiKeySignature.BITMAP_LEN * 8;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The list of underlying Ed25519 signatures
|
|
157
|
+
*/
|
|
158
|
+
public readonly signatures: AnySignature[];
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 32-bit Bitmap representing who signed the transaction
|
|
162
|
+
*
|
|
163
|
+
* This is represented where each public key can be masked to determine whether the message was signed by that key.
|
|
164
|
+
*/
|
|
165
|
+
public readonly bitmap: Uint8Array;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Signature for a K-of-N multi-sig transaction.
|
|
169
|
+
*
|
|
170
|
+
* @see {@link
|
|
171
|
+
* https://aptos.dev/integration/creating-a-signed-transaction/#multisignature-transactions | Creating a Signed Transaction}
|
|
172
|
+
*
|
|
173
|
+
* @param args.signatures A list of signatures
|
|
174
|
+
* @param args.bitmap 4 bytes, at most 32 signatures are supported. If Nth bit value is `1`, the Nth
|
|
175
|
+
* signature should be provided in `signatures`. Bits are read from left to right
|
|
176
|
+
*/
|
|
177
|
+
constructor(args: { signatures: Array<Signature | AnySignature>; bitmap: Uint8Array | number[] }) {
|
|
178
|
+
super();
|
|
179
|
+
const { signatures, bitmap } = args;
|
|
180
|
+
|
|
181
|
+
if (signatures.length > MultiKeySignature.MAX_SIGNATURES_SUPPORTED) {
|
|
182
|
+
throw new Error(`The number of signatures cannot be greater than ${MultiKeySignature.MAX_SIGNATURES_SUPPORTED}`);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Make sure that all signatures are normalized to the SingleKey authentication scheme
|
|
186
|
+
this.signatures = signatures.map((signature) =>
|
|
187
|
+
signature instanceof AnySignature ? signature : new AnySignature(signature),
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
if (!(bitmap instanceof Uint8Array)) {
|
|
191
|
+
this.bitmap = MultiKeySignature.createBitmap({ bits: bitmap });
|
|
192
|
+
} else if (bitmap.length !== MultiKeySignature.BITMAP_LEN) {
|
|
193
|
+
throw new Error(`"bitmap" length should be ${MultiKeySignature.BITMAP_LEN}`);
|
|
194
|
+
} else {
|
|
195
|
+
this.bitmap = bitmap;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const nSignatures = this.bitmap.reduce((acc, byte) => acc + bitCount(byte), 0);
|
|
199
|
+
if (nSignatures !== this.signatures.length) {
|
|
200
|
+
throw new Error(`Expecting ${nSignatures} signatures from the bitmap, but got ${this.signatures.length}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
95
203
|
|
|
96
204
|
/**
|
|
97
|
-
*
|
|
205
|
+
* Helper method to create a bitmap out of the specified bit positions
|
|
206
|
+
* @param args.bits The bitmap positions that should be set. A position starts at index 0.
|
|
207
|
+
* Valid position should range between 0 and 31.
|
|
208
|
+
* @example
|
|
209
|
+
* Here's an example of valid `bits`
|
|
210
|
+
* ```
|
|
211
|
+
* [0, 2, 31]
|
|
212
|
+
* ```
|
|
213
|
+
* `[0, 2, 31]` means the 1st, 3rd and 32nd bits should be set in the bitmap.
|
|
214
|
+
* The result bitmap should be 0b1010000000000000000000000000001
|
|
98
215
|
*
|
|
99
|
-
* @returns
|
|
216
|
+
* @returns bitmap that is 32bit long
|
|
100
217
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
218
|
+
static createBitmap(args: { bits: number[] }): Uint8Array {
|
|
219
|
+
const { bits } = args;
|
|
220
|
+
// Bits are read from left to right. e.g. 0b10000000 represents the first bit is set in one byte.
|
|
221
|
+
// The decimal value of 0b10000000 is 128.
|
|
222
|
+
const firstBitInByte = 128;
|
|
223
|
+
const bitmap = new Uint8Array([0, 0, 0, 0]);
|
|
224
|
+
|
|
225
|
+
// Check if duplicates exist in bits
|
|
226
|
+
const dupCheckSet = new Set();
|
|
227
|
+
|
|
228
|
+
bits.forEach((bit: number) => {
|
|
229
|
+
if (bit >= MultiKeySignature.MAX_SIGNATURES_SUPPORTED) {
|
|
230
|
+
throw new Error(`Cannot have a signature larger than ${MultiKeySignature.MAX_SIGNATURES_SUPPORTED - 1}.`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (dupCheckSet.has(bit)) {
|
|
234
|
+
throw new Error("Duplicate bits detected.");
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
dupCheckSet.add(bit);
|
|
238
|
+
|
|
239
|
+
const byteOffset = Math.floor(bit / 8);
|
|
240
|
+
|
|
241
|
+
let byte = bitmap[byteOffset];
|
|
242
|
+
|
|
243
|
+
// eslint-disable-next-line no-bitwise
|
|
244
|
+
byte |= firstBitInByte >> bit % 8;
|
|
245
|
+
|
|
246
|
+
bitmap[byteOffset] = byte;
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
return bitmap;
|
|
103
250
|
}
|
|
104
251
|
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
252
|
+
// region Signature
|
|
253
|
+
|
|
254
|
+
toUint8Array(): Uint8Array {
|
|
255
|
+
return this.bcsToBytes();
|
|
109
256
|
}
|
|
110
257
|
|
|
258
|
+
// endregion
|
|
259
|
+
|
|
260
|
+
// region Serializable
|
|
261
|
+
|
|
111
262
|
serialize(serializer: Serializer): void {
|
|
112
|
-
|
|
113
|
-
serializer.
|
|
263
|
+
// Note: we should not need to serialize the vector length, as it can be derived from the bitmap
|
|
264
|
+
serializer.serializeVector(this.signatures);
|
|
265
|
+
serializer.serializeBytes(this.bitmap);
|
|
114
266
|
}
|
|
115
267
|
|
|
116
|
-
static deserialize(deserializer: Deserializer):
|
|
117
|
-
const
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
268
|
+
static deserialize(deserializer: Deserializer): MultiKeySignature {
|
|
269
|
+
const bitmap = deserializer.deserializeBytes();
|
|
270
|
+
const nSignatures = bitmap.reduce((acc, byte) => acc + bitCount(byte), 0);
|
|
271
|
+
const signatures: AnySignature[] = [];
|
|
272
|
+
for (let i = 0; i < nSignatures; i += 1) {
|
|
273
|
+
const signature = AnySignature.deserialize(deserializer);
|
|
274
|
+
signatures.push(signature);
|
|
275
|
+
}
|
|
276
|
+
return new MultiKeySignature({ signatures, bitmap });
|
|
121
277
|
}
|
|
278
|
+
|
|
279
|
+
// endregion
|
|
122
280
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { HexInput } from "../../types";
|
|
2
|
+
import { PublicKey } from "./publicKey";
|
|
3
|
+
import { Signature } from "./signature";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An abstract representation of a private key.
|
|
7
|
+
* It is associated to a signature scheme and provides signing capabilities.
|
|
8
|
+
*/
|
|
9
|
+
export interface PrivateKey {
|
|
10
|
+
/**
|
|
11
|
+
* Sign the given message with the private key.
|
|
12
|
+
* @param message in HexInput format
|
|
13
|
+
*/
|
|
14
|
+
sign(message: HexInput): Signature;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Derive the public key associated with the private key
|
|
18
|
+
*/
|
|
19
|
+
publicKey(): PublicKey;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get the private key in bytes (Uint8Array).
|
|
23
|
+
*/
|
|
24
|
+
toUint8Array(): Uint8Array;
|
|
25
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Serializable } from "../../bcs";
|
|
2
|
+
import { HexInput } from "../../types";
|
|
3
|
+
import { AuthenticationKey } from "../authenticationKey";
|
|
4
|
+
import { Hex } from "../hex";
|
|
5
|
+
import { Signature } from "./signature";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Arguments for verifying a signature
|
|
9
|
+
*/
|
|
10
|
+
export interface VerifySignatureArgs {
|
|
11
|
+
message: HexInput;
|
|
12
|
+
signature: Signature;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* An abstract representation of a public key.
|
|
17
|
+
*
|
|
18
|
+
* Provides a common interface for verifying any signature.
|
|
19
|
+
*/
|
|
20
|
+
export abstract class PublicKey extends Serializable {
|
|
21
|
+
/**
|
|
22
|
+
* Verifies that the private key associated with this public key signed the message with the given signature.
|
|
23
|
+
* @param args.message The message that was signed
|
|
24
|
+
* @param args.signature The signature to verify
|
|
25
|
+
*/
|
|
26
|
+
abstract verifySignature(args: VerifySignatureArgs): boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get the raw public key bytes
|
|
30
|
+
*/
|
|
31
|
+
abstract toUint8Array(): Uint8Array;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get the public key as a hex string with a 0x prefix e.g. 0x123456...
|
|
35
|
+
*/
|
|
36
|
+
toString(): string {
|
|
37
|
+
const bytes = this.toUint8Array();
|
|
38
|
+
return Hex.fromHexInput(bytes).toString();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* An abstract representation of an account public key.
|
|
44
|
+
*
|
|
45
|
+
* Provides a common interface for deriving an authentication key.
|
|
46
|
+
*/
|
|
47
|
+
export abstract class AccountPublicKey extends PublicKey {
|
|
48
|
+
/**
|
|
49
|
+
* Get the authentication key associated with this public key
|
|
50
|
+
*/
|
|
51
|
+
abstract authKey(): AuthenticationKey;
|
|
52
|
+
}
|
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
import { sha3_256 } from "@noble/hashes/sha3";
|
|
5
5
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
6
6
|
import { HDKey } from "@scure/bip32";
|
|
7
|
-
import {
|
|
8
|
-
import { Deserializer, Serializer } from "../../bcs";
|
|
7
|
+
import { Serializable, Deserializer, Serializer } from "../../bcs";
|
|
9
8
|
import { Hex } from "../hex";
|
|
10
9
|
import { HexInput } from "../../types";
|
|
11
10
|
import { isValidBIP44Path, mnemonicToSeed } from "./hdKey";
|
|
11
|
+
import { PrivateKey } from "./privateKey";
|
|
12
|
+
import { PublicKey, VerifySignatureArgs } from "./publicKey";
|
|
13
|
+
import { Signature } from "./signature";
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Represents the Secp256k1 ecdsa public key
|
|
@@ -37,38 +39,27 @@ export class Secp256k1PublicKey extends PublicKey {
|
|
|
37
39
|
this.key = hex;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
// region PublicKey
|
|
43
|
+
|
|
44
|
+
verifySignature(args: VerifySignatureArgs): boolean {
|
|
45
|
+
const { message, signature } = args;
|
|
46
|
+
if (!(signature instanceof Secp256k1Signature)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const messageBytes = Hex.fromHexInput(message).toUint8Array();
|
|
51
|
+
const messageSha3Bytes = sha3_256(messageBytes);
|
|
52
|
+
const signatureBytes = signature.toUint8Array();
|
|
53
|
+
return secp256k1.verify(signatureBytes, messageSha3Bytes, this.key.toUint8Array());
|
|
54
|
+
}
|
|
55
|
+
|
|
45
56
|
toUint8Array(): Uint8Array {
|
|
46
57
|
return this.key.toUint8Array();
|
|
47
58
|
}
|
|
48
59
|
|
|
49
|
-
|
|
50
|
-
* Get the public key as a hex string with the 0x prefix.
|
|
51
|
-
*
|
|
52
|
-
* @returns string representation of the public key
|
|
53
|
-
*/
|
|
54
|
-
toString(): string {
|
|
55
|
-
return this.key.toString();
|
|
56
|
-
}
|
|
60
|
+
// endregion
|
|
57
61
|
|
|
58
|
-
|
|
59
|
-
* Verifies a signed data with a public key
|
|
60
|
-
*
|
|
61
|
-
* @param args.message message
|
|
62
|
-
* @param args.signature The signature
|
|
63
|
-
* @returns true if the signature is valid
|
|
64
|
-
*/
|
|
65
|
-
verifySignature(args: { message: HexInput; signature: Secp256k1Signature }): boolean {
|
|
66
|
-
const { message, signature } = args;
|
|
67
|
-
const msgHex = Hex.fromHexInput(message).toUint8Array();
|
|
68
|
-
const sha3Message = sha3_256(msgHex);
|
|
69
|
-
const rawSignature = signature.toUint8Array();
|
|
70
|
-
return secp256k1.verify(rawSignature, sha3Message, this.toUint8Array());
|
|
71
|
-
}
|
|
62
|
+
// region Serializable
|
|
72
63
|
|
|
73
64
|
serialize(serializer: Serializer): void {
|
|
74
65
|
serializer.serializeBytes(this.key.toUint8Array());
|
|
@@ -79,11 +70,12 @@ export class Secp256k1PublicKey extends PublicKey {
|
|
|
79
70
|
return new Secp256k1PublicKey(bytes);
|
|
80
71
|
}
|
|
81
72
|
|
|
82
|
-
|
|
83
|
-
const bytes = deserializer.deserializeBytes();
|
|
84
|
-
return new Secp256k1PublicKey(bytes);
|
|
85
|
-
}
|
|
73
|
+
// endregion
|
|
86
74
|
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated use `instanceof Secp256k1PublicKey` instead
|
|
77
|
+
* @param publicKey
|
|
78
|
+
*/
|
|
87
79
|
static isPublicKey(publicKey: PublicKey): publicKey is Secp256k1PublicKey {
|
|
88
80
|
return publicKey instanceof Secp256k1PublicKey;
|
|
89
81
|
}
|
|
@@ -92,7 +84,7 @@ export class Secp256k1PublicKey extends PublicKey {
|
|
|
92
84
|
/**
|
|
93
85
|
* A Secp256k1 ecdsa private key
|
|
94
86
|
*/
|
|
95
|
-
export class Secp256k1PrivateKey extends PrivateKey {
|
|
87
|
+
export class Secp256k1PrivateKey extends Serializable implements PrivateKey {
|
|
96
88
|
/**
|
|
97
89
|
* Length of Secp256k1 ecdsa private key
|
|
98
90
|
*/
|
|
@@ -104,6 +96,8 @@ export class Secp256k1PrivateKey extends PrivateKey {
|
|
|
104
96
|
*/
|
|
105
97
|
private readonly key: Hex;
|
|
106
98
|
|
|
99
|
+
// region Constructors
|
|
100
|
+
|
|
107
101
|
/**
|
|
108
102
|
* Create a new PrivateKey instance from a Uint8Array or String.
|
|
109
103
|
*
|
|
@@ -120,46 +114,6 @@ export class Secp256k1PrivateKey extends PrivateKey {
|
|
|
120
114
|
this.key = privateKeyHex;
|
|
121
115
|
}
|
|
122
116
|
|
|
123
|
-
/**
|
|
124
|
-
* Get the private key in bytes (Uint8Array).
|
|
125
|
-
*
|
|
126
|
-
* @returns
|
|
127
|
-
*/
|
|
128
|
-
toUint8Array(): Uint8Array {
|
|
129
|
-
return this.key.toUint8Array();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Get the private key as a hex string with the 0x prefix.
|
|
134
|
-
*
|
|
135
|
-
* @returns string representation of the private key
|
|
136
|
-
*/
|
|
137
|
-
toString(): string {
|
|
138
|
-
return this.key.toString();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Sign the given message with the private key.
|
|
143
|
-
*
|
|
144
|
-
* @param message in HexInput format
|
|
145
|
-
* @returns Signature
|
|
146
|
-
*/
|
|
147
|
-
sign(message: HexInput): Secp256k1Signature {
|
|
148
|
-
const msgHex = Hex.fromHexInput(message);
|
|
149
|
-
const sha3Message = sha3_256(msgHex.toUint8Array());
|
|
150
|
-
const signature = secp256k1.sign(sha3Message, this.key.toUint8Array());
|
|
151
|
-
return new Secp256k1Signature(signature.toCompactRawBytes());
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
serialize(serializer: Serializer): void {
|
|
155
|
-
serializer.serializeBytes(this.toUint8Array());
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
static deserialize(deserializer: Deserializer): Secp256k1PrivateKey {
|
|
159
|
-
const bytes = deserializer.deserializeBytes();
|
|
160
|
-
return new Secp256k1PrivateKey(bytes);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
117
|
/**
|
|
164
118
|
* Generate a new random private key.
|
|
165
119
|
*
|
|
@@ -170,16 +124,6 @@ export class Secp256k1PrivateKey extends PrivateKey {
|
|
|
170
124
|
return new Secp256k1PrivateKey(hexInput);
|
|
171
125
|
}
|
|
172
126
|
|
|
173
|
-
/**
|
|
174
|
-
* Derive the Secp256k1PublicKey from this private key.
|
|
175
|
-
*
|
|
176
|
-
* @returns Secp256k1PublicKey
|
|
177
|
-
*/
|
|
178
|
-
publicKey(): Secp256k1PublicKey {
|
|
179
|
-
const bytes = secp256k1.getPublicKey(this.key.toUint8Array(), false);
|
|
180
|
-
return new Secp256k1PublicKey(bytes);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
127
|
/**
|
|
184
128
|
* Derives a private key from a mnemonic seed phrase.
|
|
185
129
|
*
|
|
@@ -214,13 +158,76 @@ export class Secp256k1PrivateKey extends PrivateKey {
|
|
|
214
158
|
return new Secp256k1PrivateKey(privateKey);
|
|
215
159
|
}
|
|
216
160
|
|
|
161
|
+
// endregion
|
|
162
|
+
|
|
163
|
+
// region PrivateKey
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Sign the given message with the private key.
|
|
167
|
+
*
|
|
168
|
+
* @param message in HexInput format
|
|
169
|
+
* @returns Signature
|
|
170
|
+
*/
|
|
171
|
+
sign(message: HexInput): Secp256k1Signature {
|
|
172
|
+
const messageBytes = Hex.fromHexInput(message);
|
|
173
|
+
const messageHashBytes = sha3_256(messageBytes.toUint8Array());
|
|
174
|
+
const signature = secp256k1.sign(messageHashBytes, this.key.toUint8Array());
|
|
175
|
+
return new Secp256k1Signature(signature.toCompactRawBytes());
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Derive the Secp256k1PublicKey from this private key.
|
|
180
|
+
*
|
|
181
|
+
* @returns Secp256k1PublicKey
|
|
182
|
+
*/
|
|
183
|
+
publicKey(): Secp256k1PublicKey {
|
|
184
|
+
const bytes = secp256k1.getPublicKey(this.key.toUint8Array(), false);
|
|
185
|
+
return new Secp256k1PublicKey(bytes);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Get the private key in bytes (Uint8Array).
|
|
190
|
+
*
|
|
191
|
+
* @returns
|
|
192
|
+
*/
|
|
193
|
+
toUint8Array(): Uint8Array {
|
|
194
|
+
return this.key.toUint8Array();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Get the private key as a hex string with the 0x prefix.
|
|
199
|
+
*
|
|
200
|
+
* @returns string representation of the private key
|
|
201
|
+
*/
|
|
202
|
+
toString(): string {
|
|
203
|
+
return this.key.toString();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// endregion
|
|
207
|
+
|
|
208
|
+
// region Serializable
|
|
209
|
+
|
|
210
|
+
serialize(serializer: Serializer): void {
|
|
211
|
+
serializer.serializeBytes(this.toUint8Array());
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static deserialize(deserializer: Deserializer): Secp256k1PrivateKey {
|
|
215
|
+
const bytes = deserializer.deserializeBytes();
|
|
216
|
+
return new Secp256k1PrivateKey(bytes);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// endregion
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @deprecated use `instanceof Secp256k1PrivateKey` instead
|
|
223
|
+
*/
|
|
217
224
|
static isPrivateKey(privateKey: PrivateKey): privateKey is Secp256k1PrivateKey {
|
|
218
225
|
return privateKey instanceof Secp256k1PrivateKey;
|
|
219
226
|
}
|
|
220
227
|
}
|
|
221
228
|
|
|
222
229
|
/**
|
|
223
|
-
* A signature of a message signed using
|
|
230
|
+
* A signature of a message signed using a Secp256k1 ecdsa private key
|
|
224
231
|
*/
|
|
225
232
|
export class Secp256k1Signature extends Signature {
|
|
226
233
|
/**
|
|
@@ -234,6 +241,8 @@ export class Secp256k1Signature extends Signature {
|
|
|
234
241
|
*/
|
|
235
242
|
private readonly data: Hex;
|
|
236
243
|
|
|
244
|
+
// region Constructors
|
|
245
|
+
|
|
237
246
|
/**
|
|
238
247
|
* Create a new Signature instance from a Uint8Array or String.
|
|
239
248
|
*
|
|
@@ -241,31 +250,26 @@ export class Secp256k1Signature extends Signature {
|
|
|
241
250
|
*/
|
|
242
251
|
constructor(hexInput: HexInput) {
|
|
243
252
|
super();
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
253
|
+
const data = Hex.fromHexInput(hexInput);
|
|
254
|
+
if (data.toUint8Array().length !== Secp256k1Signature.LENGTH) {
|
|
255
|
+
throw new Error(
|
|
256
|
+
`Signature length should be ${Secp256k1Signature.LENGTH}, received ${data.toUint8Array().length}`,
|
|
257
|
+
);
|
|
248
258
|
}
|
|
249
|
-
this.data =
|
|
259
|
+
this.data = data;
|
|
250
260
|
}
|
|
251
261
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
*/
|
|
262
|
+
// endregion
|
|
263
|
+
|
|
264
|
+
// region Signature
|
|
265
|
+
|
|
257
266
|
toUint8Array(): Uint8Array {
|
|
258
267
|
return this.data.toUint8Array();
|
|
259
268
|
}
|
|
260
269
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
* @returns string representation of the signature
|
|
265
|
-
*/
|
|
266
|
-
toString(): string {
|
|
267
|
-
return this.data.toString();
|
|
268
|
-
}
|
|
270
|
+
// endregion
|
|
271
|
+
|
|
272
|
+
// region Serializable
|
|
269
273
|
|
|
270
274
|
serialize(serializer: Serializer): void {
|
|
271
275
|
serializer.serializeBytes(this.data.toUint8Array());
|
|
@@ -276,12 +280,5 @@ export class Secp256k1Signature extends Signature {
|
|
|
276
280
|
return new Secp256k1Signature(hex);
|
|
277
281
|
}
|
|
278
282
|
|
|
279
|
-
|
|
280
|
-
const bytes = deserializer.deserializeBytes();
|
|
281
|
-
return new Secp256k1Signature(bytes);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
static isSignature(signature: Signature): signature is Secp256k1Signature {
|
|
285
|
-
return signature instanceof Secp256k1Signature;
|
|
286
|
-
}
|
|
283
|
+
// endregion
|
|
287
284
|
}
|