@aptos-labs/ts-sdk 1.16.0-zeta.1 → 1.16.0-zeta.3
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/common/{accountAddress-OUd5ov6z.d.ts → accountAddress-YfW6h4Ja.d.ts} +1 -1
- package/dist/common/{chunk-VLEH6QBR.js → chunk-HPZUSDYP.js} +1 -1
- package/dist/common/{chunk-VLEH6QBR.js.map → chunk-HPZUSDYP.js.map} +1 -1
- package/dist/common/cli/index.d.ts +1 -1
- package/dist/common/cli/index.js +1 -1
- package/dist/common/index.d.ts +77 -68
- package/dist/common/index.js +12 -12
- package/dist/common/index.js.map +1 -1
- package/dist/esm/account/Account.mjs +1 -1
- package/dist/esm/account/Ed25519Account.mjs +1 -1
- package/dist/esm/account/EphemeralKeyPair.mjs +1 -1
- package/dist/esm/account/KeylessAccount.d.mts +2 -15
- package/dist/esm/account/KeylessAccount.mjs +1 -1
- package/dist/esm/account/MultiKeyAccount.mjs +1 -1
- package/dist/esm/account/SingleKeyAccount.mjs +1 -1
- package/dist/esm/account/index.d.mts +1 -2
- package/dist/esm/account/index.mjs +1 -1
- package/dist/esm/api/account.mjs +1 -1
- package/dist/esm/api/ans.mjs +1 -1
- package/dist/esm/api/aptos.d.mts +3 -4
- package/dist/esm/api/aptos.mjs +1 -1
- package/dist/esm/api/coin.mjs +1 -1
- 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.mjs +1 -1
- package/dist/esm/api/general.mjs +1 -1
- package/dist/esm/api/index.d.mts +3 -4
- package/dist/esm/api/index.mjs +1 -1
- package/dist/esm/api/keyless.d.mts +6 -14
- package/dist/esm/api/keyless.mjs +1 -1
- package/dist/esm/api/staking.mjs +1 -1
- package/dist/esm/api/table.mjs +1 -1
- package/dist/esm/api/transaction.mjs +1 -1
- package/dist/esm/api/transactionSubmission/build.mjs +1 -1
- package/dist/esm/api/transactionSubmission/management.mjs +1 -1
- package/dist/esm/api/transactionSubmission/sign.mjs +1 -1
- package/dist/esm/api/transactionSubmission/simulate.mjs +1 -1
- package/dist/esm/api/transactionSubmission/submit.mjs +1 -1
- package/dist/esm/api/utils.mjs +1 -1
- package/dist/esm/bcs/deserializer.mjs +1 -1
- package/dist/esm/bcs/index.mjs +1 -1
- package/dist/esm/bcs/serializable/entryFunctionBytes.mjs +1 -1
- package/dist/esm/bcs/serializable/fixedBytes.mjs +1 -1
- package/dist/esm/bcs/serializable/movePrimitives.mjs +1 -1
- package/dist/esm/bcs/serializable/moveStructs.mjs +1 -1
- package/dist/esm/bcs/serializer.mjs +1 -1
- package/dist/esm/{chunk-CEGCSC3T.mjs → chunk-2BDKITTE.mjs} +2 -2
- package/dist/esm/{chunk-3J53BCEQ.mjs → chunk-2DESIV2P.mjs} +2 -2
- package/dist/esm/{chunk-WSVJNBSJ.mjs → chunk-2SJENNM4.mjs} +2 -2
- package/dist/esm/{chunk-RAHMGSBW.mjs → chunk-2Y7GVUQQ.mjs} +2 -2
- package/dist/esm/{chunk-SZ6KR73C.mjs → chunk-37FFZSIM.mjs} +2 -2
- package/dist/esm/{chunk-WXLSJF4A.mjs → chunk-3IFR6T3V.mjs} +1 -1
- package/dist/esm/chunk-3IFR6T3V.mjs.map +1 -0
- package/dist/esm/chunk-3RJZNUCQ.mjs +2 -0
- package/dist/esm/{chunk-ULW5LX5H.mjs → chunk-3TIXNBXM.mjs} +2 -2
- package/dist/esm/{chunk-3DP4R3FI.mjs → chunk-472OGHMG.mjs} +2 -2
- package/dist/esm/{chunk-PG7KSUMN.mjs → chunk-4AWM7GGV.mjs} +2 -2
- package/dist/esm/{chunk-J577ODDM.mjs → chunk-4VPCPASN.mjs} +2 -2
- package/dist/esm/{chunk-D76FE35G.mjs → chunk-572AE4D7.mjs} +2 -2
- package/dist/esm/{chunk-NUBYALZP.mjs → chunk-5SGAX4VT.mjs} +2 -2
- package/dist/esm/{chunk-J534ICWA.mjs → chunk-66G6MKI6.mjs} +2 -2
- package/dist/esm/{chunk-RKHPXZM6.mjs → chunk-6FBKUTGF.mjs} +2 -2
- package/dist/esm/{chunk-RKHPXZM6.mjs.map → chunk-6FBKUTGF.mjs.map} +1 -1
- package/dist/esm/{chunk-NH466YFP.mjs → chunk-6OQBDCDK.mjs} +2 -2
- package/dist/esm/{chunk-SCHMTP4N.mjs → chunk-7BW2N4IE.mjs} +2 -2
- package/dist/esm/chunk-7FUZE7F4.mjs +2 -0
- package/dist/esm/chunk-7FUZE7F4.mjs.map +1 -0
- package/dist/esm/chunk-7GU3E2FJ.mjs +2 -0
- package/dist/esm/chunk-7GU3E2FJ.mjs.map +1 -0
- package/dist/esm/{chunk-ISXBJPLD.mjs → chunk-7SOLAI6Q.mjs} +2 -2
- package/dist/esm/{chunk-EJURLI4L.mjs → chunk-AEWSL7BS.mjs} +2 -2
- package/dist/esm/{chunk-45ESRYGP.mjs → chunk-ARHEUGVT.mjs} +2 -2
- package/dist/esm/{chunk-6F3HFDL3.mjs → chunk-AXR47GFL.mjs} +2 -2
- package/dist/esm/{chunk-LLRWILVZ.mjs → chunk-B74ZAMWR.mjs} +2 -2
- package/dist/esm/{chunk-AVWAYKNS.mjs → chunk-BO44HPGU.mjs} +2 -2
- package/dist/esm/{chunk-HOX6Q6ZP.mjs → chunk-CCIY5VLR.mjs} +2 -2
- package/dist/esm/{chunk-R4HLV32L.mjs → chunk-CI64RKDE.mjs} +2 -2
- package/dist/esm/{chunk-PGP2XMDE.mjs → chunk-DPWEHSHH.mjs} +2 -2
- package/dist/esm/{chunk-QOOHLRRJ.mjs → chunk-E62NBNHE.mjs} +2 -2
- package/dist/esm/{chunk-NGTNMV6Q.mjs → chunk-EFMAZTIM.mjs} +2 -2
- package/dist/esm/{chunk-UFMIMN7W.mjs → chunk-EJA532W4.mjs} +2 -2
- package/dist/esm/{chunk-OOYRJQPD.mjs → chunk-EJQ2EYJ7.mjs} +2 -2
- package/dist/esm/{chunk-WJIICWOB.mjs → chunk-ERPUZQVK.mjs} +2 -2
- package/dist/esm/{chunk-WHSN42R2.mjs → chunk-F3ZVWLDH.mjs} +2 -2
- package/dist/esm/chunk-F7XWXQHU.mjs +2 -0
- package/dist/esm/{chunk-JBTLE33X.mjs.map → chunk-F7XWXQHU.mjs.map} +1 -1
- package/dist/esm/{chunk-GS5Z3HO7.mjs → chunk-FGGRPEQ3.mjs} +2 -2
- package/dist/esm/{chunk-EJ7ODMDA.mjs → chunk-FIG65OJD.mjs} +2 -2
- package/dist/esm/{chunk-MSGHGK52.mjs → chunk-GRHLQDHF.mjs} +2 -2
- package/dist/esm/{chunk-VMVSUH2K.mjs → chunk-GSCM444Z.mjs} +2 -2
- package/dist/esm/{chunk-QJIMZI32.mjs → chunk-GTXZNAYI.mjs} +2 -2
- package/dist/esm/{chunk-ZV5P2GSJ.mjs → chunk-IBN7ETCB.mjs} +2 -2
- package/dist/esm/{chunk-DSVNXD5A.mjs → chunk-IPI3VB62.mjs} +2 -2
- package/dist/esm/{chunk-ZAXWW7VW.mjs → chunk-IVVWQKCF.mjs} +1 -1
- package/dist/esm/chunk-IVVWQKCF.mjs.map +1 -0
- package/dist/esm/{chunk-XQ7I34AL.mjs → chunk-IXFYYWAC.mjs} +2 -2
- package/dist/esm/{chunk-HGRU3HWY.mjs → chunk-J63BIFB7.mjs} +2 -2
- package/dist/esm/{chunk-Y24BMR2W.mjs → chunk-JBX3JBIW.mjs} +2 -2
- package/dist/esm/{chunk-SSDWEOF7.mjs → chunk-JEE2OXOZ.mjs} +2 -2
- package/dist/esm/{chunk-6MDYCC7P.mjs → chunk-JV6JCXCH.mjs} +2 -2
- package/dist/esm/{chunk-OZ3GSAFK.mjs → chunk-KGHBTSDR.mjs} +2 -2
- package/dist/esm/{chunk-3SXTTG2X.mjs → chunk-L5CPAOUM.mjs} +2 -2
- package/dist/esm/chunk-LA67NWMV.mjs +2 -0
- package/dist/esm/chunk-LA67NWMV.mjs.map +1 -0
- package/dist/esm/chunk-LYOUEPDG.mjs +2 -0
- package/dist/esm/{chunk-5VLCYHNJ.mjs.map → chunk-LYOUEPDG.mjs.map} +1 -1
- package/dist/esm/{chunk-VBODXPT3.mjs → chunk-MLX6DFMR.mjs} +2 -2
- package/dist/esm/{chunk-SNBE5YAC.mjs → chunk-MMM5NTKW.mjs} +2 -2
- package/dist/esm/{chunk-OFC75EWS.mjs → chunk-MPTKOK27.mjs} +2 -2
- package/dist/esm/chunk-NTQLNAKS.mjs +2 -0
- package/dist/esm/chunk-NTQLNAKS.mjs.map +1 -0
- package/dist/esm/{chunk-4VAYXBD2.mjs → chunk-NW3WUTTD.mjs} +2 -2
- package/dist/esm/{chunk-AUV4VAXK.mjs → chunk-NZBZV7RP.mjs} +2 -2
- package/dist/esm/{chunk-QYEJOEWB.mjs → chunk-O3BRX56F.mjs} +2 -2
- package/dist/esm/chunk-OAX7LYUZ.mjs +2 -0
- package/dist/esm/chunk-OAX7LYUZ.mjs.map +1 -0
- package/dist/esm/{chunk-QLE5JL4X.mjs → chunk-OJ6AF4YT.mjs} +2 -2
- package/dist/esm/{chunk-5SGIYAB7.mjs → chunk-OR27VDOE.mjs} +2 -2
- package/dist/esm/{chunk-M4Q4XDVR.mjs → chunk-PAJXNH6J.mjs} +2 -2
- package/dist/esm/{chunk-JCDZ2WXX.mjs → chunk-QHB5A5YP.mjs} +1 -1
- package/dist/esm/chunk-QHB5A5YP.mjs.map +1 -0
- package/dist/esm/{chunk-THURV6CN.mjs → chunk-QMYYNCC2.mjs} +2 -2
- package/dist/esm/chunk-QNDR3S5U.mjs +2 -0
- package/dist/esm/chunk-QNDR3S5U.mjs.map +1 -0
- package/dist/esm/{chunk-RWYPGTNL.mjs → chunk-SNDFJWYM.mjs} +2 -2
- package/dist/esm/{chunk-3YIUOKWW.mjs → chunk-T5YEMU53.mjs} +2 -2
- package/dist/esm/{chunk-34WI7I3Z.mjs → chunk-TDDJZLWB.mjs} +2 -2
- package/dist/esm/{chunk-IMVC2JKU.mjs → chunk-TEGJAM44.mjs} +2 -2
- package/dist/esm/{chunk-IMVC2JKU.mjs.map → chunk-TEGJAM44.mjs.map} +1 -1
- package/dist/esm/{chunk-MLQT5I6K.mjs → chunk-TUCCV62K.mjs} +2 -2
- package/dist/esm/{chunk-YLQJBXUF.mjs → chunk-TV7RXL3V.mjs} +2 -2
- package/dist/esm/{chunk-7QGIAVW4.mjs → chunk-UBON2G6Y.mjs} +2 -2
- package/dist/esm/chunk-UKKHWC4Y.mjs +2 -0
- package/dist/esm/chunk-UKKHWC4Y.mjs.map +1 -0
- package/dist/esm/{chunk-272NA6H5.mjs → chunk-UMLUOYFK.mjs} +1 -1
- package/dist/esm/{chunk-272NA6H5.mjs.map → chunk-UMLUOYFK.mjs.map} +1 -1
- package/dist/esm/chunk-VRO3J43Z.mjs +2 -0
- package/dist/esm/chunk-VRO3J43Z.mjs.map +1 -0
- package/dist/esm/{chunk-AUAL3H36.mjs → chunk-WA2NTBYY.mjs} +2 -2
- package/dist/esm/{chunk-IWKIZLFW.mjs → chunk-WT5HOIK6.mjs} +2 -2
- package/dist/esm/{chunk-V6M7FGQT.mjs → chunk-X2VUS374.mjs} +2 -2
- package/dist/esm/{chunk-PENBUSGL.mjs → chunk-XH33BXEY.mjs} +2 -2
- package/dist/esm/{chunk-WOLLRMXR.mjs → chunk-XVZBWW46.mjs} +2 -2
- package/dist/esm/{chunk-IU6REVKX.mjs → chunk-YDNOKWV3.mjs} +2 -2
- package/dist/esm/{chunk-CZOUSIAD.mjs → chunk-YDSBZMZB.mjs} +2 -2
- package/dist/esm/{chunk-GHHIUWPP.mjs → chunk-YRUF6N3U.mjs} +2 -2
- package/dist/esm/{chunk-SCRIQQV3.mjs → chunk-Z6FMMNAL.mjs} +2 -2
- package/dist/esm/{chunk-TU6VKYDC.mjs → chunk-ZNPEUH4I.mjs} +2 -2
- package/dist/esm/cli/index.mjs +1 -1
- package/dist/esm/cli/localNode.mjs +1 -1
- 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/client/types.d.mts +1 -5
- package/dist/esm/client/types.mjs +1 -1
- package/dist/esm/core/account/index.mjs +1 -1
- package/dist/esm/core/account/utils/address.mjs +1 -1
- package/dist/esm/core/account/utils/index.mjs +1 -1
- package/dist/esm/core/accountAddress.mjs +1 -1
- package/dist/esm/core/authenticationKey.mjs +1 -1
- package/dist/esm/core/crypto/cryptoHasher.mjs +1 -1
- package/dist/esm/core/crypto/ed25519.mjs +1 -1
- package/dist/esm/core/crypto/ephemeral.mjs +1 -1
- package/dist/esm/core/crypto/index.mjs +1 -1
- package/dist/esm/core/crypto/keyless.d.mts +34 -2
- package/dist/esm/core/crypto/keyless.mjs +1 -1
- package/dist/esm/core/crypto/multiEd25519.mjs +1 -1
- package/dist/esm/core/crypto/multiKey.mjs +1 -1
- package/dist/esm/core/crypto/poseidon.mjs +1 -1
- package/dist/esm/core/crypto/proof.mjs +1 -1
- package/dist/esm/core/crypto/publicKey.mjs +1 -1
- package/dist/esm/core/crypto/secp256k1.mjs +1 -1
- package/dist/esm/core/crypto/signature.mjs +1 -1
- package/dist/esm/core/crypto/singleKey.mjs +1 -1
- package/dist/esm/core/index.mjs +1 -1
- package/dist/esm/index.d.mts +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/internal/account.mjs +1 -1
- package/dist/esm/internal/ans.mjs +1 -1
- package/dist/esm/internal/coin.mjs +1 -1
- package/dist/esm/internal/digitalAsset.mjs +1 -1
- package/dist/esm/internal/event.mjs +1 -1
- package/dist/esm/internal/faucet.mjs +1 -1
- package/dist/esm/internal/fungibleAsset.mjs +1 -1
- package/dist/esm/internal/general.d.mts +2 -16
- package/dist/esm/internal/general.mjs +1 -1
- package/dist/esm/internal/keyless.d.mts +3 -8
- package/dist/esm/internal/keyless.mjs +1 -1
- package/dist/esm/internal/staking.mjs +1 -1
- package/dist/esm/internal/table.mjs +1 -1
- package/dist/esm/internal/transaction.d.mts +16 -2
- package/dist/esm/internal/transaction.mjs +1 -1
- package/dist/esm/internal/transactionSubmission.mjs +1 -1
- package/dist/esm/internal/view.mjs +1 -1
- package/dist/esm/transactions/authenticator/account.mjs +1 -1
- package/dist/esm/transactions/authenticator/index.mjs +1 -1
- package/dist/esm/transactions/authenticator/transaction.mjs +1 -1
- package/dist/esm/transactions/index.mjs +1 -1
- package/dist/esm/transactions/instances/chainId.mjs +1 -1
- package/dist/esm/transactions/instances/identifier.mjs +1 -1
- package/dist/esm/transactions/instances/index.mjs +1 -1
- package/dist/esm/transactions/instances/moduleId.mjs +1 -1
- package/dist/esm/transactions/instances/multiAgentTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/rawTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/rotationProofChallenge.mjs +1 -1
- package/dist/esm/transactions/instances/signedTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/simpleTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/transactionPayload.mjs +1 -1
- package/dist/esm/transactions/management/accountSequenceNumber.mjs +1 -1
- package/dist/esm/transactions/management/index.mjs +1 -1
- package/dist/esm/transactions/management/transactionWorker.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/helpers.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/index.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/remoteAbi.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/signingMessage.mjs +1 -1
- 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/utils/helpers.mjs +1 -1
- package/dist/esm/utils/index.mjs +1 -1
- package/dist/esm/utils/normalizeBundle.mjs +1 -1
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -2
- package/src/account/KeylessAccount.ts +11 -44
- package/src/api/general.ts +1 -2
- package/src/api/keyless.ts +2 -15
- package/src/bcs/deserializer.ts +4 -4
- package/src/bcs/serializer.ts +2 -2
- package/src/client/core.ts +1 -2
- package/src/client/types.ts +1 -1
- package/src/core/crypto/cryptoHasher.ts +1 -1
- package/src/core/crypto/keyless.ts +97 -64
- package/src/core/crypto/poseidon.ts +5 -3
- package/src/internal/general.ts +1 -38
- package/src/internal/keyless.ts +31 -12
- package/src/internal/transaction.ts +92 -0
- package/src/internal/transactionSubmission.ts +2 -2
- package/src/types/keyless.ts +22 -22
- package/src/utils/helpers.ts +6 -1
- package/src/version.ts +1 -1
- package/dist/esm/chunk-4RXGVY2H.mjs +0 -2
- package/dist/esm/chunk-4RXGVY2H.mjs.map +0 -1
- package/dist/esm/chunk-5VLCYHNJ.mjs +0 -2
- package/dist/esm/chunk-7CJAEAQZ.mjs +0 -2
- package/dist/esm/chunk-7CJAEAQZ.mjs.map +0 -1
- package/dist/esm/chunk-7Y6AWDBZ.mjs +0 -2
- package/dist/esm/chunk-7Y6AWDBZ.mjs.map +0 -1
- package/dist/esm/chunk-BNA3SGG6.mjs +0 -2
- package/dist/esm/chunk-BNA3SGG6.mjs.map +0 -1
- package/dist/esm/chunk-CIPPNT3W.mjs +0 -2
- package/dist/esm/chunk-CIPPNT3W.mjs.map +0 -1
- package/dist/esm/chunk-FUQDDIKQ.mjs +0 -2
- package/dist/esm/chunk-FUQDDIKQ.mjs.map +0 -1
- package/dist/esm/chunk-FWTJQHJR.mjs +0 -2
- package/dist/esm/chunk-FWTJQHJR.mjs.map +0 -1
- package/dist/esm/chunk-HQK6MF3G.mjs +0 -2
- package/dist/esm/chunk-JBTLE33X.mjs +0 -2
- package/dist/esm/chunk-JCDZ2WXX.mjs.map +0 -1
- package/dist/esm/chunk-MEOBWD6V.mjs +0 -2
- package/dist/esm/chunk-MEOBWD6V.mjs.map +0 -1
- package/dist/esm/chunk-WXLSJF4A.mjs.map +0 -1
- package/dist/esm/chunk-ZAXWW7VW.mjs.map +0 -1
- /package/dist/esm/{chunk-CEGCSC3T.mjs.map → chunk-2BDKITTE.mjs.map} +0 -0
- /package/dist/esm/{chunk-3J53BCEQ.mjs.map → chunk-2DESIV2P.mjs.map} +0 -0
- /package/dist/esm/{chunk-WSVJNBSJ.mjs.map → chunk-2SJENNM4.mjs.map} +0 -0
- /package/dist/esm/{chunk-RAHMGSBW.mjs.map → chunk-2Y7GVUQQ.mjs.map} +0 -0
- /package/dist/esm/{chunk-SZ6KR73C.mjs.map → chunk-37FFZSIM.mjs.map} +0 -0
- /package/dist/esm/{chunk-HQK6MF3G.mjs.map → chunk-3RJZNUCQ.mjs.map} +0 -0
- /package/dist/esm/{chunk-ULW5LX5H.mjs.map → chunk-3TIXNBXM.mjs.map} +0 -0
- /package/dist/esm/{chunk-3DP4R3FI.mjs.map → chunk-472OGHMG.mjs.map} +0 -0
- /package/dist/esm/{chunk-PG7KSUMN.mjs.map → chunk-4AWM7GGV.mjs.map} +0 -0
- /package/dist/esm/{chunk-J577ODDM.mjs.map → chunk-4VPCPASN.mjs.map} +0 -0
- /package/dist/esm/{chunk-D76FE35G.mjs.map → chunk-572AE4D7.mjs.map} +0 -0
- /package/dist/esm/{chunk-NUBYALZP.mjs.map → chunk-5SGAX4VT.mjs.map} +0 -0
- /package/dist/esm/{chunk-J534ICWA.mjs.map → chunk-66G6MKI6.mjs.map} +0 -0
- /package/dist/esm/{chunk-NH466YFP.mjs.map → chunk-6OQBDCDK.mjs.map} +0 -0
- /package/dist/esm/{chunk-SCHMTP4N.mjs.map → chunk-7BW2N4IE.mjs.map} +0 -0
- /package/dist/esm/{chunk-ISXBJPLD.mjs.map → chunk-7SOLAI6Q.mjs.map} +0 -0
- /package/dist/esm/{chunk-EJURLI4L.mjs.map → chunk-AEWSL7BS.mjs.map} +0 -0
- /package/dist/esm/{chunk-45ESRYGP.mjs.map → chunk-ARHEUGVT.mjs.map} +0 -0
- /package/dist/esm/{chunk-6F3HFDL3.mjs.map → chunk-AXR47GFL.mjs.map} +0 -0
- /package/dist/esm/{chunk-LLRWILVZ.mjs.map → chunk-B74ZAMWR.mjs.map} +0 -0
- /package/dist/esm/{chunk-AVWAYKNS.mjs.map → chunk-BO44HPGU.mjs.map} +0 -0
- /package/dist/esm/{chunk-HOX6Q6ZP.mjs.map → chunk-CCIY5VLR.mjs.map} +0 -0
- /package/dist/esm/{chunk-R4HLV32L.mjs.map → chunk-CI64RKDE.mjs.map} +0 -0
- /package/dist/esm/{chunk-PGP2XMDE.mjs.map → chunk-DPWEHSHH.mjs.map} +0 -0
- /package/dist/esm/{chunk-QOOHLRRJ.mjs.map → chunk-E62NBNHE.mjs.map} +0 -0
- /package/dist/esm/{chunk-NGTNMV6Q.mjs.map → chunk-EFMAZTIM.mjs.map} +0 -0
- /package/dist/esm/{chunk-UFMIMN7W.mjs.map → chunk-EJA532W4.mjs.map} +0 -0
- /package/dist/esm/{chunk-OOYRJQPD.mjs.map → chunk-EJQ2EYJ7.mjs.map} +0 -0
- /package/dist/esm/{chunk-WJIICWOB.mjs.map → chunk-ERPUZQVK.mjs.map} +0 -0
- /package/dist/esm/{chunk-WHSN42R2.mjs.map → chunk-F3ZVWLDH.mjs.map} +0 -0
- /package/dist/esm/{chunk-GS5Z3HO7.mjs.map → chunk-FGGRPEQ3.mjs.map} +0 -0
- /package/dist/esm/{chunk-EJ7ODMDA.mjs.map → chunk-FIG65OJD.mjs.map} +0 -0
- /package/dist/esm/{chunk-MSGHGK52.mjs.map → chunk-GRHLQDHF.mjs.map} +0 -0
- /package/dist/esm/{chunk-VMVSUH2K.mjs.map → chunk-GSCM444Z.mjs.map} +0 -0
- /package/dist/esm/{chunk-QJIMZI32.mjs.map → chunk-GTXZNAYI.mjs.map} +0 -0
- /package/dist/esm/{chunk-ZV5P2GSJ.mjs.map → chunk-IBN7ETCB.mjs.map} +0 -0
- /package/dist/esm/{chunk-DSVNXD5A.mjs.map → chunk-IPI3VB62.mjs.map} +0 -0
- /package/dist/esm/{chunk-XQ7I34AL.mjs.map → chunk-IXFYYWAC.mjs.map} +0 -0
- /package/dist/esm/{chunk-HGRU3HWY.mjs.map → chunk-J63BIFB7.mjs.map} +0 -0
- /package/dist/esm/{chunk-Y24BMR2W.mjs.map → chunk-JBX3JBIW.mjs.map} +0 -0
- /package/dist/esm/{chunk-SSDWEOF7.mjs.map → chunk-JEE2OXOZ.mjs.map} +0 -0
- /package/dist/esm/{chunk-6MDYCC7P.mjs.map → chunk-JV6JCXCH.mjs.map} +0 -0
- /package/dist/esm/{chunk-OZ3GSAFK.mjs.map → chunk-KGHBTSDR.mjs.map} +0 -0
- /package/dist/esm/{chunk-3SXTTG2X.mjs.map → chunk-L5CPAOUM.mjs.map} +0 -0
- /package/dist/esm/{chunk-VBODXPT3.mjs.map → chunk-MLX6DFMR.mjs.map} +0 -0
- /package/dist/esm/{chunk-SNBE5YAC.mjs.map → chunk-MMM5NTKW.mjs.map} +0 -0
- /package/dist/esm/{chunk-OFC75EWS.mjs.map → chunk-MPTKOK27.mjs.map} +0 -0
- /package/dist/esm/{chunk-4VAYXBD2.mjs.map → chunk-NW3WUTTD.mjs.map} +0 -0
- /package/dist/esm/{chunk-AUV4VAXK.mjs.map → chunk-NZBZV7RP.mjs.map} +0 -0
- /package/dist/esm/{chunk-QYEJOEWB.mjs.map → chunk-O3BRX56F.mjs.map} +0 -0
- /package/dist/esm/{chunk-QLE5JL4X.mjs.map → chunk-OJ6AF4YT.mjs.map} +0 -0
- /package/dist/esm/{chunk-5SGIYAB7.mjs.map → chunk-OR27VDOE.mjs.map} +0 -0
- /package/dist/esm/{chunk-M4Q4XDVR.mjs.map → chunk-PAJXNH6J.mjs.map} +0 -0
- /package/dist/esm/{chunk-THURV6CN.mjs.map → chunk-QMYYNCC2.mjs.map} +0 -0
- /package/dist/esm/{chunk-RWYPGTNL.mjs.map → chunk-SNDFJWYM.mjs.map} +0 -0
- /package/dist/esm/{chunk-3YIUOKWW.mjs.map → chunk-T5YEMU53.mjs.map} +0 -0
- /package/dist/esm/{chunk-34WI7I3Z.mjs.map → chunk-TDDJZLWB.mjs.map} +0 -0
- /package/dist/esm/{chunk-MLQT5I6K.mjs.map → chunk-TUCCV62K.mjs.map} +0 -0
- /package/dist/esm/{chunk-YLQJBXUF.mjs.map → chunk-TV7RXL3V.mjs.map} +0 -0
- /package/dist/esm/{chunk-7QGIAVW4.mjs.map → chunk-UBON2G6Y.mjs.map} +0 -0
- /package/dist/esm/{chunk-AUAL3H36.mjs.map → chunk-WA2NTBYY.mjs.map} +0 -0
- /package/dist/esm/{chunk-IWKIZLFW.mjs.map → chunk-WT5HOIK6.mjs.map} +0 -0
- /package/dist/esm/{chunk-V6M7FGQT.mjs.map → chunk-X2VUS374.mjs.map} +0 -0
- /package/dist/esm/{chunk-PENBUSGL.mjs.map → chunk-XH33BXEY.mjs.map} +0 -0
- /package/dist/esm/{chunk-WOLLRMXR.mjs.map → chunk-XVZBWW46.mjs.map} +0 -0
- /package/dist/esm/{chunk-IU6REVKX.mjs.map → chunk-YDNOKWV3.mjs.map} +0 -0
- /package/dist/esm/{chunk-CZOUSIAD.mjs.map → chunk-YDSBZMZB.mjs.map} +0 -0
- /package/dist/esm/{chunk-GHHIUWPP.mjs.map → chunk-YRUF6N3U.mjs.map} +0 -0
- /package/dist/esm/{chunk-SCRIQQV3.mjs.map → chunk-Z6FMMNAL.mjs.map} +0 -0
- /package/dist/esm/{chunk-TU6VKYDC.mjs.map → chunk-ZNPEUH4I.mjs.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internal/transactionSubmission.ts"],"sourcesContent":["/**\n * This file contains the underlying implementations for exposed submission API surface in\n * the {@link api/transaction}. By moving the methods out into a separate file,\n * other namespaces and processes can access these methods without depending on the entire\n * transaction namespace and without having a dependency cycle error.\n */\n\nimport { AptosConfig } from \"../api/aptosConfig\";\nimport { MoveVector, U8 } from \"../bcs\";\nimport { AptosApiError, postAptosFullNode } from \"../client\";\nimport { Account, KeylessAccount, KeylessError, MultiKeyAccount } from \"../account\";\nimport { AccountAddress, AccountAddressInput } from \"../core/accountAddress\";\nimport { PrivateKey } from \"../core/crypto\";\nimport { AccountAuthenticator } from \"../transactions/authenticator/account\";\nimport { RotationProofChallenge } from \"../transactions/instances/rotationProofChallenge\";\nimport {\n buildTransaction,\n generateTransactionPayload,\n generateSignedTransactionForSimulation,\n generateSignedTransaction,\n} from \"../transactions/transactionBuilder/transactionBuilder\";\nimport {\n InputGenerateTransactionData,\n AnyRawTransaction,\n InputSimulateTransactionData,\n InputGenerateTransactionOptions,\n InputGenerateTransactionPayloadDataWithRemoteABI,\n InputSubmitTransactionData,\n InputGenerateMultiAgentRawTransactionData,\n InputGenerateSingleSignerRawTransactionData,\n AnyTransactionPayloadInstance,\n EntryFunctionABI,\n} from \"../transactions/types\";\nimport { getInfo } from \"./account\";\nimport { UserTransactionResponse, PendingTransactionResponse, MimeType, HexInput, TransactionResponse } from \"../types\";\nimport { TypeTagU8, TypeTagVector, generateSigningMessageForTransaction } from \"../transactions\";\nimport { SimpleTransaction } from \"../transactions/instances/simpleTransaction\";\nimport { MultiAgentTransaction } from \"../transactions/instances/multiAgentTransaction\";\n\n/**\n * We are defining function signatures, each with its specific input and output.\n * These are the possible function signature for `generateTransaction` function.\n * When we call `generateTransaction` function with the relevant type properties,\n * Typescript can infer the return type based on the appropriate function overload.\n */\nexport async function generateTransaction(\n args: { aptosConfig: AptosConfig } & InputGenerateSingleSignerRawTransactionData,\n): Promise<SimpleTransaction>;\nexport async function generateTransaction(\n args: { aptosConfig: AptosConfig } & InputGenerateMultiAgentRawTransactionData,\n): Promise<MultiAgentTransaction>;\n/**\n * Generates any transaction by passing in the required arguments\n *\n * @param args.sender The transaction sender's account address as a AccountAddressInput\n * @param args.data EntryFunctionData | ScriptData | MultiSigData\n * @param args.feePayerAddress optional. For a fee payer (aka sponsored) transaction\n * @param args.secondarySignerAddresses optional. For a multi-agent or fee payer (aka sponsored) transactions\n * @param args.options optional. GenerateTransactionOptions type\n *\n * @example\n * For a single signer entry function\n * move function name, move function type arguments, move function arguments\n * `\n * data: {\n * function:\"0x1::aptos_account::transfer\",\n * typeArguments:[]\n * functionArguments :[receiverAddress,10]\n * }\n * `\n *\n * @example\n * For a single signer script function\n * module bytecode, move function type arguments, move function arguments\n * ```\n * data: {\n * bytecode:\"0x001234567\",\n * typeArguments:[],\n * functionArguments :[receiverAddress,10]\n * }\n * ```\n *\n * @return An instance of a RawTransaction, plus optional secondary/fee payer addresses\n * ```\n * {\n * rawTransaction: RawTransaction,\n * secondarySignerAddresses? : Array<AccountAddress>,\n * feePayerAddress?: AccountAddress\n * }\n * ```\n */\nexport async function generateTransaction(\n args: { aptosConfig: AptosConfig } & InputGenerateTransactionData,\n): Promise<AnyRawTransaction> {\n const payload = await buildTransactionPayload(args);\n return buildRawTransaction(args, payload);\n}\n\nexport async function buildTransactionPayload(\n args: { aptosConfig: AptosConfig } & InputGenerateTransactionData,\n): Promise<AnyTransactionPayloadInstance> {\n const { aptosConfig, data } = args;\n // Merge in aptosConfig for remote ABI on non-script payloads\n let generateTransactionPayloadData: InputGenerateTransactionPayloadDataWithRemoteABI;\n let payload: AnyTransactionPayloadInstance;\n\n if (\"bytecode\" in data) {\n // TODO: Add ABI checking later\n payload = await generateTransactionPayload(data);\n } else if (\"multisigAddress\" in data) {\n generateTransactionPayloadData = {\n aptosConfig,\n multisigAddress: data.multisigAddress,\n function: data.function,\n functionArguments: data.functionArguments,\n typeArguments: data.typeArguments,\n abi: data.abi,\n };\n payload = await generateTransactionPayload(generateTransactionPayloadData);\n } else {\n generateTransactionPayloadData = {\n aptosConfig,\n function: data.function,\n functionArguments: data.functionArguments,\n typeArguments: data.typeArguments,\n abi: data.abi,\n };\n payload = await generateTransactionPayload(generateTransactionPayloadData);\n }\n return payload;\n}\n\nexport async function buildRawTransaction(\n args: { aptosConfig: AptosConfig } & InputGenerateTransactionData,\n payload: AnyTransactionPayloadInstance,\n): Promise<AnyRawTransaction> {\n const { aptosConfig, sender, options } = args;\n\n let feePayerAddress;\n if (isFeePayerTransactionInput(args)) {\n feePayerAddress = AccountAddress.ZERO.toString();\n }\n\n if (isMultiAgentTransactionInput(args)) {\n const { secondarySignerAddresses } = args;\n return buildTransaction({\n aptosConfig,\n sender,\n payload,\n options,\n secondarySignerAddresses,\n feePayerAddress,\n });\n }\n\n return buildTransaction({\n aptosConfig,\n sender,\n payload,\n options,\n feePayerAddress,\n });\n}\n\nfunction isFeePayerTransactionInput(data: InputGenerateTransactionData): boolean {\n return data.withFeePayer === true;\n}\n\nfunction isMultiAgentTransactionInput(\n data: InputGenerateTransactionData,\n): data is InputGenerateMultiAgentRawTransactionData {\n return \"secondarySignerAddresses\" in data;\n}\n\n/**\n * Builds a signing message that can be signed by external signers\n *\n * Note: Please prefer using `signTransaction` unless signing outside the SDK\n *\n * @param args.transaction AnyRawTransaction, as generated by `generateTransaction()`\n *\n * @return The message to be signed\n */\nexport function getSigningMessage(args: { transaction: AnyRawTransaction }): Uint8Array {\n const { transaction } = args;\n return generateSigningMessageForTransaction(transaction);\n}\n\n/**\n * Sign a transaction that can later be submitted to chain\n *\n * @param args.signer The signer account to sign the transaction\n * @param args.transaction An instance of a RawTransaction, plus optional secondary/fee payer addresses\n * ```\n * {\n * rawTransaction: RawTransaction,\n * secondarySignerAddresses? : Array<AccountAddress>,\n * feePayerAddress?: AccountAddress\n * }\n * ```\n *\n * @return The signer AccountAuthenticator\n */\nexport function signTransaction(args: { signer: Account; transaction: AnyRawTransaction }): AccountAuthenticator {\n const { signer, transaction } = args;\n return signer.signTransactionWithAuthenticator(transaction);\n}\n\n/**\n * Simulates a transaction before singing it.\n *\n * @param args.signerPublicKey The signer public key\n * @param args.transaction The raw transaction to simulate\n * @param args.secondarySignersPublicKeys optional. For when the transaction is a multi signers transaction\n * @param args.feePayerPublicKey optional. For when the transaction is a fee payer (aka sponsored) transaction\n * @param args.options optional. A config to simulate the transaction with\n */\nexport async function simulateTransaction(\n args: { aptosConfig: AptosConfig } & InputSimulateTransactionData,\n): Promise<Array<UserTransactionResponse>> {\n const { aptosConfig, transaction, signerPublicKey, secondarySignersPublicKeys, feePayerPublicKey, options } = args;\n\n const signedTransaction = generateSignedTransactionForSimulation({\n transaction,\n signerPublicKey,\n secondarySignersPublicKeys,\n feePayerPublicKey,\n options,\n });\n\n const { data } = await postAptosFullNode<Uint8Array, Array<UserTransactionResponse>>({\n aptosConfig,\n body: signedTransaction,\n path: \"transactions/simulate\",\n params: {\n estimate_gas_unit_price: args.options?.estimateGasUnitPrice ?? false,\n estimate_max_gas_amount: args.options?.estimateMaxGasAmount ?? false,\n estimate_prioritized_gas_unit_price: args.options?.estimatePrioritizedGasUnitPrice ?? false,\n },\n originMethod: \"simulateTransaction\",\n contentType: MimeType.BCS_SIGNED_TRANSACTION,\n });\n return data;\n}\n\n/**\n * Submit transaction to chain\n *\n * @param args.transaction A aptos transaction type\n * @param args.senderAuthenticator The account authenticator of the transaction sender\n * @param args.secondarySignerAuthenticators optional. For when the transaction is a multi signers transaction\n *\n * @return PendingTransactionResponse\n */\nexport async function submitTransaction(\n args: {\n aptosConfig: AptosConfig;\n } & InputSubmitTransactionData,\n): Promise<PendingTransactionResponse> {\n const { aptosConfig } = args;\n const signedTransaction = generateSignedTransaction({ ...args });\n const { data } = await postAptosFullNode<Uint8Array, PendingTransactionResponse>({\n aptosConfig,\n body: signedTransaction,\n path: \"transactions\",\n originMethod: \"submitTransaction\",\n contentType: MimeType.BCS_SIGNED_TRANSACTION,\n });\n return data;\n}\n\nexport async function signAndSubmitTransaction(args: {\n aptosConfig: AptosConfig;\n signer: Account;\n transaction: AnyRawTransaction;\n}): Promise<PendingTransactionResponse> {\n const { aptosConfig, signer, transaction } = args;\n // If the signer contains a KeylessAccount, await proof fetching in case the proof\n // was fetched asyncronously.\n if (signer instanceof KeylessAccount || signer instanceof MultiKeyAccount) {\n await signer.waitForProofFetch();\n }\n const authenticator = signTransaction({ signer, transaction });\n return submitTransaction({\n aptosConfig,\n transaction,\n senderAuthenticator: authenticator,\n });\n}\n\nconst packagePublishAbi: EntryFunctionABI = {\n typeParameters: [],\n parameters: [TypeTagVector.u8(), new TypeTagVector(TypeTagVector.u8())],\n};\n\nexport async function publicPackageTransaction(args: {\n aptosConfig: AptosConfig;\n account: AccountAddressInput;\n metadataBytes: HexInput;\n moduleBytecode: Array<HexInput>;\n options?: InputGenerateTransactionOptions;\n}): Promise<SimpleTransaction> {\n const { aptosConfig, account, metadataBytes, moduleBytecode, options } = args;\n\n const totalByteCode = moduleBytecode.map((bytecode) => MoveVector.U8(bytecode));\n\n return generateTransaction({\n aptosConfig,\n sender: AccountAddress.from(account),\n data: {\n function: \"0x1::code::publish_package_txn\",\n functionArguments: [MoveVector.U8(metadataBytes), new MoveVector(totalByteCode)],\n abi: packagePublishAbi,\n },\n options,\n });\n}\n\nconst rotateAuthKeyAbi: EntryFunctionABI = {\n typeParameters: [],\n parameters: [\n new TypeTagU8(),\n TypeTagVector.u8(),\n new TypeTagU8(),\n TypeTagVector.u8(),\n TypeTagVector.u8(),\n TypeTagVector.u8(),\n ],\n};\n\n/**\n * TODO: Need to refactor and move this function out of transactionSubmission\n */\nexport async function rotateAuthKey(args: {\n aptosConfig: AptosConfig;\n fromAccount: Account;\n toNewPrivateKey: PrivateKey;\n}): Promise<TransactionResponse> {\n const { aptosConfig, fromAccount, toNewPrivateKey } = args;\n const accountInfo = await getInfo({\n aptosConfig,\n accountAddress: fromAccount.accountAddress,\n });\n\n const newAccount = Account.fromPrivateKey({ privateKey: toNewPrivateKey, legacy: true });\n\n const challenge = new RotationProofChallenge({\n sequenceNumber: BigInt(accountInfo.sequence_number),\n originator: fromAccount.accountAddress,\n currentAuthKey: AccountAddress.from(accountInfo.authentication_key),\n newPublicKey: newAccount.publicKey,\n });\n\n // Sign the challenge\n const challengeHex = challenge.bcsToBytes();\n const proofSignedByCurrentPrivateKey = fromAccount.sign(challengeHex);\n const proofSignedByNewPrivateKey = newAccount.sign(challengeHex);\n\n // Generate transaction\n const rawTxn = await generateTransaction({\n aptosConfig,\n sender: fromAccount.accountAddress,\n data: {\n function: \"0x1::account::rotate_authentication_key\",\n functionArguments: [\n new U8(fromAccount.signingScheme), // from scheme\n MoveVector.U8(fromAccount.publicKey.toUint8Array()),\n new U8(newAccount.signingScheme), // to scheme\n MoveVector.U8(newAccount.publicKey.toUint8Array()),\n MoveVector.U8(proofSignedByCurrentPrivateKey.toUint8Array()),\n MoveVector.U8(proofSignedByNewPrivateKey.toUint8Array()),\n ],\n abi: rotateAuthKeyAbi,\n },\n });\n return signAndSubmitTransaction({\n aptosConfig,\n signer: fromAccount,\n transaction: rawTxn,\n });\n}\n"],"mappings":"wgBA2FA,eAAsBA,EACpBC,EAC4B,CAC5B,IAAMC,EAAU,MAAMC,EAAwBF,CAAI,EAClD,OAAOG,EAAoBH,EAAMC,CAAO,CAC1C,CAEA,eAAsBC,EACpBF,EACwC,CACxC,GAAM,CAAE,YAAAI,EAAa,KAAAC,CAAK,EAAIL,EAE1BM,EACAL,EAEJ,MAAI,aAAcI,EAEhBJ,EAAU,MAAMM,EAA2BF,CAAI,EACtC,oBAAqBA,GAC9BC,EAAiC,CAC/B,YAAAF,EACA,gBAAiBC,EAAK,gBACtB,SAAUA,EAAK,SACf,kBAAmBA,EAAK,kBACxB,cAAeA,EAAK,cACpB,IAAKA,EAAK,GACZ,EACAJ,EAAU,MAAMM,EAA2BD,CAA8B,IAEzEA,EAAiC,CAC/B,YAAAF,EACA,SAAUC,EAAK,SACf,kBAAmBA,EAAK,kBACxB,cAAeA,EAAK,cACpB,IAAKA,EAAK,GACZ,EACAJ,EAAU,MAAMM,EAA2BD,CAA8B,GAEpEL,CACT,CAEA,eAAsBE,EACpBH,EACAC,EAC4B,CAC5B,GAAM,CAAE,YAAAG,EAAa,OAAAI,EAAQ,QAAAC,CAAQ,EAAIT,EAErCU,EAKJ,GAJIC,EAA2BX,CAAI,IACjCU,EAAkBE,EAAe,KAAK,SAAS,GAG7CC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Aa,gBAAAC,CAAgB,EAAI/C,EAChDgD,EAAc,MAAMC,EAAQ,CAChC,YAAA7C,EACA,eAAgB0C,EAAY,cAC9B,CAAC,EAEKI,EAAaC,EAAQ,eAAe,CAAE,WAAYJ,EAAiB,OAAQ,EAAK,CAAC,EAUjFK,EARY,IAAIC,EAAuB,CAC3C,eAAgB,OAAOL,EAAY,eAAe,EAClD,WAAYF,EAAY,eACxB,eAAgBlC,EAAe,KAAKoC,EAAY,kBAAkB,EAClE,aAAcE,EAAW,SAC3B,CAAC,EAG8B,WAAW,EACpCI,EAAiCR,EAAY,KAAKM,CAAY,EAC9DG,EAA6BL,EAAW,KAAKE,CAAY,EAGzDI,EAAS,MAAMzD,EAAoB,CACvC,YAAAK,EACA,OAAQ0C,EAAY,eACpB,KAAM,CACJ,SAAU,0CACV,kBAAmB,CACjB,IAAIW,EAAGX,EAAY,aAAa,EAChCJ,EAAW,GAAGI,EAAY,UAAU,aAAa,CAAC,EAClD,IAAIW,EAAGP,EAAW,aAAa,EAC/BR,EAAW,GAAGQ,EAAW,UAAU,aAAa,CAAC,EACjDR,EAAW,GAAGY,EAA+B,aAAa,CAAC,EAC3DZ,EAAW,GAAGa,EAA2B,aAAa,CAAC,CACzD,EACA,IAAKZ,CACP,CACF,CAAC,EACD,OAAOb,EAAyB,CAC9B,YAAA1B,EACA,OAAQ0C,EACR,YAAaU,CACf,CAAC,CACH","names":["generateTransaction","args","payload","buildTransactionPayload","buildRawTransaction","aptosConfig","data","generateTransactionPayloadData","generateTransactionPayload","sender","options","feePayerAddress","isFeePayerTransactionInput","AccountAddress","isMultiAgentTransactionInput","secondarySignerAddresses","buildTransaction","getSigningMessage","transaction","generateSigningMessageForTransaction","signTransaction","signer","simulateTransaction","signerPublicKey","secondarySignersPublicKeys","feePayerPublicKey","signedTransaction","generateSignedTransactionForSimulation","postAptosFullNode","submitTransaction","generateSignedTransaction","signAndSubmitTransaction","KeylessAccount","MultiKeyAccount","authenticator","packagePublishAbi","TypeTagVector","publicPackageTransaction","account","metadataBytes","moduleBytecode","totalByteCode","bytecode","MoveVector","rotateAuthKeyAbi","TypeTagU8","rotateAuthKey","fromAccount","toNewPrivateKey","accountInfo","getInfo","newAccount","Account","challengeHex","RotationProofChallenge","proofSignedByCurrentPrivateKey","proofSignedByNewPrivateKey","rawTxn","U8"]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as c}from"./chunk-THURV6CN.mjs";import{a as e,b as s,c as r,d as n,e as t,g as i,h as a}from"./chunk-7Y6AWDBZ.mjs";var g=class{constructor(o){this.config=o}async getLedgerInfo(){return e({aptosConfig:this.config})}async getChainId(){return(await this.getLedgerInfo()).chain_id}async getBlockByVersion(o){return s({aptosConfig:this.config,...o})}async getBlockByHeight(o){return r({aptosConfig:this.config,...o})}async view(o){return c({aptosConfig:this.config,...o})}async getChainTopUserTransactions(o){return n({aptosConfig:this.config,...o})}async queryIndexer(o){return t({aptosConfig:this.config,...o})}async getIndexerLastSuccessVersion(){return i({aptosConfig:this.config})}async getProcessorStatus(o){return a({aptosConfig:this.config,processorType:o})}};export{g as a};
|
|
2
|
-
//# sourceMappingURL=chunk-7CJAEAQZ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/general.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { AptosConfig } from \"./aptosConfig\";\nimport {\n getBlockByHeight,\n getBlockByVersion,\n getChainTopUserTransactions,\n getIndexerLastSuccessVersion,\n getLedgerInfo,\n getProcessorStatus,\n queryIndexer,\n} from \"../internal/general\";\nimport { view } from \"../internal/view\";\nimport {\n AnyNumber,\n Block,\n GetChainTopUserTransactionsResponse,\n GetProcessorStatusResponse,\n GraphqlQuery,\n LedgerInfo,\n LedgerVersionArg,\n MoveValue,\n} from \"../types\";\nimport { ProcessorType } from \"../utils/const\";\nimport { InputViewFunctionData } from \"../transactions\";\n\n/**\n * A class to query all `General` Aptos related queries\n */\nexport class General {\n readonly config: AptosConfig;\n\n constructor(config: AptosConfig) {\n this.config = config;\n }\n\n /**\n * Queries for the Aptos ledger info\n *\n * @returns Aptos Ledger Info\n *\n * @example\n * const ledgerInfo = await aptos.getLedgerInfo()\n * // an example of the returned data\n * ```\n * {\n * \"chain_id\": 4,\n * \"epoch\": \"8\",\n * \"ledger_version\": \"714\",\n * \"oldest_ledger_version\": \"0\",\n * \"ledger_timestamp\": \"1694695496521775\",\n * \"node_role\": \"validator\",\n * \"oldest_block_height\": \"0\",\n * \"block_height\": \"359\",\n * \"git_hash\": \"c82193f36f4e185fed9f68c4ad21f6c6dd390c6e\"\n * }\n * ```\n */\n async getLedgerInfo(): Promise<LedgerInfo> {\n return getLedgerInfo({ aptosConfig: this.config });\n }\n\n /**\n * Queries for the chain id\n *\n * @example\n * const chainId = await aptos.getChainId()\n *\n * @returns The chain id\n */\n async getChainId(): Promise<number> {\n const result = await this.getLedgerInfo();\n return result.chain_id;\n }\n\n /**\n * Queries for block by transaction version\n *\n * @example\n * const block = await aptos.getBlockByVersion({ledgerVersion:5})\n *\n * @param args.ledgerVersion Ledger version to lookup block information for\n * @param args.options.withTransactions If set to true, include all transactions in the block\n *\n * @returns Block information with optional transactions\n */\n async getBlockByVersion(args: {\n ledgerVersion: AnyNumber;\n options?: { withTransactions?: boolean };\n }): Promise<Block> {\n return getBlockByVersion({\n aptosConfig: this.config,\n ...args,\n });\n }\n\n /**\n * Get block by block height\n *\n * @example\n * const block = await aptos.getBlockByVersion({blockHeight:5})\n *\n * @param args.blockHeight Block height to lookup. Starts at 0\n * @param args.options.withTransactions If set to true, include all transactions in the block\n *\n * @returns Block with optional transactions\n */\n async getBlockByHeight(args: { blockHeight: AnyNumber; options?: { withTransactions?: boolean } }): Promise<Block> {\n return getBlockByHeight({ aptosConfig: this.config, ...args });\n }\n\n /**\n * Queries for a Move view function\n * @param args.payload Payload for the view function\n * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version\n *\n * @example\n * const data = await aptos.view({\n * payload: {\n * function: \"0x1::coin::balance\",\n * typeArguments: [\"0x1::aptos_coin::AptosCoin\"],\n * functionArguments: [accountAddress],\n * }\n * })\n *\n * @returns an array of Move values\n */\n async view<T extends Array<MoveValue>>(args: {\n payload: InputViewFunctionData;\n options?: LedgerVersionArg;\n }): Promise<T> {\n return view<T>({ aptosConfig: this.config, ...args });\n }\n\n /**\n * Queries top user transactions\n *\n * @example\n * const topUserTransactions = await aptos.getChainTopUserTransactions({limit:5})\n *\n * @param args.limit The number of transactions to return\n * @returns GetChainTopUserTransactionsResponse\n */\n async getChainTopUserTransactions(args: { limit: number }): Promise<GetChainTopUserTransactionsResponse> {\n return getChainTopUserTransactions({\n aptosConfig: this.config,\n ...args,\n });\n }\n\n /**\n * A generic function for retrieving data from Aptos Indexer.\n * For more detailed queries specification see\n * {@link https://cloud.hasura.io/public/graphiql?endpoint=https://api.mainnet.aptoslabs.com/v1/graphql}\n *\n * @example\n * const topUserTransactions = await aptos.queryIndexer({\n * query: `query MyQuery {\n * ledger_infos {\n * chain_id\n * }}`;\n * })\n *\n * @param args.query.query A GraphQL query\n * @param args.query.variables The variables for the query\n *\n * @return The provided T type\n */\n async queryIndexer<T extends {}>(args: { query: GraphqlQuery }): Promise<T> {\n return queryIndexer<T>({\n aptosConfig: this.config,\n ...args,\n });\n }\n\n /**\n * Queries for the last successful indexer version\n *\n * This is useful to tell what ledger version the indexer is updated to, as it can be behind the full nodes.\n *\n * @example\n * const version = await aptos.getIndexerLastSuccessVersion()\n */\n async getIndexerLastSuccessVersion(): Promise<bigint> {\n return getIndexerLastSuccessVersion({ aptosConfig: this.config });\n }\n\n /**\n * Query the processor status for a specific processor type.\n *\n * @example\n * const status = await aptos.getProcessorStatus({processorType:\"account_transactions_processor\"})\n *\n * @param processorType The processor type to query\n * @returns\n */\n async getProcessorStatus(processorType: ProcessorType): Promise<GetProcessorStatusResponse[0]> {\n return getProcessorStatus({ aptosConfig: this.config, processorType });\n }\n}\n"],"mappings":"4HA8BO,IAAMA,EAAN,KAAc,CAGnB,YAAYC,EAAqB,CAC/B,KAAK,OAASA,CAChB,CAwBA,MAAM,eAAqC,CACzC,OAAOC,EAAc,CAAE,YAAa,KAAK,MAAO,CAAC,CACnD,CAUA,MAAM,YAA8B,CAElC,OADe,MAAM,KAAK,cAAc,GAC1B,QAChB,CAaA,MAAM,kBAAkBC,EAGL,CACjB,OAAOC,EAAkB,CACvB,YAAa,KAAK,OAClB,GAAGD,CACL,CAAC,CACH,CAaA,MAAM,iBAAiBA,EAA4F,CACjH,OAAOE,EAAiB,CAAE,YAAa,KAAK,OAAQ,GAAGF,CAAK,CAAC,CAC/D,CAkBA,MAAM,KAAiCA,EAGxB,CACb,OAAOG,EAAQ,CAAE,YAAa,KAAK,OAAQ,GAAGH,CAAK,CAAC,CACtD,CAWA,MAAM,4BAA4BA,EAAuE,CACvG,OAAOI,EAA4B,CACjC,YAAa,KAAK,OAClB,GAAGJ,CACL,CAAC,CACH,CAoBA,MAAM,aAA2BA,EAA2C,CAC1E,OAAOK,EAAgB,CACrB,YAAa,KAAK,OAClB,GAAGL,CACL,CAAC,CACH,CAUA,MAAM,8BAAgD,CACpD,OAAOM,EAA6B,CAAE,YAAa,KAAK,MAAO,CAAC,CAClE,CAWA,MAAM,mBAAmBC,EAAsE,CAC7F,OAAOC,EAAmB,CAAE,YAAa,KAAK,OAAQ,cAAAD,CAAc,CAAC,CACvE,CACF","names":["General","config","getLedgerInfo","args","getBlockByVersion","getBlockByHeight","view","getChainTopUserTransactions","queryIndexer","getIndexerLastSuccessVersion","processorType","getProcessorStatus"]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{m as p,v as a}from"./chunk-S3EDNXZE.mjs";import{b as n}from"./chunk-M4Q4XDVR.mjs";import{c}from"./chunk-WSVJNBSJ.mjs";async function h(o){let{aptosConfig:t}=o,{data:s}=await n({aptosConfig:t,originMethod:"getLedgerInfo",path:""});return s}async function d(o){let{aptosConfig:t,ledgerVersion:s,options:e}=o,{data:r}=await n({aptosConfig:t,originMethod:"getBlockByVersion",path:`blocks/by_version/${s}`,params:{with_transactions:e?.withTransactions}});return r}async function C(o){let{aptosConfig:t,blockHeight:s,options:e}=o,{data:r}=await n({aptosConfig:t,originMethod:"getBlockByHeight",path:`blocks/by_height/${s}`,params:{with_transactions:e?.withTransactions}});return r}async function l(o){let{aptosConfig:t,limit:s}=o;return(await i({aptosConfig:t,query:{query:p,variables:{limit:s}},originMethod:"getChainTopUserTransactions"})).user_transactions}async function i(o){let{aptosConfig:t,query:s,originMethod:e}=o,{data:r}=await c({aptosConfig:t,originMethod:e??"queryIndexer",path:"",body:s,overrides:{WITH_CREDENTIALS:!1}});return r}async function g(o){let{aptosConfig:t}=o;return(await i({aptosConfig:t,query:{query:a},originMethod:"getProcessorStatuses"})).processor_status}async function m(o){let t=await g({aptosConfig:o.aptosConfig});return BigInt(t[0].last_success_version)}async function T(o){let{aptosConfig:t,processorType:s}=o;return(await i({aptosConfig:t,query:{query:a,variables:{where_condition:{processor:{_eq:s}}}},originMethod:"getProcessorStatus"})).processor_status[0]}export{h as a,d as b,C as c,l as d,i as e,g as f,m as g,T as h};
|
|
2
|
-
//# sourceMappingURL=chunk-7Y6AWDBZ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internal/general.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * This file contains the underlying implementations for exposed API surface in\n * the {@link api/general}. By moving the methods out into a separate file,\n * other namespaces and processes can access these methods without depending on the entire\n * general namespace and without having a dependency cycle error.\n */\n\nimport { AptosConfig } from \"../api/aptosConfig\";\nimport { getAptosFullNode, postAptosIndexer } from \"../client\";\nimport {\n AnyNumber,\n Block,\n GetChainTopUserTransactionsResponse,\n GetProcessorStatusResponse,\n GraphqlQuery,\n LedgerInfo,\n} from \"../types\";\nimport { GetChainTopUserTransactionsQuery, GetProcessorStatusQuery } from \"../types/generated/operations\";\nimport { GetChainTopUserTransactions, GetProcessorStatus } from \"../types/generated/queries\";\nimport { ProcessorType } from \"../utils/const\";\n\nexport async function getLedgerInfo(args: { aptosConfig: AptosConfig }): Promise<LedgerInfo> {\n const { aptosConfig } = args;\n const { data } = await getAptosFullNode<{}, LedgerInfo>({\n aptosConfig,\n originMethod: \"getLedgerInfo\",\n path: \"\",\n });\n return data;\n}\n\nexport async function getBlockByVersion(args: {\n aptosConfig: AptosConfig;\n ledgerVersion: AnyNumber;\n options?: { withTransactions?: boolean };\n}): Promise<Block> {\n const { aptosConfig, ledgerVersion, options } = args;\n const { data } = await getAptosFullNode<{}, Block>({\n aptosConfig,\n originMethod: \"getBlockByVersion\",\n path: `blocks/by_version/${ledgerVersion}`,\n params: { with_transactions: options?.withTransactions },\n });\n return data;\n}\n\nexport async function getBlockByHeight(args: {\n aptosConfig: AptosConfig;\n blockHeight: AnyNumber;\n options?: { withTransactions?: boolean };\n}): Promise<Block> {\n const { aptosConfig, blockHeight, options } = args;\n const { data } = await getAptosFullNode<{}, Block>({\n aptosConfig,\n originMethod: \"getBlockByHeight\",\n path: `blocks/by_height/${blockHeight}`,\n params: { with_transactions: options?.withTransactions },\n });\n return data;\n}\n\nexport async function getChainTopUserTransactions(args: {\n aptosConfig: AptosConfig;\n limit: number;\n}): Promise<GetChainTopUserTransactionsResponse> {\n const { aptosConfig, limit } = args;\n const graphqlQuery = {\n query: GetChainTopUserTransactions,\n variables: { limit },\n };\n\n const data = await queryIndexer<GetChainTopUserTransactionsQuery>({\n aptosConfig,\n query: graphqlQuery,\n originMethod: \"getChainTopUserTransactions\",\n });\n\n return data.user_transactions;\n}\n\nexport async function queryIndexer<T extends {}>(args: {\n aptosConfig: AptosConfig;\n query: GraphqlQuery;\n originMethod?: string;\n}): Promise<T> {\n const { aptosConfig, query, originMethod } = args;\n const { data } = await postAptosIndexer<GraphqlQuery, T>({\n aptosConfig,\n originMethod: originMethod ?? \"queryIndexer\",\n path: \"\",\n body: query,\n overrides: { WITH_CREDENTIALS: false },\n });\n return data;\n}\n\nexport async function getProcessorStatuses(args: { aptosConfig: AptosConfig }): Promise<GetProcessorStatusResponse> {\n const { aptosConfig } = args;\n\n const graphqlQuery = {\n query: GetProcessorStatus,\n };\n\n const data = await queryIndexer<GetProcessorStatusQuery>({\n aptosConfig,\n query: graphqlQuery,\n originMethod: \"getProcessorStatuses\",\n });\n\n return data.processor_status;\n}\n\nexport async function getIndexerLastSuccessVersion(args: { aptosConfig: AptosConfig }): Promise<bigint> {\n const response = await getProcessorStatuses({ aptosConfig: args.aptosConfig });\n return BigInt(response[0].last_success_version);\n}\n\nexport async function getProcessorStatus(args: {\n aptosConfig: AptosConfig;\n processorType: ProcessorType;\n}): Promise<GetProcessorStatusResponse[0]> {\n const { aptosConfig, processorType } = args;\n\n const whereCondition: { processor: { _eq: string } } = {\n processor: { _eq: processorType },\n };\n\n const graphqlQuery = {\n query: GetProcessorStatus,\n variables: {\n where_condition: whereCondition,\n },\n };\n\n const data = await queryIndexer<GetProcessorStatusQuery>({\n aptosConfig,\n query: graphqlQuery,\n originMethod: \"getProcessorStatus\",\n });\n\n return data.processor_status[0];\n}\n"],"mappings":"6HAwBA,eAAsBA,EAAcC,EAAyD,CAC3F,GAAM,CAAE,YAAAC,CAAY,EAAID,EAClB,CAAE,KAAAE,CAAK,EAAI,MAAMC,EAAiC,CACtD,YAAAF,EACA,aAAc,gBACd,KAAM,EACR,CAAC,EACD,OAAOC,CACT,CAEA,eAAsBE,EAAkBJ,EAIrB,CACjB,GAAM,CAAE,YAAAC,EAAa,cAAAI,EAAe,QAAAC,CAAQ,EAAIN,EAC1C,CAAE,KAAAE,CAAK,EAAI,MAAMC,EAA4B,CACjD,YAAAF,EACA,aAAc,oBACd,KAAM,qBAAqBI,CAAa,GACxC,OAAQ,CAAE,kBAAmBC,GAAS,gBAAiB,CACzD,CAAC,EACD,OAAOJ,CACT,CAEA,eAAsBK,EAAiBP,EAIpB,CACjB,GAAM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c,CAClC,CAME,CACF,EAKE,aAAc,oBAChB,CAAC,GAEW,iBAAiB,CAAC,CAChC","names":["getLedgerInfo","args","aptosConfig","data","getAptosFullNode","getBlockByVersion","ledgerVersion","options","getBlockByHeight","blockHeight","getChainTopUserTransactions","limit","queryIndexer","GetChainTopUserTransactions","query","originMethod","postAptosIndexer","getProcessorStatuses","GetProcessorStatus","getIndexerLastSuccessVersion","response","getProcessorStatus","processorType"]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{g as x,h as P}from"./chunk-7Y6AWDBZ.mjs";import{a as R}from"./chunk-AH44UPM4.mjs";import{b as c,d as A}from"./chunk-M4Q4XDVR.mjs";import{a as C}from"./chunk-RKHPXZM6.mjs";import{a as h}from"./chunk-JCDZ2WXX.mjs";import{d as w}from"./chunk-YE5B2S5L.mjs";async function v(s){let{aptosConfig:n,options:t}=s;return A({aptosConfig:n,originMethod:"getTransactions",path:"transactions",params:{start:t?.offset,limit:t?.limit}})}async function D(s){let{aptosConfig:n}=s;return R(async()=>{let{data:t}=await c({aptosConfig:n,originMethod:"getGasPriceEstimation",path:"estimate_gas_price"});return t},`gas-price-${n.network}`,1e3*60*5)()}async function N(s){let{aptosConfig:n,ledgerVersion:t}=s,{data:o}=await c({aptosConfig:n,originMethod:"getTransactionByVersion",path:`transactions/by_version/${t}`});return o}async function T(s){let{aptosConfig:n,transactionHash:t}=s,{data:o}=await c({aptosConfig:n,path:`transactions/by_hash/${t}`,originMethod:"getTransactionByHash"});return o}async function G(s){let{aptosConfig:n,transactionHash:t}=s;try{return(await T({aptosConfig:n,transactionHash:t})).type==="pending_transaction"}catch(o){if(o?.status===404)return!0;throw o}}async function b(s){let{aptosConfig:n,transactionHash:t}=s,{data:o}=await c({aptosConfig:n,path:`transactions/wait_by_hash/${t}`,originMethod:"longWaitForTransaction"});return o}async function W(s){let{aptosConfig:n,transactionHash:t,options:o}=s,r=o?.timeoutSecs??20,u=o?.checkSuccess??!0,a=!0,p=0,e,g,m=200,E=1.5;function d(i){if(!(i instanceof C)||(g=i,i.status!==404&&i.status>=400&&i.status<500))throw i}try{e=await T({aptosConfig:n,transactionHash:t}),a=e.type==="pending_transaction"}catch(i){d(i)}if(a){let i=Date.now();try{e=await b({aptosConfig:n,transactionHash:t}),a=e.type==="pending_transaction"}catch(l){d(l)}p=(Date.now()-i)/1e3}for(;a&&!(p>=r);){try{if(e=await T({aptosConfig:n,transactionHash:t}),a=e.type==="pending_transaction",!a)break}catch(i){d(i)}await h(m),p+=m/1e3,m*=E}if(e===void 0)throw g||new f(`Fetching transaction ${t} failed and timed out after ${r} seconds`,e);if(e.type==="pending_transaction")throw new f(`Transaction ${t} timed out in pending state after ${r} seconds`,e);if(!u)return e;if(!e.success)throw new y(`Transaction ${t} failed with an error: ${e.vm_status}`,e);return e}async function O(s){let{aptosConfig:n,processorType:t}=s,o=BigInt(s.minimumLedgerVersion),r=3e3,u=new Date().getTime(),a=BigInt(-1);for(;a<o;){if(new Date().getTime()-u>r)throw new Error("waitForLastSuccessIndexerVersionSync timeout");if(t===void 0?a=await x({aptosConfig:n}):a=(await P({aptosConfig:n,processorType:t})).last_success_version,a>=o)break;await h(200)}}var f=class extends Error{constructor(t,o){super(t);this.lastSubmittedTransaction=o}},y=class extends Error{constructor(t,o){super(t);this.transaction=o}};export{v as a,D as b,N as c,T as d,G as e,b as f,W as g,O as h,f as i,y as j};
|
|
2
|
-
//# sourceMappingURL=chunk-BNA3SGG6.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internal/transaction.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * This file contains the underlying implementations for exposed API surface in\n * the {@link api/transaction}. By moving the methods out into a separate file,\n * other namespaces and processes can access these methods without depending on the entire\n * transaction namespace and without having a dependency cycle error.\n */\n\nimport { AptosConfig } from \"../api/aptosConfig\";\nimport { AptosApiError, getAptosFullNode, paginateWithCursor } from \"../client\";\nimport {\n TransactionResponseType,\n type AnyNumber,\n type GasEstimation,\n type HexInput,\n type PaginationArgs,\n type TransactionResponse,\n WaitForTransactionOptions,\n CommittedTransactionResponse,\n} from \"../types\";\nimport { DEFAULT_TXN_TIMEOUT_SEC, ProcessorType } from \"../utils/const\";\nimport { sleep } from \"../utils/helpers\";\nimport { memoizeAsync } from \"../utils/memoize\";\nimport { getIndexerLastSuccessVersion, getProcessorStatus } from \"./general\";\n\nexport async function getTransactions(args: {\n aptosConfig: AptosConfig;\n options?: PaginationArgs;\n}): Promise<TransactionResponse[]> {\n const { aptosConfig, options } = args;\n return paginateWithCursor<{}, TransactionResponse[]>({\n aptosConfig,\n originMethod: \"getTransactions\",\n path: \"transactions\",\n params: { start: options?.offset, limit: options?.limit },\n });\n}\n\nexport async function getGasPriceEstimation(args: { aptosConfig: AptosConfig }) {\n const { aptosConfig } = args;\n\n return memoizeAsync(\n async () => {\n const { data } = await getAptosFullNode<{}, GasEstimation>({\n aptosConfig,\n originMethod: \"getGasPriceEstimation\",\n path: \"estimate_gas_price\",\n });\n return data;\n },\n `gas-price-${aptosConfig.network}`,\n 1000 * 60 * 5, // 5 minutes\n )();\n}\n\nexport async function getTransactionByVersion(args: {\n aptosConfig: AptosConfig;\n ledgerVersion: AnyNumber;\n}): Promise<TransactionResponse> {\n const { aptosConfig, ledgerVersion } = args;\n const { data } = await getAptosFullNode<{}, TransactionResponse>({\n aptosConfig,\n originMethod: \"getTransactionByVersion\",\n path: `transactions/by_version/${ledgerVersion}`,\n });\n return data;\n}\n\nexport async function getTransactionByHash(args: {\n aptosConfig: AptosConfig;\n transactionHash: HexInput;\n}): Promise<TransactionResponse> {\n const { aptosConfig, transactionHash } = args;\n const { data } = await getAptosFullNode<{}, TransactionResponse>({\n aptosConfig,\n path: `transactions/by_hash/${transactionHash}`,\n originMethod: \"getTransactionByHash\",\n });\n return data;\n}\n\nexport async function isTransactionPending(args: {\n aptosConfig: AptosConfig;\n transactionHash: HexInput;\n}): Promise<boolean> {\n const { aptosConfig, transactionHash } = args;\n try {\n const transaction = await getTransactionByHash({ aptosConfig, transactionHash });\n return transaction.type === TransactionResponseType.Pending;\n } catch (e: any) {\n if (e?.status === 404) {\n return true;\n }\n throw e;\n }\n}\n\nexport async function longWaitForTransaction(args: {\n aptosConfig: AptosConfig;\n transactionHash: HexInput;\n}): Promise<TransactionResponse> {\n const { aptosConfig, transactionHash } = args;\n const { data } = await getAptosFullNode<{}, TransactionResponse>({\n aptosConfig,\n path: `transactions/wait_by_hash/${transactionHash}`,\n originMethod: \"longWaitForTransaction\",\n });\n return data;\n}\n\nexport async function waitForTransaction(args: {\n aptosConfig: AptosConfig;\n transactionHash: HexInput;\n options?: WaitForTransactionOptions;\n}): Promise<CommittedTransactionResponse> {\n const { aptosConfig, transactionHash, options } = args;\n const timeoutSecs = options?.timeoutSecs ?? DEFAULT_TXN_TIMEOUT_SEC;\n const checkSuccess = options?.checkSuccess ?? true;\n\n let isPending = true;\n let timeElapsed = 0;\n let lastTxn: TransactionResponse | undefined;\n let lastError: AptosApiError | undefined;\n let backoffIntervalMs = 200;\n const backoffMultiplier = 1.5;\n\n function handleAPIError(e: any) {\n // In short, this means we will retry if it was an AptosApiError and the code was 404 or 5xx.\n const isAptosApiError = e instanceof AptosApiError;\n if (!isAptosApiError) {\n throw e; // This would be unexpected\n }\n lastError = e;\n const isRequestError = e.status !== 404 && e.status >= 400 && e.status < 500;\n if (isRequestError) {\n throw e;\n }\n }\n\n // check to see if the txn is already on the blockchain\n try {\n lastTxn = await getTransactionByHash({ aptosConfig, transactionHash });\n isPending = lastTxn.type === TransactionResponseType.Pending;\n } catch (e) {\n handleAPIError(e);\n }\n\n // If the transaction is pending, we do a long wait once to avoid polling\n if (isPending) {\n const startTime = Date.now();\n try {\n lastTxn = await longWaitForTransaction({ aptosConfig, transactionHash });\n isPending = lastTxn.type === TransactionResponseType.Pending;\n } catch (e) {\n handleAPIError(e);\n }\n timeElapsed = (Date.now() - startTime) / 1000;\n }\n\n // Now we do polling to see if the transaction is still pending\n while (isPending) {\n if (timeElapsed >= timeoutSecs) {\n break;\n }\n try {\n // eslint-disable-next-line no-await-in-loop\n lastTxn = await getTransactionByHash({ aptosConfig, transactionHash });\n\n isPending = lastTxn.type === TransactionResponseType.Pending;\n\n if (!isPending) {\n break;\n }\n } catch (e) {\n handleAPIError(e);\n }\n // eslint-disable-next-line no-await-in-loop\n await sleep(backoffIntervalMs);\n timeElapsed += backoffIntervalMs / 1000; // Convert to seconds\n backoffIntervalMs *= backoffMultiplier;\n }\n\n // There is a chance that lastTxn is still undefined. Let's throw the last error otherwise a WaitForTransactionError\n if (lastTxn === undefined) {\n if (lastError) {\n throw lastError;\n } else {\n throw new WaitForTransactionError(\n `Fetching transaction ${transactionHash} failed and timed out after ${timeoutSecs} seconds`,\n lastTxn,\n );\n }\n }\n\n if (lastTxn.type === TransactionResponseType.Pending) {\n throw new WaitForTransactionError(\n `Transaction ${transactionHash} timed out in pending state after ${timeoutSecs} seconds`,\n lastTxn,\n );\n }\n if (!checkSuccess) {\n return lastTxn;\n }\n if (!lastTxn.success) {\n throw new FailedTransactionError(\n `Transaction ${transactionHash} failed with an error: ${lastTxn.vm_status}`,\n lastTxn,\n );\n }\n\n return lastTxn;\n}\n\n/**\n * Waits for the indexer to sync up to the ledgerVersion. Timeout is 3 seconds.\n */\nexport async function waitForIndexer(args: {\n aptosConfig: AptosConfig;\n minimumLedgerVersion: AnyNumber;\n processorType?: ProcessorType;\n}): Promise<void> {\n const { aptosConfig, processorType } = args;\n const minimumLedgerVersion = BigInt(args.minimumLedgerVersion);\n const timeoutMilliseconds = 3000; // 3 seconds\n const startTime = new Date().getTime();\n let indexerVersion = BigInt(-1);\n\n while (indexerVersion < minimumLedgerVersion) {\n // check for timeout\n if (new Date().getTime() - startTime > timeoutMilliseconds) {\n throw new Error(\"waitForLastSuccessIndexerVersionSync timeout\");\n }\n\n if (processorType === undefined) {\n // Get the last success version from all processor\n // eslint-disable-next-line no-await-in-loop\n indexerVersion = await getIndexerLastSuccessVersion({ aptosConfig });\n } else {\n // Get the last success version from the specific processor\n // eslint-disable-next-line no-await-in-loop\n const processor = await getProcessorStatus({ aptosConfig, processorType });\n indexerVersion = processor.last_success_version;\n }\n\n if (indexerVersion >= minimumLedgerVersion) {\n // break out immediately if we are synced\n break;\n }\n\n // eslint-disable-next-line no-await-in-loop\n await sleep(200);\n }\n}\n\n/**\n * This error is used by `waitForTransaction` when waiting for a\n * transaction to time out or when the transaction response is undefined\n */\nexport class WaitForTransactionError extends Error {\n public readonly lastSubmittedTransaction: TransactionResponse | undefined;\n\n constructor(message: string, lastSubmittedTransaction: TransactionResponse | undefined) {\n super(message);\n this.lastSubmittedTransaction = lastSubmittedTransaction;\n }\n}\n\n/**\n * This error is used by `waitForTransaction` if `checkSuccess` is true.\n * See that function for more information.\n */\nexport class FailedTransactionError extends Error {\n public readonly transaction: TransactionResponse;\n\n constructor(message: string, transaction: TransactionResponse) {\n super(message);\n this.transaction = transaction;\n }\n}\n"],"mappings":"oQA2BA,eAAsBA,EAAgBC,EAGH,CACjC,GAAM,CAAE,YAAAC,EAAa,QAAAC,CAAQ,EAAIF,EACjC,OAAOG,EAA8C,CACnD,YAAAF,EACA,aAAc,kBACd,KAAM,eACN,OAAQ,CAAE,MAAOC,GAAS,OAAQ,MAAOA,GAAS,KAAM,CAC1D,CAAC,CACH,CAEA,eAAsBE,EAAsBJ,EAAoC,CAC9E,GAAM,CAAE,YAAAC,CAAY,EAAID,EAExB,OAAOK,EACL,SAAY,CACV,GAAM,CAAE,KAAAC,CAAK,EAAI,MAAMC,EAAoC,CACzD,YAAAN,EACA,aAAc,wBACd,KAAM,oBACR,CAAC,EACD,OAAOK,CACT,EACA,aAAaL,EAAY,OAAO,GAChC,IAAO,GAAK,CACd,EAAE,CACJ,CAEA,eAAsBO,EAAwBR,EAGb,CAC/B,GAAM,CAAE,YAAAC,EAAa,cAAAQ,CAAc,EAAIT,EACjC,CAAE,KAAAM,CAAK,EAAI,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,GAXIF,IAAkB,OAGpBG,EAAiB,MAAMC,EAA6B,CAAE,YAAAlC,CAAY,CAAC,EAKnEiC,GADkB,MAAME,EAAmB,CAAE,YAAAnC,EAAa,cAAA8B,CAAc,CAAC,GAC9C,qBAGzBG,GAAkBF,EAEpB,MAIF,MAAML,EAAM,GAAG,CACjB,CACF,CAMO,IAAMC,EAAN,cAAsC,KAAM,CAGjD,YAAYS,EAAiBC,EAA2D,CACtF,MAAMD,CAAO,EACb,KAAK,yBAA2BC,CAClC,CACF,EAMaT,EAAN,cAAqC,KAAM,CAGhD,YAAYQ,EAAiBE,EAAkC,CAC7D,MAAMF,CAAO,EACb,KAAK,YAAcE,CACrB,CACF","names":["getTransactions","args","aptosConfig","options","paginateWithCursor","getGasPriceEstimation","memoizeAsync","data","getAptosFullNode","getTransactionByVersion","ledgerVersion","getTransactionByHash","transactionHash","isTransactionPending","e","longWaitForTransaction","waitForTransaction","timeoutSecs","checkSuccess","isPending","timeElapsed","lastTxn","lastError","backoffIntervalMs","backoffMultiplier","handleAPIError","AptosApiError","startTime","sleep","WaitForTransactionError","FailedTransactionError","waitForIndexer","processorType","minimumLedgerVersion","timeoutMilliseconds","indexerVersion","getIndexerLastSuccessVersion","getProcessorStatus","message","lastSubmittedTransaction","transaction"]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as T}from"./chunk-SZ6KR73C.mjs";import{a as S,b as d}from"./chunk-3SXTTG2X.mjs";import{a as x,c as I,d as B,e as D}from"./chunk-ZAXWW7VW.mjs";import{a as H,c as U}from"./chunk-WOLLRMXR.mjs";import{b as K}from"./chunk-AUAL3H36.mjs";import{a as g}from"./chunk-J577ODDM.mjs";import{a as G}from"./chunk-NGTNMV6Q.mjs";import{a as A}from"./chunk-WXLSJF4A.mjs";import{a as m,b as E}from"./chunk-272NA6H5.mjs";import{b as u}from"./chunk-AOCNYMMX.mjs";var C=1e7,_=120,M=30,O=330,ie=120,re=350,ae=300,ne=93,l=class l extends K{constructor(e,t){super();let i=u.fromHexInput(t).toUint8Array();if(i.length!==l.ID_COMMITMENT_LENGTH)throw new Error(`Id Commitment length in bytes should be ${l.ID_COMMITMENT_LENGTH}`);this.iss=e,this.idCommitment=i}authKey(){let e=new E;return e.serializeU32AsUleb128(3),e.serializeFixedBytes(this.bcsToBytes()),G.fromSchemeAndBytes({scheme:2,input:e.toUint8Array()})}toUint8Array(){return this.bcsToBytes()}toString(){return u.fromHexInput(this.toUint8Array()).toString()}verifySignature(e){throw new Error("Not yet implemented")}serialize(e){e.serializeStr(this.iss),e.serializeBytes(this.idCommitment)}static deserialize(e){let t=e.deserializeStr(),i=e.deserializeBytes();return new l(t,i)}static load(e){let t=e.deserializeStr(),i=e.deserializeBytes();return new l(t,i)}static isPublicKey(e){return e instanceof l}static create(e){return v(e),new l(e.iss,v(e))}};l.ID_COMMITMENT_LENGTH=32;var z=l;function v(a){let{uidKey:r,uidVal:e,aud:t,pepper:i}=a,n=[I(u.fromHexInput(i).toUint8Array()),x(t,_),x(e,O),x(r,M)];return B(D(n),z.ID_COMMITMENT_LENGTH)}var P=class a extends g{constructor(e){super();let{jwtHeader:t,ephemeralCertificate:i,expiryDateSecs:n,ephemeralPublicKey:s,ephemeralSignature:o}=e;this.jwtHeader=t,this.ephemeralCertificate=i,this.expiryDateSecs=n,this.ephemeralPublicKey=s,this.ephemeralSignature=o}toUint8Array(){return this.bcsToBytes()}serialize(e){this.ephemeralCertificate.serialize(e),e.serializeStr(this.jwtHeader),e.serializeU64(this.expiryDateSecs),this.ephemeralPublicKey.serialize(e),this.ephemeralSignature.serialize(e)}static deserialize(e){let t=h.deserialize(e),i=e.deserializeStr(),n=e.deserializeU64(),s=S.deserialize(e),o=d.deserialize(e);return new a({jwtHeader:i,expiryDateSecs:Number(n),ephemeralCertificate:t,ephemeralPublicKey:s,ephemeralSignature:o})}static load(e){let t=h.deserialize(e),i=e.deserializeStr(),n=e.deserializeU64(),s=S.deserialize(e),o=d.deserialize(e);return new a({jwtHeader:i,expiryDateSecs:Number(n),ephemeralCertificate:t,ephemeralPublicKey:s,ephemeralSignature:o})}static getSimulationSignature(){return new a({jwtHeader:"{}",ephemeralCertificate:new h(new f({proof:new y(new b({a:new Uint8Array(32),b:new Uint8Array(64),c:new Uint8Array(32)}),0)}),0),expiryDateSecs:0,ephemeralPublicKey:new S(new H(new Uint8Array(32))),ephemeralSignature:new d(new U(new Uint8Array(64)))})}static isSignature(e){return e instanceof a}},h=class a extends g{constructor(e,t){super();this.signature=e,this.variant=t}toUint8Array(){return this.signature.toUint8Array()}serialize(e){e.serializeU32AsUleb128(this.variant),this.signature.serialize(e)}static deserialize(e){let t=e.deserializeUleb128AsU32();switch(t){case 0:return new a(f.deserialize(e),t);default:throw new Error(`Unknown variant index for EphemeralCertificate: ${t}`)}}},c=class a extends m{constructor(e){super();if(this.data=u.fromHexInput(e).toUint8Array(),this.data.length!==32)throw new Error("Input needs to be 32 bytes")}serialize(e){e.serializeFixedBytes(this.data)}static deserialize(e){let t=e.deserializeFixedBytes(32);return new a(t)}},p=class a extends m{constructor(e){super();if(this.data=u.fromHexInput(e).toUint8Array(),this.data.length!==64)throw new Error("Input needs to be 64 bytes")}serialize(e){e.serializeFixedBytes(this.data)}static deserialize(e){let t=e.deserializeFixedBytes(64);return new a(t)}},b=class a extends T{constructor(e){super();let{a:t,b:i,c:n}=e;this.a=new c(t),this.b=new p(i),this.c=new c(n)}serialize(e){this.a.serialize(e),this.b.serialize(e),this.c.serialize(e)}static deserialize(e){let t=c.deserialize(e).bcsToBytes(),i=p.deserialize(e).bcsToBytes(),n=c.deserialize(e).bcsToBytes();return new a({a:t,b:i,c:n})}},y=class a extends m{constructor(e,t){super();this.proof=e,this.variant=t}serialize(e){e.serializeU32AsUleb128(this.variant),this.proof.serialize(e)}static deserialize(e){let t=e.deserializeUleb128AsU32();switch(t){case 0:return new a(b.deserialize(e),t);default:throw new Error(`Unknown variant index for ZkProof: ${t}`)}}},f=class a extends g{constructor(e){super();let{proof:t,expHorizonSecs:i=BigInt(C),trainingWheelsSignature:n,extraField:s,overrideAudVal:o}=e;this.proof=t,this.expHorizonSecs=i,this.trainingWheelsSignature=n,this.extraField=s,this.overrideAudVal=o}toUint8Array(){return this.bcsToBytes()}static fromBytes(e){return a.deserialize(new A(e))}serialize(e){this.proof.serialize(e),e.serializeU64(this.expHorizonSecs),e.serializeOptionStr(this.extraField),e.serializeOptionStr(this.overrideAudVal),e.serializeOption(this.trainingWheelsSignature)}static deserialize(e){let t=y.deserialize(e),i=e.deserializeU64(),n=e.deserializeOptionStr(),s=e.deserializeOptionStr(),o=e.deserializeOption(d);return new a({proof:t,expHorizonSecs:i,trainingWheelsSignature:o,extraField:n,overrideAudVal:s})}static load(e){let t=y.deserialize(e),i=e.deserializeU64(),n=e.deserializeOptionStr(),s=e.deserializeOptionStr(),o=e.deserializeOption(d);return new a({proof:t,expHorizonSecs:i,trainingWheelsSignature:o,extraField:n,overrideAudVal:s})}},V=class a{constructor(r,e){this.verficationKey=r,this.maxExpHorizonSecs=e}static create(r,e){return new a(new w({alphaG1:r.alpha_g1,betaG2:r.beta_g2,deltaG2:r.delta_g2,gammaAbcG1:r.gamma_abc_g1,gammaG2:r.gamma_g2}),e)}},w=class a{constructor(r){let{alphaG1:e,betaG2:t,deltaG2:i,gammaAbcG1:n,gammaG2:s}=r;this.alphaG1=new c(e),this.betaG2=new p(t),this.deltaG2=new p(i),this.gammaAbcG1=[new c(n[0]),new c(n[1])],this.gammaG2=new p(s)}static fromGroth16VerificationKeyResponse(r){return new a({alphaG1:r.alpha_g1,betaG2:r.beta_g2,deltaG2:r.delta_g2,gammaAbcG1:r.gamma_abc_g1,gammaG2:r.gamma_g2})}};export{C as a,_ as b,M as c,O as d,ie as e,re as f,ae as g,ne as h,z as i,P as j,h as k,b as l,y as m,f as n,V as o};
|
|
2
|
-
//# sourceMappingURL=chunk-CIPPNT3W.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/crypto/keyless.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { AccountPublicKey, PublicKey } from \"./publicKey\";\nimport { Signature } from \"./signature\";\nimport { Deserializer, Serializable, Serializer } from \"../../bcs\";\nimport { Hex } from \"../hex\";\nimport { HexInput, EphemeralCertificateVariant, AnyPublicKeyVariant, SigningScheme, ZkpVariant } from \"../../types\";\nimport { EphemeralPublicKey, EphemeralSignature } from \"./ephemeral\";\nimport { bigIntToBytesLE, bytesToBigIntLE, hashStrToField, poseidonHash } from \"./poseidon\";\nimport { AuthenticationKey } from \"../authenticationKey\";\nimport { Proof } from \"./proof\";\nimport { Ed25519PublicKey, Ed25519Signature } from \"./ed25519\";\nimport { Groth16VerificationKeyResponse } from \"../../types/keyless\";\n\nexport const EPK_HORIZON_SECS = 10000000;\nexport const MAX_AUD_VAL_BYTES = 120;\nexport const MAX_UID_KEY_BYTES = 30;\nexport const MAX_UID_VAL_BYTES = 330;\nexport const MAX_ISS_VAL_BYTES = 120;\nexport const MAX_EXTRA_FIELD_BYTES = 350;\nexport const MAX_JWT_HEADER_B64_BYTES = 300;\nexport const MAX_COMMITED_EPK_BYTES = 93;\n\n/**\n * Represents the KeylessPublicKey public key\n *\n * KeylessPublicKey authentication key is represented in the SDK as `AnyPublicKey`.\n */\nexport class KeylessPublicKey extends AccountPublicKey {\n static readonly ID_COMMITMENT_LENGTH: number = 32;\n\n /**\n * The value of the 'iss' claim on the JWT which identifies the OIDC provider.\n */\n readonly iss: string;\n\n /**\n * A value representing a cryptographic commitment to a user identity.\n * \n * It is calculated from the aud, uidKey, uidVal, pepper.\n */\n readonly idCommitment: Uint8Array;\n\n constructor(iss: string, idCommitment: HexInput) {\n super();\n const idcBytes = Hex.fromHexInput(idCommitment).toUint8Array();\n if (idcBytes.length !== KeylessPublicKey.ID_COMMITMENT_LENGTH) {\n throw new Error(`Id Commitment length in bytes should be ${KeylessPublicKey.ID_COMMITMENT_LENGTH}`);\n }\n this.iss = iss;\n this.idCommitment = idcBytes;\n }\n\n /**\n * Get the authentication key for the keyless public key\n *\n * @returns AuthenticationKey\n */\n authKey(): AuthenticationKey {\n const serializer = new Serializer();\n serializer.serializeU32AsUleb128(AnyPublicKeyVariant.Keyless);\n serializer.serializeFixedBytes(this.bcsToBytes());\n return AuthenticationKey.fromSchemeAndBytes({\n scheme: SigningScheme.SingleKey,\n input: serializer.toUint8Array(),\n });\n }\n\n /**\n * Get the public key in bytes (Uint8Array).\n *\n * @returns Uint8Array representation of the public key\n */\n toUint8Array(): Uint8Array {\n return this.bcsToBytes();\n }\n\n /**\n * Get the public key as a hex string with the 0x prefix.\n *\n * @returns string representation of the public key\n */\n toString(): string {\n return Hex.fromHexInput(this.toUint8Array()).toString();\n }\n\n /**\n * Verifies a signed data with a public key\n *\n * @param args.message message\n * @param args.signature The signature\n * @returns true if the signature is valid\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this\n verifySignature(args: { message: HexInput; signature: KeylessSignature }): boolean {\n throw new Error(\"Not yet implemented\");\n }\n\n serialize(serializer: Serializer): void {\n serializer.serializeStr(this.iss);\n serializer.serializeBytes(this.idCommitment);\n }\n\n static deserialize(deserializer: Deserializer): KeylessPublicKey {\n const iss = deserializer.deserializeStr();\n const addressSeed = deserializer.deserializeBytes();\n return new KeylessPublicKey(iss, addressSeed);\n }\n\n static load(deserializer: Deserializer): KeylessPublicKey {\n const iss = deserializer.deserializeStr();\n const addressSeed = deserializer.deserializeBytes();\n return new KeylessPublicKey(iss, addressSeed);\n }\n\n static isPublicKey(publicKey: PublicKey): publicKey is KeylessPublicKey {\n return publicKey instanceof KeylessPublicKey;\n }\n\n /**\n * Creates a KeylessPublicKey from the JWT components plus pepper\n *\n * @param args.iss the iss of the identity\n * @param args.uidKey the key to use to get the uidVal in the JWT token\n * @param args.uidVal the value of the uidKey in the JWT token\n * @param args.aud the client ID of the application\n * @param args.pepper The pepper used to maintain privacy of the account\n * @returns KeylessPublicKey\n */\n static create(args: {\n iss: string;\n uidKey: string;\n uidVal: string;\n aud: string;\n pepper: HexInput;\n }): KeylessPublicKey {\n computeIdCommitment(args);\n return new KeylessPublicKey(args.iss, computeIdCommitment(args));\n }\n}\n\nfunction computeIdCommitment(args: { uidKey: string; uidVal: string; aud: string; pepper: HexInput }): Uint8Array {\n const { uidKey, uidVal, aud, pepper } = args;\n\n const fields = [\n bytesToBigIntLE(Hex.fromHexInput(pepper).toUint8Array()),\n hashStrToField(aud, MAX_AUD_VAL_BYTES),\n hashStrToField(uidVal, MAX_UID_VAL_BYTES),\n hashStrToField(uidKey, MAX_UID_KEY_BYTES),\n ];\n\n return bigIntToBytesLE(poseidonHash(fields), KeylessPublicKey.ID_COMMITMENT_LENGTH);\n}\n\n/**\n * A signature of a message signed via Keyless Accounnt that uses proofs or the jwt token to authenticate.\n */\nexport class KeylessSignature extends Signature {\n /**\n * The inner signature ZeroKnowledgeSigniature or OpenIdSignature\n */\n readonly ephemeralCertificate: EphemeralCertificate;\n\n /**\n * The jwt header in the token used to create the proof/signature. In json string representation.\n */\n readonly jwtHeader: string;\n\n /**\n * The expiry timestamp in seconds of the EphemeralKeyPair used to sign\n */\n readonly expiryDateSecs: number;\n\n /**\n * The ephemeral public key used to verify the signature\n */\n readonly ephemeralPublicKey: EphemeralPublicKey;\n\n /**\n * The signature resulting from signing with the private key of the EphemeralKeyPair\n */\n readonly ephemeralSignature: EphemeralSignature;\n\n constructor(args: {\n jwtHeader: string;\n ephemeralCertificate: EphemeralCertificate;\n expiryDateSecs: number;\n ephemeralPublicKey: EphemeralPublicKey;\n ephemeralSignature: EphemeralSignature;\n }) {\n super();\n const { jwtHeader, ephemeralCertificate, expiryDateSecs, ephemeralPublicKey, ephemeralSignature } = args;\n this.jwtHeader = jwtHeader;\n this.ephemeralCertificate = ephemeralCertificate;\n this.expiryDateSecs = expiryDateSecs;\n this.ephemeralPublicKey = ephemeralPublicKey;\n this.ephemeralSignature = ephemeralSignature;\n }\n\n /**\n * Get the signature in bytes (Uint8Array).\n *\n * @returns Uint8Array representation of the signature\n */\n toUint8Array(): Uint8Array {\n return this.bcsToBytes();\n }\n\n serialize(serializer: Serializer): void {\n this.ephemeralCertificate.serialize(serializer);\n serializer.serializeStr(this.jwtHeader);\n serializer.serializeU64(this.expiryDateSecs);\n this.ephemeralPublicKey.serialize(serializer);\n this.ephemeralSignature.serialize(serializer);\n }\n\n static deserialize(deserializer: Deserializer): KeylessSignature {\n const ephemeralCertificate = EphemeralCertificate.deserialize(deserializer);\n const jwtHeader = deserializer.deserializeStr();\n const expiryDateSecs = deserializer.deserializeU64();\n const ephemeralPublicKey = EphemeralPublicKey.deserialize(deserializer);\n const ephemeralSignature = EphemeralSignature.deserialize(deserializer);\n return new KeylessSignature({\n jwtHeader,\n expiryDateSecs: Number(expiryDateSecs),\n ephemeralCertificate,\n ephemeralPublicKey,\n ephemeralSignature,\n });\n }\n\n static load(deserializer: Deserializer): KeylessSignature {\n const ephemeralCertificate = EphemeralCertificate.deserialize(deserializer);\n const jwtHeader = deserializer.deserializeStr();\n const expiryDateSecs = deserializer.deserializeU64();\n const ephemeralPublicKey = EphemeralPublicKey.deserialize(deserializer);\n const ephemeralSignature = EphemeralSignature.deserialize(deserializer);\n return new KeylessSignature({\n jwtHeader,\n expiryDateSecs: Number(expiryDateSecs),\n ephemeralCertificate,\n ephemeralPublicKey,\n ephemeralSignature,\n });\n }\n\n static getSimulationSignature(): KeylessSignature {\n return new KeylessSignature({\n jwtHeader: \"{}\",\n ephemeralCertificate: new EphemeralCertificate(\n new ZeroKnowledgeSig({\n proof: new ZkProof(\n new Groth16Zkp({ a: new Uint8Array(32), b: new Uint8Array(64), c: new Uint8Array(32) }),\n ZkpVariant.Groth16,\n ),\n }),\n EphemeralCertificateVariant.ZkProof,\n ),\n expiryDateSecs: 0,\n ephemeralPublicKey: new EphemeralPublicKey(new Ed25519PublicKey(new Uint8Array(32))),\n ephemeralSignature: new EphemeralSignature(new Ed25519Signature(new Uint8Array(64))),\n });\n }\n\n static isSignature(signature: Signature): signature is KeylessSignature {\n return signature instanceof KeylessSignature;\n }\n}\n\n/**\n * A container for a signature that is a ZeroKnowledgeSig. Can be expanded to support OpenIdSignature.\n */\nexport class EphemeralCertificate extends Signature {\n public readonly signature: Signature;\n\n /**\n * Index of the underlying enum variant\n */\n private readonly variant: EphemeralCertificateVariant;\n\n constructor(signature: Signature, variant: EphemeralCertificateVariant) {\n super();\n this.signature = signature;\n this.variant = variant;\n }\n\n /**\n * Get the public key in bytes (Uint8Array).\n *\n * @returns Uint8Array representation of the public key\n */\n toUint8Array(): Uint8Array {\n return this.signature.toUint8Array();\n }\n\n serialize(serializer: Serializer): void {\n serializer.serializeU32AsUleb128(this.variant);\n this.signature.serialize(serializer);\n }\n\n static deserialize(deserializer: Deserializer): EphemeralCertificate {\n const variant = deserializer.deserializeUleb128AsU32();\n switch (variant) {\n case EphemeralCertificateVariant.ZkProof:\n return new EphemeralCertificate(ZeroKnowledgeSig.deserialize(deserializer), variant);\n default:\n throw new Error(`Unknown variant index for EphemeralCertificate: ${variant}`);\n }\n }\n}\n\nclass G1Bytes extends Serializable {\n data: Uint8Array;\n\n constructor(data: HexInput) {\n super();\n this.data = Hex.fromHexInput(data).toUint8Array();\n if (this.data.length !== 32) {\n throw new Error(\"Input needs to be 32 bytes\");\n }\n }\n\n serialize(serializer: Serializer): void {\n serializer.serializeFixedBytes(this.data);\n }\n\n static deserialize(deserializer: Deserializer): G1Bytes {\n const bytes = deserializer.deserializeFixedBytes(32);\n return new G1Bytes(bytes);\n }\n}\n\nclass G2Bytes extends Serializable {\n data: Uint8Array;\n\n constructor(data: HexInput) {\n super();\n this.data = Hex.fromHexInput(data).toUint8Array();\n if (this.data.length !== 64) {\n throw new Error(\"Input needs to be 64 bytes\");\n }\n }\n\n serialize(serializer: Serializer): void {\n serializer.serializeFixedBytes(this.data);\n }\n\n static deserialize(deserializer: Deserializer): G2Bytes {\n const bytes = deserializer.deserializeFixedBytes(64);\n return new G2Bytes(bytes);\n }\n}\n\n/**\n * A representation of a Groth16 proof. The points are the compressed serialization of affine reprentation of the proof.\n */\nexport class Groth16Zkp extends Proof {\n /**\n * The bytes of G1 proof point a\n */\n a: G1Bytes;\n\n /**\n * The bytes of G2 proof point b\n */\n b: G2Bytes;\n\n /**\n * The bytes of G1 proof point c\n */\n c: G1Bytes;\n\n constructor(args: { a: HexInput; b: HexInput; c: HexInput }) {\n super();\n const { a, b, c } = args;\n this.a = new G1Bytes(a)\n this.b = new G2Bytes(b)\n this.c = new G1Bytes(c)\n }\n\n serialize(serializer: Serializer): void {\n this.a.serialize(serializer);\n this.b.serialize(serializer);\n this.c.serialize(serializer);\n }\n\n static deserialize(deserializer: Deserializer): Groth16Zkp {\n const a = G1Bytes.deserialize(deserializer).bcsToBytes();\n const b = G2Bytes.deserialize(deserializer).bcsToBytes();\n const c = G1Bytes.deserialize(deserializer).bcsToBytes();\n return new Groth16Zkp({ a, b, c });\n }\n}\n\n/**\n * A container for a different zero knowledge proof types\n */\nexport class ZkProof extends Serializable {\n public readonly proof: Proof;\n\n /**\n * Index of the underlying enum variant\n */\n private readonly variant: ZkpVariant;\n\n constructor(proof: Proof, variant: ZkpVariant) {\n super();\n this.proof = proof;\n this.variant = variant;\n }\n\n serialize(serializer: Serializer): void {\n serializer.serializeU32AsUleb128(this.variant);\n this.proof.serialize(serializer);\n }\n\n static deserialize(deserializer: Deserializer): ZkProof {\n const variant = deserializer.deserializeUleb128AsU32();\n switch (variant) {\n case ZkpVariant.Groth16:\n return new ZkProof(Groth16Zkp.deserialize(deserializer), variant);\n default:\n throw new Error(`Unknown variant index for ZkProof: ${variant}`);\n }\n }\n}\n\n/**\n * The signature representation of a proof\n */\nexport class ZeroKnowledgeSig extends Signature {\n /**\n * The proof\n */\n readonly proof: ZkProof;\n\n /**\n * The max lifespan of the proof\n */\n readonly expHorizonSecs: bigint;\n\n /**\n * A key value pair on the JWT token that can be specified on the signature which would reveal the value on chain.\n * Can be used to assert identity or other attributes.\n */\n readonly extraField?: string;\n\n /**\n * The 'aud' value of the recovery service which is set when recovering an account.\n */\n readonly overrideAudVal?: string;\n\n /**\n * The training wheels signature\n */\n readonly trainingWheelsSignature?: EphemeralSignature;\n\n constructor(args: {\n proof: ZkProof;\n expHorizonSecs?: bigint;\n extraField?: string;\n overrideAudVal?: string;\n trainingWheelsSignature?: EphemeralSignature;\n }) {\n super();\n const {\n proof,\n expHorizonSecs = BigInt(EPK_HORIZON_SECS),\n trainingWheelsSignature,\n extraField,\n overrideAudVal,\n } = args;\n this.proof = proof;\n this.expHorizonSecs = expHorizonSecs;\n this.trainingWheelsSignature = trainingWheelsSignature;\n this.extraField = extraField;\n this.overrideAudVal = overrideAudVal;\n }\n\n /**\n * Get the signature in bytes (Uint8Array).\n *\n * @returns Uint8Array representation of the signature\n */\n toUint8Array(): Uint8Array {\n return this.bcsToBytes();\n }\n\n /**\n * Return a ZeroKnowledgeSig object from its bcs serialization in bytes.\n *\n * @returns ZeroKnowledgeSig\n */\n static fromBytes(bytes: Uint8Array): ZeroKnowledgeSig {\n return ZeroKnowledgeSig.deserialize(new Deserializer(bytes));\n }\n\n serialize(serializer: Serializer): void {\n this.proof.serialize(serializer);\n serializer.serializeU64(this.expHorizonSecs);\n serializer.serializeOptionStr(this.extraField);\n serializer.serializeOptionStr(this.overrideAudVal);\n serializer.serializeOption(this.trainingWheelsSignature);\n }\n\n static deserialize(deserializer: Deserializer): ZeroKnowledgeSig {\n const proof = ZkProof.deserialize(deserializer);\n const expHorizonSecs = deserializer.deserializeU64();\n const extraField = deserializer.deserializeOptionStr();\n const overrideAudVal = deserializer.deserializeOptionStr();\n const trainingWheelsSignature = deserializer.deserializeOption(EphemeralSignature);\n return new ZeroKnowledgeSig({ proof, expHorizonSecs, trainingWheelsSignature, extraField, overrideAudVal });\n }\n\n static load(deserializer: Deserializer): ZeroKnowledgeSig {\n const proof = ZkProof.deserialize(deserializer);\n const expHorizonSecs = deserializer.deserializeU64();\n const extraField = deserializer.deserializeOptionStr();\n const overrideAudVal = deserializer.deserializeOptionStr();\n const trainingWheelsSignature = deserializer.deserializeOption(EphemeralSignature);\n return new ZeroKnowledgeSig({ proof, expHorizonSecs, trainingWheelsSignature, extraField, overrideAudVal });\n }\n}\n\nexport class KeylessConfiguration {\n readonly verficationKey: Groth16VerificationKey;\n\n readonly maxExpHorizonSecs: number;\n\n constructor(verficationKey: Groth16VerificationKey, maxExpHorizonSecs: number) {\n this.verficationKey = verficationKey;\n this.maxExpHorizonSecs = maxExpHorizonSecs;\n }\n\n static create(res: Groth16VerificationKeyResponse, maxExpHorizonSecs: number): KeylessConfiguration {\n return new KeylessConfiguration(new Groth16VerificationKey({\n alphaG1: res.alpha_g1,\n betaG2: res.beta_g2,\n deltaG2: res.delta_g2,\n gammaAbcG1: res.gamma_abc_g1,\n gammaG2: res.gamma_g2\n }), maxExpHorizonSecs)\n }\n\n}\n \n class Groth16VerificationKey {\n readonly alphaG1: G1Bytes;\n\n readonly betaG2: G2Bytes;\n\n readonly deltaG2: G2Bytes;\n\n readonly gammaAbcG1: G1Bytes[];\n\n readonly gammaG2: G2Bytes;\n \n constructor(args: {\n alphaG1: HexInput;\n betaG2: HexInput;\n deltaG2: HexInput;\n gammaAbcG1: [HexInput, HexInput];\n gammaG2: HexInput;\n }) {\n const {\n alphaG1,\n betaG2,\n deltaG2,\n gammaAbcG1,\n gammaG2,\n } = args;\n this.alphaG1 = new G1Bytes(alphaG1)\n this.betaG2 = new G2Bytes(betaG2)\n this.deltaG2 = new G2Bytes(deltaG2)\n this.gammaAbcG1 = [new G1Bytes(gammaAbcG1[0]), new G1Bytes(gammaAbcG1[1])]\n this.gammaG2 =new G2Bytes(gammaG2)\n }\n\n static fromGroth16VerificationKeyResponse(res: Groth16VerificationKeyResponse): Groth16VerificationKey {\n return new Groth16VerificationKey({\n alphaG1: res.alpha_g1,\n betaG2: res.beta_g2,\n deltaG2: res.delta_g2,\n gammaAbcG1: res.gamma_abc_g1,\n gammaG2: res.g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,EACA,QAAAC,CACF,EAAIjE,EACJ,KAAK,QAAU,IAAIkC,EAAQ2B,CAAO,EAClC,KAAK,OAAS,IAAItB,EAAQuB,CAAM,EAChC,KAAK,QAAU,IAAIvB,EAAQwB,CAAO,EAClC,KAAK,WAAa,CAAC,IAAI7B,EAAQ8B,EAAW,CAAC,CAAC,EAAG,IAAI9B,EAAQ8B,EAAW,CAAC,CAAC,CAAC,EACzE,KAAK,QAAS,IAAIzB,EAAQ0B,CAAO,CACnC,CAEA,OAAO,mCAAmCP,EAA6D,CACrG,OAAO,IAAIE,EAAuB,CAChC,QAASF,EAAI,SACb,OAAQA,EAAI,QACZ,QAASA,EAAI,SACb,WAAYA,EAAI,aAChB,QAASA,EAAI,QACf,CAAC,CACH,CACF","names":["EPK_HORIZON_SECS","MAX_AUD_VAL_BYTES","MAX_UID_KEY_BYTES","MAX_UID_VAL_BYTES","MAX_ISS_VAL_BYTES","MAX_EXTRA_FIELD_BYTES","MAX_JWT_HEADER_B64_BYTES","MAX_COMMITED_EPK_BYTES","_KeylessPublicKey","AccountPublicKey","iss","idCommitment","idcBytes","Hex","serializer","Serializer","AuthenticationKey","args","deserializer","addressSeed","publicKey","computeIdCommitment","KeylessPublicKey","uidKey","uidVal","aud","pepper","fields","bytesToBigIntLE","hashStrToField","bigIntToBytesLE","poseidonHash","KeylessSignature","_KeylessSignature","Signature","jwtHeader","ephemeralCertificate","expiryDateSecs","ephemeralPublicKey","ephemeralSignature","EphemeralCertificate","EphemeralPublicKey","EphemeralSignature","ZeroKnowledgeSig","ZkProof","Groth16Zkp","Ed25519PublicKey","Ed25519Signature","signature","_EphemeralCertificate","variant","G1Bytes","_G1Bytes","Serializable","data","bytes","G2Bytes","_G2Bytes","_Groth16Zkp","Proof","a","b","c","_ZkProof","proof","_ZeroKnowledgeSig","expHorizonSecs","trainingWheelsSignature","extraField","overrideAudVal","Deserializer","KeylessConfiguration","_KeylessConfiguration","verficationKey","maxExpHorizonSecs","res","Groth16VerificationKey","_Groth16VerificationKey","alphaG1","betaG2","deltaG2","gammaAbcG1","gammaG2"]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as x}from"./chunk-AH44UPM4.mjs";import{b as u}from"./chunk-M4Q4XDVR.mjs";import{e as K,f as C}from"./chunk-WSVJNBSJ.mjs";import{d as a}from"./chunk-MEOBWD6V.mjs";import{a as l,l as P,m as d,n as h,o as m}from"./chunk-CIPPNT3W.mjs";import{b as y}from"./chunk-3SXTTG2X.mjs";import{b as g}from"./chunk-WHSN42R2.mjs";import{b as i}from"./chunk-AOCNYMMX.mjs";async function L(e){let{aptosConfig:r}=e;return x(async()=>{let o=await _(e),t=await w(e);return m.create(t,Number(o.max_exp_horizon_secs))},`keyless-configuration-${r.network}`,1e3*60*5)()}async function _(e){let{aptosConfig:r,options:o}=e,t="0x1::keyless_account::Configuration",{data:n}=await u({aptosConfig:r,originMethod:"getKeylessConfiguration",path:`accounts/${g.from("0x1").toString()}/resource/${t}`,params:{ledger_version:o?.ledgerVersion}});return n.data}async function w(e){let{aptosConfig:r,options:o}=e,t="0x1::keyless_account::Groth16VerificationKey",{data:n}=await u({aptosConfig:r,originMethod:"getGroth16VerificationKey",path:`accounts/${g.from("0x1").toString()}/resource/${t}`,params:{ledger_version:o?.ledgerVersion}});return n.data}async function b(e){let{aptosConfig:r,jwt:o,ephemeralKeyPair:t,uidKey:n,derivationPath:s}=e,c={jwt_b64:o,epk:t.getPublicKey().bcsToHex().toStringWithoutPrefix(),exp_date_secs:t.expiryDateSecs,epk_blinder:i.fromHexInput(t.blinder).toStringWithoutPrefix(),uid_key:n||"sub",derivation_path:s},{data:p}=await K({aptosConfig:r,path:"fetch",body:c,originMethod:"getPepper",overrides:{WITH_CREDENTIALS:!1}});return i.fromHexInput(p.pepper).toUint8Array()}async function R(e){let{aptosConfig:r,jwt:o,ephemeralKeyPair:t,pepper:n,uidKey:s}=e,c={jwt_b64:o,epk:t.getPublicKey().bcsToHex().toStringWithoutPrefix(),epk_blinder:i.fromHexInput(t.blinder).toStringWithoutPrefix(),exp_date_secs:t.expiryDateSecs,exp_horizon_secs:l,pepper:i.fromHexInput(n).toStringWithoutPrefix(),uid_key:s||"sub"},{data:p}=await C({aptosConfig:r,path:"prove",body:c,originMethod:"getProof",overrides:{WITH_CREDENTIALS:!1}}),f=p.proof,A=new P({a:f.a,b:f.b,c:f.c});return new h({proof:new d(A,0),trainingWheelsSignature:y.fromHex(p.training_wheels_signature)})}async function M(e){let{proofFetchCallback:r}=e,{pepper:o}=e;if(o===void 0?o=await b(e):o=i.fromHexInput(o).toUint8Array(),o.length!==a.PEPPER_LENGTH)throw new Error(`Pepper needs to be ${a.PEPPER_LENGTH} bytes`);let t=R({...e,pepper:o}),n=r?t:await t;return a.fromJWTAndProof({...e,proof:n,pepper:o,proofFetchCallback:r})}export{L as a,b,R as c,M as d};
|
|
2
|
-
//# sourceMappingURL=chunk-FUQDDIKQ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internal/keyless.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * This file contains the underlying implementations for exposed API surface in\n * the {@link api/keyless}. By moving the methods out into a separate file,\n * other namespaces and processes can access these methods without depending on the entire\n * keyless namespace and without having a dependency cycle error.\n */\nimport { AptosConfig } from \"../api/aptosConfig\";\nimport { getAptosFullNode, postAptosPepperService, postAptosProvingService } from \"../client\";\nimport {\n AccountAddress,\n EPK_HORIZON_SECS,\n EphemeralSignature,\n Groth16Zkp,\n Hex,\n KeylessConfiguration,\n ZeroKnowledgeSig,\n ZkProof,\n} from \"../core\";\nimport { HexInput, LedgerVersionArg, MoveResource, ZkpVariant } from \"../types\";\nimport { EphemeralKeyPair, KeylessAccount, ProofFetchCallback } from \"../account\";\nimport {\n Groth16VerificationKeyResponse,\n KeylessConfigurationResponse,\n PepperFetchRequest,\n PepperFetchResponse,\n ProverRequest,\n ProverResponse,\n} from \"../types/keyless\";\nimport { memoizeAsync } from \"../utils/memoize\";\n\nexport async function getKeylessConfig(args: {\n aptosConfig: AptosConfig;\n options?: LedgerVersionArg;\n}): Promise<KeylessConfiguration> {\n const { aptosConfig } = args;\n return memoizeAsync(\n async () => {\n const config = await getKeylessConfiguration(args);\n const vk = await getGroth16VerificationKey(args);\n return KeylessConfiguration.create(vk, Number(config.max_exp_horizon_secs));\n },\n `keyless-configuration-${aptosConfig.network}`,\n 1000 * 60 * 5, // 5 minutes\n )();\n}\n\nasync function getKeylessConfiguration(args: {\n aptosConfig: AptosConfig;\n options?: LedgerVersionArg;\n}): Promise<KeylessConfigurationResponse> {\n const { aptosConfig, options } = args;\n const resourceType = \"0x1::keyless_account::Configuration\";\n const { data } = await getAptosFullNode<{}, MoveResource<KeylessConfigurationResponse>>({\n aptosConfig,\n originMethod: \"getKeylessConfiguration\",\n path: `accounts/${AccountAddress.from(\"0x1\").toString()}/resource/${resourceType}`,\n params: { ledger_version: options?.ledgerVersion },\n });\n\n return data.data;\n}\n\nasync function getGroth16VerificationKey(args: {\n aptosConfig: AptosConfig;\n options?: LedgerVersionArg;\n}): Promise<Groth16VerificationKeyResponse> {\n const { aptosConfig, options } = args;\n const resourceType = \"0x1::keyless_account::Groth16VerificationKey\";\n const { data } = await getAptosFullNode<{}, MoveResource<Groth16VerificationKeyResponse>>({\n aptosConfig,\n originMethod: \"getGroth16VerificationKey\",\n path: `accounts/${AccountAddress.from(\"0x1\").toString()}/resource/${resourceType}`,\n params: { ledger_version: options?.ledgerVersion },\n });\n\n return data.data;\n}\n\nexport async function getPepper(args: {\n aptosConfig: AptosConfig;\n jwt: string;\n ephemeralKeyPair: EphemeralKeyPair;\n uidKey?: string;\n derivationPath?: string;\n}): Promise<Uint8Array> {\n const { aptosConfig, jwt, ephemeralKeyPair, uidKey, derivationPath } = args;\n\n const body = {\n jwt_b64: jwt,\n epk: ephemeralKeyPair.getPublicKey().bcsToHex().toStringWithoutPrefix(),\n exp_date_secs: ephemeralKeyPair.expiryDateSecs,\n epk_blinder: Hex.fromHexInput(ephemeralKeyPair.blinder).toStringWithoutPrefix(),\n uid_key: uidKey || \"sub\",\n derivation_path: derivationPath,\n };\n const { data } = await postAptosPepperService<PepperFetchRequest, PepperFetchResponse>({\n aptosConfig,\n path: \"fetch\",\n body,\n originMethod: \"getPepper\",\n overrides: { WITH_CREDENTIALS: false },\n });\n return Hex.fromHexInput(data.pepper).toUint8Array();\n}\n\nexport async function getProof(args: {\n aptosConfig: AptosConfig;\n jwt: string;\n ephemeralKeyPair: EphemeralKeyPair;\n pepper: HexInput;\n uidKey?: string;\n}): Promise<ZeroKnowledgeSig> {\n const { aptosConfig, jwt, ephemeralKeyPair, pepper, uidKey } = args;\n const json = {\n jwt_b64: jwt,\n epk: ephemeralKeyPair.getPublicKey().bcsToHex().toStringWithoutPrefix(),\n epk_blinder: Hex.fromHexInput(ephemeralKeyPair.blinder).toStringWithoutPrefix(),\n exp_date_secs: ephemeralKeyPair.expiryDateSecs,\n exp_horizon_secs: EPK_HORIZON_SECS,\n pepper: Hex.fromHexInput(pepper).toStringWithoutPrefix(),\n uid_key: uidKey || \"sub\",\n };\n\n const { data } = await postAptosProvingService<ProverRequest, ProverResponse>({\n aptosConfig,\n path: \"prove\",\n body: json,\n originMethod: \"getProof\",\n overrides: { WITH_CREDENTIALS: false },\n });\n\n const proofPoints = data.proof;\n const groth16Zkp = new Groth16Zkp({\n a: proofPoints.a,\n b: proofPoints.b,\n c: proofPoints.c,\n });\n\n const signedProof = new ZeroKnowledgeSig({\n proof: new ZkProof(groth16Zkp, ZkpVariant.Groth16),\n trainingWheelsSignature: EphemeralSignature.fromHex(data.training_wheels_signature),\n });\n return signedProof;\n}\n\nexport async function deriveKeylessAccount(args: {\n aptosConfig: AptosConfig;\n jwt: string;\n ephemeralKeyPair: EphemeralKeyPair;\n uidKey?: string;\n pepper?: HexInput;\n proofFetchCallback?: ProofFetchCallback;\n}): Promise<KeylessAccount> {\n const { proofFetchCallback } = args;\n let { pepper } = args;\n if (pepper === undefined) {\n pepper = await getPepper(args);\n } else {\n pepper = Hex.fromHexInput(pepper).toUint8Array();\n }\n\n if (pepper.length !== KeylessAccount.PEPPER_LENGTH) {\n throw new Error(`Pepper needs to be ${KeylessAccount.PEPPER_LENGTH} bytes`);\n }\n\n const proofPromise = getProof({ ...args, pepper });\n const proof = proofFetchCallback ? proofPromise : await proofPromise;\n\n const keylessAccount = KeylessAccount.fromJWTAndProof({ ...args, proof, pepper, proofFetchCallback });\n\n return keylessAccount;\n}\n"],"mappings":"2WAiCA,eAAsBA,EAAiBC,EAGL,CAChC,GAAM,CAAE,YAAAC,CAAY,EAAID,EACxB,OAAOE,EACL,SAAY,CACV,IAAMC,EAAS,MAAMC,EAAwBJ,CAAI,EAC3CK,EAAK,MAAMC,EAA0BN,CAAI,EAC/C,OAAOO,EAAqB,OAAOF,EAAI,OAAOF,EAAO,oBAAoB,CAAC,CAC5E,EACA,yBAAyBF,EAAY,OAAO,GAC5C,IAAO,GAAK,CACd,EAAE,CACJ,CAEA,eAAeG,EAAwBJ,EAGG,CACxC,GAAM,CAAE,YAAAC,EAAa,QAAAO,CAAQ,EAAIR,EAC3BS,EAAe,sCACf,CAAE,KAAAC,CAAK,EAAI,MAAMC,EAAiE,CACtF,YAAAV,EACA,aAAc,0BACd,KAAM,YAAYW,EAAe,KAAK,KAAK,EAAE,SAAS,CAAC,aAAaH,CAAY,GAChF,OAAQ,CAAE,eAAgBD,GAAS,aAAc,CACnD,CAAC,EAED,OAAOE,EAAK,IACd,CAEA,eAAeJ,EAA0BN,EAGG,CAC1C,GAAM,CAAE,YAAAC,EAAa,QAAAO,CAAQ,EAAIR,EAC3BS,EAAe,+CACf,CAAE,KAAAC,CAAK,EAAI,MAAMC,EAAmE,CACxF,YAAAV,EACA,aAAc,4BACd,KAAM,YAAYW,EAAe,KAAK,KAAK,EAAE,SAAS,CAAC,aAAaH,CAAY,GAChF,OAAQ,CAAE,eAAgBD,GAAS,aAAc,CACnD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BAAyBI,EAAmB,QAAQrB,EAAK,yBAAyB,CACpF,CAAC,CAEH,CAEA,eAAsBsB,EAAqBhC,EAOf,CAC1B,GAAM,CAAE,mBAAAiC,CAAmB,EAAIjC,EAC3B,CAAE,OAAAsB,CAAO,EAAItB,EAOjB,GANIsB,IAAW,OACbA,EAAS,MAAMT,EAAUb,CAAI,EAE7BsB,EAASH,EAAI,aAAaG,CAAM,EAAE,aAAa,EAG7CA,EAAO,SAAWY,EAAe,cACnC,MAAM,IAAI,MAAM,sBAAsBA,EAAe,aAAa,QAAQ,EAG5E,IAAMC,EAAed,EAAS,CAAE,GAAGrB,EAAM,OAAAsB,CAAO,CAAC,EAC3Cc,EAAQH,EAAqBE,EAAe,MAAMA,EAIxD,OAFuBD,EAAe,gBAAgB,CAAE,GAAGlC,EAAM,MAAAoC,EAAO,OAAAd,EAAQ,mBAAAW,CAAmB,CAAC,CAGtG","names":["getKeylessConfig","args","aptosConfig","memoizeAsync","config","getKeylessConfiguration","vk","getGroth16VerificationKey","KeylessConfiguration","options","resourceType","data","getAptosFullNode","AccountAddress","getPepper","jwt","ephemeralKeyPair","uidKey","derivationPath","body","Hex","postAptosPepperService","getProof","pepper","json","EPK_HORIZON_SECS","postAptosProvingService","proofPoints","groth16Zkp","Groth16Zkp","ZeroKnowledgeSig","ZkProof","EphemeralSignature","deriveKeylessAccount","proofFetchCallback","KeylessAccount","proofPromise","proof"]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as r,b as o,d as i}from"./chunk-FUQDDIKQ.mjs";var t=class{constructor(e){this.config=e}async getKeylessConfig(e){return r({aptosConfig:this.config,options:e})}async getPepper(e){return o({aptosConfig:this.config,...e})}async deriveKeylessAccount(e){return i({aptosConfig:this.config,...e})}};export{t as a};
|
|
2
|
-
//# sourceMappingURL=chunk-FWTJQHJR.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/keyless.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { EphemeralKeyPair, KeylessAccount, ProofFetchCallback } from \"../account\";\nimport { KeylessConfiguration } from \"../core\";\nimport { deriveKeylessAccount, getKeylessConfig, getPepper } from \"../internal/keyless\";\nimport { HexInput, LedgerVersionArg } from \"../types\";\nimport { AptosConfig } from \"./aptosConfig\";\n\n/**\n * A class to query all `Keyless` related queries on Aptos.\n */\nexport class Keyless {\n constructor(readonly config: AptosConfig) {}\n\n /**\n * Gets the parameters of how Keyless Accounts are configured on chain.\n *\n * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version\n * @returns KeylessConfiguration\n */\n async getKeylessConfig(\n options?: LedgerVersionArg\n ): Promise<KeylessConfiguration> {\n return getKeylessConfig({ aptosConfig: this.config, options });\n }\n\n /**\n * Fetches the pepper from the Aptos pepper service API.\n *\n * @param args.jwt JWT token\n * @param args.ephemeralKeyPair the EphemeralKeyPair used to generate the nonce in the JWT token\n * @returns The pepper which is a Uint8Array of length 31.\n */\n async getPepper(args: { jwt: string; ephemeralKeyPair: EphemeralKeyPair }): Promise<Uint8Array> {\n return getPepper({ aptosConfig: this.config, ...args });\n }\n\n /**\n * Fetches the pepper from the Aptos pepper service API.\n *\n * @param args.jwt JWT token\n * @param args.ephemeralKeyPair the EphemeralKeyPair used to generate the nonce in the JWT token\n * @param args.uidKey a key in the JWT token to use to set the uidVal in the IdCommitment\n * @param args.pepper the pepper\n * @param args.proofFetchCallback a callback function that if set, the fetch of the proof will be done asyncronously. Once\n * if finishes the callback function will be called.\n * @returns A KeylessAccount that can be used to sign transactions\n */\n async deriveKeylessAccount(args: {\n jwt: string;\n ephemeralKeyPair: EphemeralKeyPair;\n uidKey?: string;\n pepper?: HexInput;\n proofFetchCallback?: ProofFetchCallback;\n }): Promise<KeylessAccount> {\n return deriveKeylessAccount({ aptosConfig: this.config, ...args });\n }\n}\n"],"mappings":"uDAYO,IAAMA,EAAN,KAAc,CACnB,YAAqBC,EAAqB,CAArB,YAAAA,CAAsB,CAQ3C,MAAM,iBACJC,EAC+B,CAC/B,OAAOC,EAAiB,CAAE,YAAa,KAAK,OAAQ,QAAAD,CAAQ,CAAC,CAC/D,CASA,MAAM,UAAUE,EAAgF,CAC9F,OAAOC,EAAU,CAAE,YAAa,KAAK,OAAQ,GAAGD,CAAK,CAAC,CACxD,CAaA,MAAM,qBAAqBA,EAMC,CAC1B,OAAOE,EAAqB,CAAE,YAAa,KAAK,OAAQ,GAAGF,CAAK,CAAC,CACnE,CACF","names":["Keyless","config","options","getKeylessConfig","args","getPepper","deriveKeylessAccount"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/helpers.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { decode } from \"js-base64\";\n\n/**\n * Sleep the current thread for the given amount of time\n * @param timeMs time in milliseconds to sleep\n */\nexport async function sleep(timeMs: number): Promise<null> {\n return new Promise((resolve) => {\n setTimeout(resolve, timeMs);\n });\n}\n\n\nexport function currentTimeInSeconds(): number {\n return Math.floor(new Date().getTime() / 1000);\n}\n\nexport function floorToWholeHour(timestampInSeconds: number): number {\n const date = new Date(timestampInSeconds * 1000);\n // Reset minutes and seconds to zero\n date.setMinutes(0);\n date.setSeconds(0);\n date.setMilliseconds(0);\n return Math.floor(date.getTime() / 1000);\n}\n\nexport function base64UrlDecode(base64Url: string): string {\n // Replace base64url-specific characters\n const base64 = base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n // Pad the string with '=' characters if needed\n const paddedBase64 = base64 + \"==\".substring(0, (3 - (base64.length % 3)) % 3);\n const decodedString = decode(paddedBase64);\n return decodedString;\n}\n"],"mappings":"AAGA,OAAS,UAAAA,MAAc,YAMvB,eAAsBC,EAAMC,EAA+B,CACzD,OAAO,IAAI,QAASC,GAAY,CAC9B,WAAWA,EAASD,CAAM,CAC5B,CAAC,CACH,CAGO,SAASE,GAA+B,CAC7C,OAAO,KAAK,MAAM,IAAI,KAAK,EAAE,QAAQ,EAAI,GAAI,CAC/C,CAEO,SAASC,EAAiBC,EAAoC,CACnE,IAAMC,EAAO,IAAI,KAAKD,EAAqB,GAAI,EAE/C,OAAAC,EAAK,WAAW,CAAC,EACjBA,EAAK,WAAW,CAAC,EACjBA,EAAK,gBAAgB,CAAC,EACf,KAAK,MAAMA,EAAK,QAAQ,EAAI,GAAI,CACzC,CAEO,SAASC,EAAgBC,EAA2B,CAEzD,IAAMC,EAASD,EAAU,QAAQ,KAAM,GAAG,EAAE,QAAQ,KAAM,GAAG,EAEvDE,EAAeD,EAAS,KAAK,UAAU,GAAI,EAAKA,EAAO,OAAS,GAAM,CAAC,EAE7E,OADsBV,EAAOW,CAAY,CAE3C","names":["decode","sleep","timeMs","resolve","currentTimeInSeconds","floorToWholeHour","timestampInSeconds","date","base64UrlDecode","base64Url","base64","paddedBase64"]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as O}from"./chunk-5VLCYHNJ.mjs";import{a as T}from"./chunk-D76FE35G.mjs";import{d as I}from"./chunk-JCDZ2WXX.mjs";import{a as N}from"./chunk-OZ3GSAFK.mjs";import{d as P}from"./chunk-HGRU3HWY.mjs";import{a as m,b as y}from"./chunk-QYEJOEWB.mjs";import{i as F,j as b,k as x,n as f}from"./chunk-CIPPNT3W.mjs";import{b as S}from"./chunk-WHSN42R2.mjs";import{a as K}from"./chunk-WXLSJF4A.mjs";import{a as E}from"./chunk-272NA6H5.mjs";import{b as A}from"./chunk-AOCNYMMX.mjs";import{jwtDecode as D}from"jwt-decode";import k from"eventemitter3";var te={"https://accounts.google.com":"https://www.googleapis.com/oauth2/v3/certs"},z=(t=>(t[t.JWK_EXPIRED=0]="JWK_EXPIRED",t[t.EPK_EXPIRED=1]="EPK_EXPIRED",t[t.PROOF_NOT_FOUND=2]="PROOF_NOT_FOUND",t[t.UNKNOWN_INVALID_SIGNATURE=3]="UNKNOWN_INVALID_SIGNATURE",t[t.UNKNOWN=4]="UNKNOWN",t))(z||{}),c=class p extends Error{constructor(e){super();this.type=e}static async fromAptosApiError(e,r){return e.data.message.includes("INVALID_SIGNATURE")?r.isExpired()?new p(1):new p(3):new p(4)}},s=class s extends E{constructor(e){super();let{address:r,ephemeralKeyPair:i,uidKey:t,uidVal:n,aud:a,pepper:h,proofOrFetcher:o,proofFetchCallback:l,jwt:d}=e;if(this.ephemeralKeyPair=i,this.publicKey=F.create(e),this.accountAddress=r?S.from(r):this.publicKey.authKey().derivedAddress(),this.uidKey=t,this.uidVal=n,this.aud=a,this.jwt=d,this.emitter=new k,this.proofOrPromise=o,o instanceof f)this.proof=o;else{if(l===void 0)throw new Error("Must provide callback for async proof fetch");this.emitter.on("proofFetchFinish",async v=>{await l(v),this.emitter.removeAllListeners()}),this.init(o)}this.signingScheme=2;let u=A.fromHexInput(h).toUint8Array();if(u.length!==s.PEPPER_LENGTH)throw new Error(`Pepper length in bytes should be ${s.PEPPER_LENGTH}`);this.pepper=u,this.isJwtValid=!0}async init(e){try{this.proof=await e,this.emitter.emit("proofFetchFinish",{status:"Success"})}catch(r){r instanceof Error?this.emitter.emit("proofFetchFinish",{status:"Failed",error:r.toString()}):this.emitter.emit("proofFetchFinish",{status:"Failed",error:"Unknown"})}}serialize(e){if(e.serializeStr(this.jwt),e.serializeStr(this.uidKey),e.serializeFixedBytes(this.pepper),this.ephemeralKeyPair.serialize(e),this.proof===void 0)throw new Error("Connot serialize - proof undefined");this.proof.serialize(e)}static deserialize(e){let r=e.deserializeStr(),i=e.deserializeStr(),t=e.deserializeFixedBytes(31),n=T.deserialize(e),a=f.deserialize(e);return s.fromJWTAndProof({proof:a,pepper:t,uidKey:i,jwt:r,ephemeralKeyPair:n})}isExpired(){return this.ephemeralKeyPair.isExpired()}signWithAuthenticator(e){let r=new y(this.sign(e)),i=new m(this.publicKey);return new P(i,r)}signTransactionWithAuthenticator(e){let r=new y(this.signTransaction(e)),i=new m(this.publicKey);return new P(i,r)}async waitForProofFetch(){this.proofOrPromise instanceof Promise&&await this.proofOrPromise}sign(e){let{expiryDateSecs:r}=this.ephemeralKeyPair;if(this.isExpired())throw new c(1);if(this.proof===void 0)throw new c(2);if(!this.isJwtValid)throw new c(0);let i=this.ephemeralKeyPair.getPublicKey(),t=this.ephemeralKeyPair.sign(e);return new b({jwtHeader:I(this.jwt.split(".")[0]),ephemeralCertificate:new x(this.proof,0),expiryDateSecs:r,ephemeralPublicKey:i,ephemeralSignature:t})}signTransaction(e){if(this.proof===void 0)throw new Error("Proof not found");let r=N(e),t=new g(r,this.proof.proof).hash();return this.sign(t)}verifySignature(e){throw new Error("Not implemented")}static fromBytes(e){return s.deserialize(new K(e))}static fromJWTAndProof(e){let{proof:r,jwt:i,ephemeralKeyPair:t,pepper:n,proofFetchCallback:a}=e,h=e.uidKey??"sub",o=D(i),l=o.iss;if(typeof o.aud!="string")throw new Error("aud was not found or an array of values");let d=o.aud,u=o[h];return new s({proofOrFetcher:r,ephemeralKeyPair:t,iss:l,uidKey:h,uidVal:u,aud:d,pepper:n,jwt:i,proofFetchCallback:a})}};s.PEPPER_LENGTH=31;var R=s,g=class extends O{constructor(e,r){super();this.transaction=e,this.proof=r,this.domainSeparator="APTOS::TransactionAndProof"}serialize(e){e.serializeFixedBytes(this.transaction.bcsToBytes()),e.serializeOption(this.proof)}};export{te as a,z as b,c,R as d,g as e};
|
|
2
|
-
//# sourceMappingURL=chunk-MEOBWD6V.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/account/KeylessAccount.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { JwtPayload, jwtDecode } from \"jwt-decode\";\nimport EventEmitter from \"eventemitter3\";\nimport { EphemeralCertificateVariant, HexInput, SigningScheme } from \"../types\";\nimport { AccountAddress } from \"../core/accountAddress\";\nimport {\n AnyPublicKey,\n AnySignature,\n KeylessPublicKey,\n KeylessSignature,\n EphemeralCertificate,\n Signature,\n ZeroKnowledgeSig,\n ZkProof,\n} from \"../core/crypto\";\n\nimport { Account } from \"./Account\";\nimport { EphemeralKeyPair } from \"./EphemeralKeyPair\";\nimport { Hex } from \"../core/hex\";\nimport { AccountAuthenticatorSingleKey } from \"../transactions/authenticator/account\";\nimport { Deserializer, Serializable, Serializer } from \"../bcs\";\nimport {\n deriveTransactionType,\n} from \"../transactions/transactionBuilder/signingMessage\";\nimport { AnyRawTransaction, AnyRawTransactionInstance } from \"../transactions/types\";\nimport { AptosApiError } from \"../client/types\";\nimport { AptsoDomainSeparator, CryptoHashable } from \"../core/crypto/cryptoHasher\";\nimport { base64UrlDecode } from \"../utils/helpers\";\n\nexport const IssuerToJwkEndpoint: Record<string, string> = {\n \"https://accounts.google.com\": \"https://www.googleapis.com/oauth2/v3/certs\",\n};\n\nexport enum KeylessErrorType {\n JWK_EXPIRED,\n EPK_EXPIRED,\n PROOF_NOT_FOUND,\n UNKNOWN_INVALID_SIGNATURE,\n UNKNOWN,\n}\nexport class KeylessError extends Error {\n readonly type: KeylessErrorType;\n\n constructor(type: KeylessErrorType) {\n super();\n this.type = type;\n }\n\n static async fromAptosApiError(error: AptosApiError, signer: KeylessAccount): Promise<KeylessError> {\n if (!error.data.message.includes(\"INVALID_SIGNATURE\")) {\n return new KeylessError(KeylessErrorType.UNKNOWN);\n }\n if (signer.isExpired()) {\n return new KeylessError(KeylessErrorType.EPK_EXPIRED);\n }\n return new KeylessError(KeylessErrorType.UNKNOWN_INVALID_SIGNATURE);\n }\n}\n\n/**\n * Account implementation for the Keyless authentication scheme.\n *\n * Used to represent a Keyless based account and sign transactions with it.\n * \n * Use KeylessAccount.fromJWTAndProof to instantiate a KeylessAccount with a JWT, proof and EphemeralKeyPair.\n * \n * When the proof expires or the JWT becomes invalid, the KeylessAccount must be instantiated again with a new JWT,\n * EphemeralKeyPair, and corresponding proof.\n */\nexport class KeylessAccount extends Serializable implements Account {\n static readonly PEPPER_LENGTH: number = 31;\n\n /**\n * The KeylessPublicKey associated with the account\n */\n readonly publicKey: KeylessPublicKey;\n\n /**\n * The EphemeralKeyPair used to generate sign. \n */\n readonly ephemeralKeyPair: EphemeralKeyPair;\n\n /**\n * The claim on the JWT to identify a user. This is typically 'sub' or 'email'.\n */\n readonly uidKey: string;\n\n /**\n * The value of the uidKey claim on the JWT. This intended to be a stable user identifier.\n */\n readonly uidVal: string;\n\n /**\n * The value of the 'aud' claim on the JWT, also known as client ID. This is the identifier for the dApp's\n * OIDC registration with the identity provider.\n */\n readonly aud: string;\n\n /**\n * A value contains 31 bytes of entropy that preserves privacy of the account. Typically fetched from a pepper provider.\n */\n readonly pepper: Uint8Array;\n\n /**\n * Account address associated with the account\n */\n readonly accountAddress: AccountAddress;\n\n /**\n * The zero knowledge signature (if ready) which contains the proof used to validate the EphemeralKeyPair.\n */\n proof: ZeroKnowledgeSig | undefined;\n\n /**\n * The proof of the EphemeralKeyPair or a promise that provides the proof. This is used to allow for awaiting on\n * fetching the proof.\n */\n readonly proofOrPromise: ZeroKnowledgeSig | Promise<ZeroKnowledgeSig>;\n\n /**\n * Signing scheme used to sign transactions\n */\n readonly signingScheme: SigningScheme;\n\n /**\n * The JWT token used to derive the account\n */\n private jwt: string;\n\n /**\n * A value that caches the JWT's validity. A JWT becomes invalid when it's corresponding JWK is rotated from the \n * identity provider's JWK keyset.\n */\n private isJwtValid: boolean;\n\n /**\n * An event emitter used to assist in handling asycronous proof fetching.\n */\n private readonly emitter: EventEmitter<ProofFetchEvents>;\n\n constructor(args: {\n address?: AccountAddress;\n ephemeralKeyPair: EphemeralKeyPair;\n iss: string;\n uidKey: string;\n uidVal: string;\n aud: string;\n pepper: HexInput;\n proofOrFetcher: ZeroKnowledgeSig | Promise<ZeroKnowledgeSig>;\n proofFetchCallback?: ProofFetchCallback;\n jwt: string;\n }) {\n super();\n const { address, ephemeralKeyPair, uidKey, uidVal, aud, pepper, proofOrFetcher, proofFetchCallback, jwt } = args;\n this.ephemeralKeyPair = ephemeralKeyPair;\n this.publicKey = KeylessPublicKey.create(args);\n this.accountAddress = address ? AccountAddress.from(address) : this.publicKey.authKey().derivedAddress();\n this.uidKey = uidKey;\n this.uidVal = uidVal;\n this.aud = aud;\n this.jwt = jwt;\n this.emitter = new EventEmitter<ProofFetchEvents>();\n this.proofOrPromise = proofOrFetcher;\n if (proofOrFetcher instanceof ZeroKnowledgeSig) {\n this.proof = proofOrFetcher;\n } else {\n if (proofFetchCallback === undefined) {\n throw new Error(\"Must provide callback for async proof fetch\");\n }\n this.emitter.on(\"proofFetchFinish\", async (status) => {\n await proofFetchCallback(status);\n this.emitter.removeAllListeners();\n });\n this.init(proofOrFetcher);\n }\n this.signingScheme = SigningScheme.SingleKey;\n const pepperBytes = Hex.fromHexInput(pepper).toUint8Array();\n if (pepperBytes.length !== KeylessAccount.PEPPER_LENGTH) {\n throw new Error(`Pepper length in bytes should be ${KeylessAccount.PEPPER_LENGTH}`);\n }\n this.pepper = pepperBytes;\n this.isJwtValid = true;\n }\n\n /**\n * This initializes the asyncronous proof fetch\n * @return\n */\n async init(promise: Promise<ZeroKnowledgeSig>) {\n try {\n this.proof = await promise;\n this.emitter.emit(\"proofFetchFinish\", { status: \"Success\" });\n } catch (error) {\n if (error instanceof Error) {\n this.emitter.emit(\"proofFetchFinish\", { status: \"Failed\", error: error.toString() });\n } else {\n this.emitter.emit(\"proofFetchFinish\", { status: \"Failed\", error: \"Unknown\" });\n }\n }\n }\n\n serialize(serializer: Serializer): void {\n serializer.serializeStr(this.jwt);\n serializer.serializeStr(this.uidKey);\n serializer.serializeFixedBytes(this.pepper);\n this.ephemeralKeyPair.serialize(serializer);\n if (this.proof === undefined) {\n throw new Error(\"Connot serialize - proof undefined\");\n }\n this.proof.serialize(serializer);\n }\n\n static deserialize(deserializer: Deserializer): KeylessAccount {\n const jwt = deserializer.deserializeStr();\n const uidKey = deserializer.deserializeStr();\n const pepper = deserializer.deserializeFixedBytes(31);\n const ephemeralKeyPair = EphemeralKeyPair.deserialize(deserializer);\n const proof = ZeroKnowledgeSig.deserialize(deserializer);\n return KeylessAccount.fromJWTAndProof({\n proof,\n pepper,\n uidKey,\n jwt,\n ephemeralKeyPair,\n });\n }\n\n /**\n * Checks if the proof is expired. If so the account must be rederived with a new EphemeralKeyPair\n * and JWT token.\n * @return boolean\n */\n isExpired(): boolean {\n return this.ephemeralKeyPair.isExpired();\n }\n\n /**\n * Sign a message using Keyless.\n * @param message the message to sign, as binary input\n * @return the AccountAuthenticator containing the signature, together with the account's public key\n */\n signWithAuthenticator(message: HexInput): AccountAuthenticatorSingleKey {\n const signature = new AnySignature(this.sign(message));\n const publicKey = new AnyPublicKey(this.publicKey);\n return new AccountAuthenticatorSingleKey(publicKey, signature);\n }\n\n /**\n * Sign a transaction using Keyless.\n * @param transaction the raw transaction\n * @return the AccountAuthenticator containing the signature of the transaction, together with the account's public key\n */\n signTransactionWithAuthenticator(transaction: AnyRawTransaction): AccountAuthenticatorSingleKey {\n const signature = new AnySignature(this.signTransaction(transaction));\n const publicKey = new AnyPublicKey(this.publicKey);\n return new AccountAuthenticatorSingleKey(publicKey, signature);\n }\n\n /**\n * Waits for asyncronous proof fetching to finish.\n * @return\n */\n async waitForProofFetch() {\n if (this.proofOrPromise instanceof Promise) {\n await this.proofOrPromise;\n }\n }\n\n /**\n * Sign the given message using Keyless.\n * @param message in HexInput format\n * @returns Signature\n */\n sign(data: HexInput): KeylessSignature {\n const { expiryDateSecs } = this.ephemeralKeyPair;\n if (this.isExpired()) {\n throw new KeylessError(KeylessErrorType.EPK_EXPIRED);\n }\n if (this.proof === undefined) {\n throw new KeylessError(KeylessErrorType.PROOF_NOT_FOUND);\n }\n if (!this.isJwtValid) {\n throw new KeylessError(KeylessErrorType.JWK_EXPIRED);\n }\n const ephemeralPublicKey = this.ephemeralKeyPair.getPublicKey();\n const ephemeralSignature = this.ephemeralKeyPair.sign(data);\n\n return new KeylessSignature({\n jwtHeader: base64UrlDecode(this.jwt.split(\".\")[0]),\n ephemeralCertificate: new EphemeralCertificate(this.proof, EphemeralCertificateVariant.ZkProof),\n expiryDateSecs,\n ephemeralPublicKey,\n ephemeralSignature,\n });\n }\n\n /**\n * Sign the given transaction with Keyless.\n * Signs the transaction and proof to guard against proof malleability.\n * @param transaction the transaction to be signed\n * @returns KeylessSignature\n */\n signTransaction(transaction: AnyRawTransaction): KeylessSignature {\n if (this.proof === undefined) {\n throw new Error(\"Proof not found\");\n }\n const raw = deriveTransactionType(transaction);\n const txnAndProof = new TransactionAndProof(raw, this.proof.proof);\n const signMess = txnAndProof.hash();\n return this.sign(signMess);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this\n verifySignature(args: { message: HexInput; signature: Signature }): boolean {\n throw new Error(\"Not implemented\");\n }\n\n static fromBytes(bytes: Uint8Array): KeylessAccount {\n return KeylessAccount.deserialize(new Deserializer(bytes));\n }\n\n static fromJWTAndProof(args: {\n proof: ZeroKnowledgeSig | Promise<ZeroKnowledgeSig>;\n jwt: string;\n ephemeralKeyPair: EphemeralKeyPair;\n pepper: HexInput;\n uidKey?: string;\n proofFetchCallback?: ProofFetchCallback;\n }): KeylessAccount {\n const { proof, jwt, ephemeralKeyPair, pepper, proofFetchCallback } = args;\n const uidKey = args.uidKey ?? \"sub\";\n\n const jwtPayload = jwtDecode<JwtPayload & { [key: string]: string }>(jwt);\n const iss = jwtPayload.iss!;\n if (typeof jwtPayload.aud !== \"string\") {\n throw new Error(\"aud was not found or an array of values\");\n }\n const aud = jwtPayload.aud!;\n const uidVal = jwtPayload[uidKey];\n return new KeylessAccount({\n proofOrFetcher: proof,\n ephemeralKeyPair,\n iss,\n uidKey,\n uidVal,\n aud,\n pepper,\n jwt,\n proofFetchCallback,\n });\n }\n}\n\n/**\n * A container class to hold a transaction and a proof. It implements CryptoHashable which is used to create\n * the signing message for Keyless transactions. We sign over the proof to ensure non-malleability.\n */\nexport class TransactionAndProof extends CryptoHashable {\n /**\n * The transaction to sign.\n */\n transaction: AnyRawTransactionInstance;\n\n /**\n * The zero knowledge proof used in signing the transaction.\n */\n proof?: ZkProof;\n\n /**\n * The domain separator prefix used when hashing.\n */\n domainSeparator: AptsoDomainSeparator;\n\n constructor(transaction: AnyRawTransactionInstance, proof?: ZkProof) {\n super();\n this.transaction = transaction;\n this.proof = proof;\n this.domainSeparator = \"APTOS::TransactionAndProof\"\n }\n\n serialize(serializer: Serializer): void {\n serializer.serializeFixedBytes(this.transaction.bcsToBytes());\n serializer.serializeOption(this.proof);\n }\n}\n\nexport type ProofFetchSuccess = {\n status: \"Success\";\n};\n\nexport type ProofFetchFailure = {\n status: \"Failed\";\n error: string;\n};\n\nexport type ProofFetchStatus = ProofFetchSuccess | ProofFetchFailure;\n\nexport type ProofFetchCallback = (status: ProofFetchStatus) => Promise<void>;\n\nexport interface ProofFetchEvents {\n proofFetchFinish: (status: ProofFetchStatus) => void;\n}\n"],"mappings":"+dAGA,OAAqB,aAAAA,MAAiB,aACtC,OAAOC,MAAkB,gBA2BlB,IAAMC,GAA8C,CACzD,8BAA+B,4CACjC,EAEYC,OACVA,IAAA,6BACAA,IAAA,6BACAA,IAAA,qCACAA,IAAA,yDACAA,IAAA,qBALUA,OAAA,IAOCC,EAAN,MAAMC,UAAqB,KAAM,CAGtC,YAAYC,EAAwB,CAClC,MAAM,EACN,KAAK,KAAOA,CACd,CAEA,aAAa,kBAAkBC,EAAsBC,EAA+C,CAClG,OAAKD,EAAM,KAAK,QAAQ,SAAS,mBAAmB,EAGhDC,EAAO,UAAU,EACZ,IAAIH,EAAa,CAA4B,EAE/C,IAAIA,EAAa,CAA0C,EALzD,IAAIA,EAAa,CAAwB,CAMpD,CACF,EAYaI,EAAN,MAAMA,UAAuBC,CAAgC,CAuElE,YAAYC,EAWT,CACD,MAAM,EACN,GAAM,CAAE,QAAAC,EAAS,iBAAAC,EAAkB,OAAAC,EAAQ,OAAAC,EAAQ,IAAAC,EAAK,OAAAC,EAAQ,eAAAC,EAAgB,mBAAAC,EAAoB,IAAAC,CAAI,EAA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W,gBAAgB,KAAK,KAAK,CACvC,CACF","names":["jwtDecode","EventEmitter","IssuerToJwkEndpoint","KeylessErrorType","KeylessError","_KeylessError","type","error","signer","_KeylessAccount","Serializable","args","address","ephemeralKeyPair","uidKey","uidVal","aud","pepper","proofOrFetcher","proofFetchCallback","jwt","KeylessPublicKey","AccountAddress","EventEmitter","ZeroKnowledgeSig","status","pepperBytes","Hex","promise","serializer","deserializer","EphemeralKeyPair","proof","message","signature","AnySignature","publicKey","AnyPublicKey","AccountAuthenticatorSingleKey","transaction","data","expiryDateSecs","ephemeralPublicKey","ephemeralSignature","KeylessSignature","base64UrlDecode","EphemeralCertificate","raw","deriveTransactionType","signMess","TransactionAndProof","bytes","Deserializer","jwtPayload","jwtDecode","iss","KeylessAccount","CryptoHashable"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bcs/deserializer.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable no-bitwise */\nimport { MAX_U32_NUMBER } from \"./consts\";\nimport { Uint8, Uint16, Uint32, Uint64, Uint128, Uint256 } from \"../types\";\n\n/**\n * This interface exists to define Deserializable<T> inputs for functions that\n * deserialize a byte buffer into a type T.\n * It is not intended to be implemented or extended, because Typescript has no support\n * for static methods in interfaces.\n */\nexport interface Deserializable<T> {\n deserialize(deserializer: Deserializer): T;\n}\n\nexport class Deserializer {\n private buffer: ArrayBuffer;\n\n private offset: number;\n\n constructor(data: Uint8Array) {\n // copies data to prevent outside mutation of buffer.\n this.buffer = new ArrayBuffer(data.length);\n new Uint8Array(this.buffer).set(data, 0);\n this.offset = 0;\n }\n\n private read(length: number): ArrayBuffer {\n if (this.offset + length > this.buffer.byteLength) {\n throw new Error(\"Reached to the end of buffer\");\n }\n\n const bytes = this.buffer.slice(this.offset, this.offset + length);\n this.offset += length;\n return bytes;\n }\n\n /**\n * Deserializes a string. UTF8 string is supported. Reads the string's bytes length \"l\" first,\n * and then reads \"l\" bytes of content. Decodes the byte array into a string.\n *\n * BCS layout for \"string\": string_length | string_content\n * where string_length is a u32 integer encoded as a uleb128 integer, equal to the number of bytes in string_content.\n *\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([8, 49, 50, 51, 52, 97, 98, 99, 100]));\n * assert(deserializer.deserializeStr() === \"1234abcd\");\n * ```\n */\n deserializeStr(): string {\n const value = this.deserializeBytes();\n const textDecoder = new TextDecoder();\n return textDecoder.decode(value);\n }\n\n /**\n * Deserializes a an optional string.\n *\n * BCS layout for Optional<String>: 0 if none, else 1 | string_length | string_content\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x00]));\n * assert(deserializer.deserializeOptionStr() === undefined);\n * const deserializer = new Deserializer(new Uint8Array([1, 8, 49, 50, 51, 52, 97, 98, 99, 100]));\n * assert(deserializer.deserializeOptionStr() === \"1234abcd\");\n * ```\n */\n deserializeOptionStr(): string | undefined {\n const exists = this.deserializeUleb128AsU32();\n if (exists === 1) {\n return this.deserializeStr();\n }\n return undefined;\n }\n\n /**\n * Deserializes a an optional deserializable class.\n *\n * BCS layout for Optional<T>: 0 if none, else 1 | bcs representation of class\n * \n * @example \n * const deserializer = new Deserializer(new Uint8Array([1, 2, 3]));\n * const value = deserializer.deserializeOption(MyClass); // where MyClass has a `deserialize` function\n * // value is now an instance of MyClass\n * \n * const deserializer = new Deserializer(new Uint8Array([0]));\n * const value = deserializer.deserializeOption(MyClass); // where MyClass has a `deserialize` function\n * // value is undefined\n * \n * @param cls The BCS-deserializable class to deserialize the buffered bytes into.\n *\n * @returns the deserialized value of class type T\n */\n deserializeOption<T>(cls: Deserializable<T>): T | undefined {\n const exists = this.deserializeUleb128AsU32();\n if (exists === 1) {\n return this.deserialize(cls);\n }\n return undefined;\n }\n\n /**\n * Deserializes an array of bytes.\n *\n * BCS layout for \"bytes\": bytes_length | bytes\n * where bytes_length is a u32 integer encoded as a uleb128 integer, equal to the length of the bytes array.\n */\n deserializeBytes(): Uint8Array {\n const len = this.deserializeUleb128AsU32();\n return new Uint8Array(this.read(len));\n }\n\n /**\n * Deserializes an array of bytes. The number of bytes to read is already known.\n *\n */\n deserializeFixedBytes(len: number): Uint8Array {\n return new Uint8Array(this.read(len));\n }\n\n /**\n * Deserializes a boolean value.\n *\n * BCS layout for \"boolean\": One byte. \"0x01\" for true and \"0x00\" for false.\n */\n deserializeBool(): boolean {\n const bool = new Uint8Array(this.read(1))[0];\n if (bool !== 1 && bool !== 0) {\n throw new Error(\"Invalid boolean value\");\n }\n return bool === 1;\n }\n\n /**\n * Deserializes a uint8 number.\n *\n * BCS layout for \"uint8\": One byte. Binary format in little-endian representation.\n */\n deserializeU8(): Uint8 {\n return new DataView(this.read(1)).getUint8(0);\n }\n\n /**\n * Deserializes a uint16 number.\n *\n * BCS layout for \"uint16\": Two bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x34, 0x12]));\n * assert(deserializer.deserializeU16() === 4660);\n * ```\n */\n deserializeU16(): Uint16 {\n return new DataView(this.read(2)).getUint16(0, true);\n }\n\n /**\n * Deserializes a uint32 number.\n *\n * BCS layout for \"uint32\": Four bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x78, 0x56, 0x34, 0x12]));\n * assert(deserializer.deserializeU32() === 305419896);\n * ```\n */\n deserializeU32(): Uint32 {\n return new DataView(this.read(4)).getUint32(0, true);\n }\n\n /**\n * Deserializes a uint64 number.\n *\n * BCS layout for \"uint64\": Eight bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));\n * assert(deserializer.deserializeU64() === 1311768467750121216);\n * ```\n */\n deserializeU64(): Uint64 {\n const low = this.deserializeU32();\n const high = this.deserializeU32();\n\n // combine the two 32-bit values and return (little endian)\n return BigInt((BigInt(high) << BigInt(32)) | BigInt(low));\n }\n\n /**\n * Deserializes a uint128 number.\n *\n * BCS layout for \"uint128\": Sixteen bytes. Binary format in little-endian representation.\n */\n deserializeU128(): Uint128 {\n const low = this.deserializeU64();\n const high = this.deserializeU64();\n\n // combine the two 64-bit values and return (little endian)\n return BigInt((high << BigInt(64)) | low);\n }\n\n /**\n * Deserializes a uint256 number.\n *\n * BCS layout for \"uint256\": Thirty-two bytes. Binary format in little-endian representation.\n */\n deserializeU256(): Uint256 {\n const low = this.deserializeU128();\n const high = this.deserializeU128();\n\n // combine the two 128-bit values and return (little endian)\n return BigInt((high << BigInt(128)) | low);\n }\n\n /**\n * Deserializes a uleb128 encoded uint32 number.\n *\n * BCS use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n */\n deserializeUleb128AsU32(): Uint32 {\n let value: bigint = BigInt(0);\n let shift = 0;\n\n while (value < MAX_U32_NUMBER) {\n const byte = this.deserializeU8();\n value |= BigInt(byte & 0x7f) << BigInt(shift);\n\n if ((byte & 0x80) === 0) {\n break;\n }\n shift += 7;\n }\n\n if (value > MAX_U32_NUMBER) {\n throw new Error(\"Overflow while parsing uleb128-encoded uint32 value\");\n }\n\n return Number(value);\n }\n\n /**\n * Helper function that primarily exists to support alternative syntax for deserialization.\n * That is, if we have a `const deserializer: new Deserializer(...)`, instead of having to use\n * `MyClass.deserialize(deserializer)`, we can call `deserializer.deserialize(MyClass)`.\n *\n * @example const deserializer = new Deserializer(new Uint8Array([1, 2, 3]));\n * const value = deserializer.deserialize(MyClass); // where MyClass has a `deserialize` function\n * // value is now an instance of MyClass\n * // equivalent to `const value = MyClass.deserialize(deserializer)`\n * @param cls The BCS-deserializable class to deserialize the buffered bytes into.\n *\n * @returns the deserialized value of class type T\n */\n deserialize<T>(cls: Deserializable<T>): T {\n // NOTE: `deserialize` in `cls.deserialize(this)` here is a static method defined in `cls`,\n // It is separate from the `deserialize` instance method defined here in Deserializer.\n return cls.deserialize(this);\n }\n\n /**\n * Deserializes an array of BCS Deserializable values given an existing Deserializer\n * instance with a loaded byte buffer.\n *\n * @param cls The BCS-deserializable class to deserialize the buffered bytes into.\n * @example\n * // serialize a vector of addresses\n * const addresses = new Array<AccountAddress>(\n * AccountAddress.from(\"0x1\"),\n * AccountAddress.from(\"0x2\"),\n * AccountAddress.from(\"0xa\"),\n * AccountAddress.from(\"0xb\"),\n * );\n * const serializer = new Serializer();\n * serializer.serializeVector(addresses);\n * const serializedBytes = serializer.toUint8Array();\n *\n * // deserialize the bytes into an array of addresses\n * const deserializer = new Deserializer(serializedBytes);\n * const deserializedAddresses = deserializer.deserializeVector(AccountAddress);\n * // deserializedAddresses is now an array of AccountAddress instances\n * @returns an array of deserialized values of type T\n */\n deserializeVector<T>(cls: Deserializable<T>): Array<T> {\n const length = this.deserializeUleb128AsU32();\n const vector = new Array<T>();\n for (let i = 0; i < length; i += 1) {\n vector.push(this.deserialize(cls));\n }\n return vector;\n }\n}\n"],"mappings":"yCAiBO,IAAMA,EAAN,KAAmB,CAKxB,YAAYC,EAAkB,CAE5B,KAAK,OAAS,IAAI,YAAYA,EAAK,MAAM,EACzC,IAAI,WAAW,KAAK,MAAM,EAAE,IAAIA,EAAM,CAAC,EACvC,KAAK,OAAS,CAChB,CAEQ,KAAKC,EAA6B,CACxC,GAAI,KAAK,OAASA,EAAS,KAAK,OAAO,WACrC,MAAM,IAAI,MAAM,8BAA8B,EAGhD,IAAMC,EAAQ,KAAK,OAAO,MAAM,KAAK,OAAQ,KAAK,OAASD,CAAM,EACjE,YAAK,QAAUA,EACRC,CACT,CAeA,gBAAyB,CACvB,IAAMC,EAAQ,KAAK,iBAAiB,EAEpC,OADoB,IAAI,YAAY,EACjB,OAAOA,CAAK,CACjC,CAcA,sBAA2C,CAEzC,GADe,KAAK,wBAAwB,IAC7B,EACb,OAAO,KAAK,eAAe,CAG/B,CAoBA,kBAAqBC,EAAuC,CAE1D,GADe,KAAK,wBAAwB,IAC7B,EACb,OAAO,KAAK,YAAYA,CAAG,CAG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AOF,CAAK,EAEvC,EAAAE,EAAO,KACV,MAEFF,GAAS,CACX,CAEA,GAAIN,EAAQO,EACV,MAAM,IAAI,MAAM,qDAAqD,EAGvE,OAAO,OAAOP,CAAK,CACrB,CAeA,YAAeC,EAA2B,CAGxC,OAAOA,EAAI,YAAY,IAAI,CAC7B,CAyBA,kBAAqBA,EAAkC,CACrD,IAAMH,EAAS,KAAK,wBAAwB,EACtCW,EAAS,IAAI,MACnB,QAASC,EAAI,EAAGA,EAAIZ,EAAQY,GAAK,EAC/BD,EAAO,KAAK,KAAK,YAAYR,CAAG,CAAC,EAEnC,OAAOQ,CACT,CACF","names":["Deserializer","data","length","bytes","value","cls","len","bool","low","high","shift","MAX_U32_NUMBER","byte","vector","i"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/crypto/poseidon.ts"],"sourcesContent":["/* eslint-disable no-bitwise */\nimport {\n poseidon1,\n poseidon2,\n poseidon3,\n poseidon4,\n poseidon5,\n poseidon6,\n poseidon7,\n poseidon8,\n poseidon9,\n poseidon10,\n poseidon11,\n poseidon12,\n poseidon13,\n poseidon14,\n poseidon15,\n poseidon16,\n} from \"poseidon-lite\";\n\nconst numInputsToPoseidonFunc = [\n poseidon1,\n poseidon2,\n poseidon3,\n poseidon4,\n poseidon5,\n poseidon6,\n poseidon7,\n poseidon8,\n poseidon9,\n poseidon10,\n poseidon11,\n poseidon12,\n poseidon13,\n poseidon14,\n poseidon15,\n poseidon16,\n];\n\nconst BYTES_PACKED_PER_SCALAR = 31;\nconst MAX_NUM_INPUT_SCALARS = 16;\nconst MAX_NUM_INPUT_BYTES = (MAX_NUM_INPUT_SCALARS - 1) * BYTES_PACKED_PER_SCALAR;\n\n/**\n * Hashes a string to a field element via poseidon\n * \n * @returns bigint result of the hash\n */\nexport function hashStrToField(str: string, maxSizeBytes: number): bigint {\n const textEncoder = new TextEncoder();\n const strBytes = textEncoder.encode(str);\n return hashBytesWithLen(strBytes, maxSizeBytes);\n}\n\nfunction hashBytesWithLen(bytes: Uint8Array, maxSizeBytes: number): bigint {\n if (bytes.length > maxSizeBytes) {\n throw new Error(`Inputted bytes of length ${bytes} is longer than ${maxSizeBytes}`);\n }\n const packed = padAndPackBytesWithLen(bytes, maxSizeBytes);\n return poseidonHash(packed);\n}\n\nfunction padAndPackBytesNoLen(bytes: Uint8Array, maxSizeBytes: number): bigint[] {\n if (bytes.length > maxSizeBytes) {\n throw new Error(`Input bytes of length ${bytes} is longer than ${maxSizeBytes}`);\n }\n const paddedStrBytes = padUint8ArrayWithZeros(bytes, maxSizeBytes);\n return packBytes(paddedStrBytes);\n}\n\nexport function padAndPackBytesWithLen(bytes: Uint8Array, maxSizeBytes: number): bigint[] {\n if (bytes.length > maxSizeBytes) {\n throw new Error(`Input bytes of length ${bytes} is longer than ${maxSizeBytes}`);\n }\n return padAndPackBytesNoLen(bytes, maxSizeBytes).concat([BigInt(bytes.length)]);\n}\n\nfunction packBytes(bytes: Uint8Array): bigint[] {\n if (bytes.length > MAX_NUM_INPUT_BYTES) {\n throw new Error(`Can't pack more than ${MAX_NUM_INPUT_BYTES}. Was given ${bytes.length} bytes`);\n }\n return chunkUint8Array(bytes, BYTES_PACKED_PER_SCALAR).map((chunk) => bytesToBigIntLE(chunk));\n}\n\nfunction chunkUint8Array(array: Uint8Array, chunkSize: number): Uint8Array[] {\n const result: Uint8Array[] = [];\n for (let i = 0; i < array.length; i += chunkSize) {\n result.push(array.subarray(i, i + chunkSize));\n }\n return result;\n}\n\nexport function bytesToBigIntLE(bytes: Uint8Array): bigint {\n let result = BigInt(0);\n for (let i = bytes.length - 1; i >= 0; i -= 1) {\n result = (result << BigInt(8)) | BigInt(bytes[i]);\n }\n return result;\n}\n\nexport function bigIntToBytesLE(value: bigint, length: number): Uint8Array {\n const bytes = new Uint8Array(length);\n for (let i = 0; i < length; i += 1) {\n bytes[i] = Number(value & BigInt(0xff));\n // eslint-disable-next-line no-param-reassign\n value >>= BigInt(8);\n }\n return bytes;\n}\n\nfunction padUint8ArrayWithZeros(inputArray: Uint8Array, paddedSize: number): Uint8Array {\n if (paddedSize < inputArray.length) {\n throw new Error(\"Padded size must be greater than or equal to the input array size.\");\n }\n\n // Create a new Uint8Array with the padded size\n const paddedArray = new Uint8Array(paddedSize);\n\n // Copy the content of the input array to the new array\n paddedArray.set(inputArray);\n\n // Fill the remaining space with zeros\n for (let i = inputArray.length; i < paddedSize; i += 1) {\n paddedArray[i] = 0;\n }\n\n return paddedArray;\n}\n\n/**\n * Hashes up to 16 scalar elements via the poseidon hashing algorithm.\n * \n * Each element must be scalar fields of the BN254 elliptic curve group.\n *\n * @returns bigint result of the hash\n */\nexport function poseidonHash(inputs: (number | bigint | string)[]): bigint {\n if (inputs.length > numInputsToPoseidonFunc.length) {\n throw new Error(`Unable to hash input of length ${inputs.length}. Max input length is ${numInputsToPoseidonFunc.length}`);\n }\n return numInputsToPoseidonFunc[inputs.length - 1](inputs);\n}\n"],"mappings":"AACA,OACE,aAAAA,EACA,aAAAC,EACA,aAAAC,EACA,aAAAC,EACA,aAAAC,EACA,aAAAC,EACA,aAAAC,EACA,aAAAC,EACA,aAAAC,EACA,cAAAC,EACA,cAAAC,EACA,cAAAC,EACA,cAAAC,EACA,cAAAC,EACA,cAAAC,EACA,cAAAC,MACK,gBAEP,IAAMC,EAA0B,CAC9BhB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,CACF,EAEME,EAA0B,GAC1BC,EAAwB,GACxBC,GAAuBD,EAAwB,GAAKD,EAOnD,SAASG,EAAeC,EAAaC,EAA8B,CAExE,IAAMC,EADc,IAAI,YAAY,EACP,OAAOF,CAAG,EACvC,OAAOG,EAAiBD,EAAUD,CAAY,CAChD,CAEA,SAASE,EAAiBC,EAAmBH,EAA8B,CACzE,GAAIG,EAAM,OAASH,EACjB,MAAM,IAAI,MAAM,4BAA4BG,CAAK,mBAAmBH,CAAY,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C/Bd,EAAMc,CAAC,EAAI,OAAOE,EAAQ,OAAO,GAAI,CAAC,EAEtCA,IAAU,OAAO,CAAC,EAEpB,OAAOhB,CACT,CAEA,SAASM,EAAuBY,EAAwBC,EAAgC,CACtF,GAAIA,EAAaD,EAAW,OAC1B,MAAM,IAAI,MAAM,oEAAoE,EAItF,IAAME,EAAc,IAAI,WAAWD,CAAU,EAG7CC,EAAY,IAAIF,CAAU,EAG1B,QAASJ,EAAII,EAAW,OAAQJ,EAAIK,EAAYL,GAAK,EACnDM,EAAYN,CAAC,EAAI,EAGnB,OAAOM,CACT,CASO,SAASjB,EAAakB,EAA8C,CACzE,GAAIA,EAAO,OAAS9B,EAAwB,OAC1C,MAAM,IAAI,MAAM,kCAAkC8B,EAAO,MAAM,0BAA0B9B,EAAwB,MAAM,EAAE,EAE3H,OAAOA,EAAwB8B,EAAO,OAAS,CAAC,EAAEA,CAAM,CAC1D","names":["poseidon1","poseidon2","poseidon3","poseidon4","poseidon5","poseidon6","poseidon7","poseidon8","poseidon9","poseidon10","poseidon11","poseidon12","poseidon13","poseidon14","poseidon15","poseidon16","numInputsToPoseidonFunc","BYTES_PACKED_PER_SCALAR","MAX_NUM_INPUT_SCALARS","MAX_NUM_INPUT_BYTES","hashStrToField","str","maxSizeBytes","strBytes","hashBytesWithLen","bytes","packed","padAndPackBytesWithLen","poseidonHash","padAndPackBytesNoLen","paddedStrBytes","padUint8ArrayWithZeros","packBytes","chunkUint8Array","chunk","bytesToBigIntLE","array","chunkSize","result","i","bigIntToBytesLE","value","length","inputArray","paddedSize","paddedArray","inputs"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|