@aptos-labs/ts-sdk 4.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/{account-CmEgDBH6.d.ts → account-BW99GTa5.d.ts} +35 -4
- package/dist/common/chunk-A2XB7TVI.js +4 -0
- package/dist/common/chunk-A2XB7TVI.js.map +1 -0
- package/dist/common/cli/index.d.ts +1 -1
- package/dist/common/cli/index.js +1 -1
- package/dist/common/cli/index.js.map +1 -1
- package/dist/common/index.d.ts +381 -47
- package/dist/common/index.js +34 -36
- package/dist/common/index.js.map +1 -1
- package/dist/esm/{Ed25519Account-ndmdpFe9.d.mts → Ed25519Account-CPwej6wB.d.mts} +1 -1
- package/dist/esm/account/AbstractKeylessAccount.d.mts +3 -3
- package/dist/esm/account/AbstractKeylessAccount.mjs +1 -1
- package/dist/esm/account/AbstractedAccount.d.mts +3 -2
- package/dist/esm/account/AbstractedAccount.mjs +1 -1
- package/dist/esm/account/Account.d.mts +2 -2
- package/dist/esm/account/Account.mjs +1 -1
- package/dist/esm/account/AccountUtils.d.mts +3 -3
- package/dist/esm/account/AccountUtils.mjs +1 -1
- package/dist/esm/account/DerivableAbstractedAccount.d.mts +2 -2
- package/dist/esm/account/DerivableAbstractedAccount.mjs +1 -1
- package/dist/esm/account/Ed25519Account.d.mts +2 -2
- package/dist/esm/account/Ed25519Account.mjs +1 -1
- package/dist/esm/account/EphemeralKeyPair.d.mts +1 -1
- package/dist/esm/account/EphemeralKeyPair.mjs +1 -1
- package/dist/esm/account/FederatedKeylessAccount.d.mts +3 -3
- package/dist/esm/account/FederatedKeylessAccount.mjs +1 -1
- package/dist/esm/account/KeylessAccount.d.mts +3 -3
- package/dist/esm/account/KeylessAccount.mjs +1 -1
- package/dist/esm/account/MultiEd25519Account.d.mts +2 -2
- package/dist/esm/account/MultiEd25519Account.mjs +1 -1
- package/dist/esm/account/MultiKeyAccount.d.mts +3 -3
- package/dist/esm/account/MultiKeyAccount.mjs +1 -1
- package/dist/esm/account/SingleKeyAccount.d.mts +2 -2
- package/dist/esm/account/SingleKeyAccount.mjs +1 -1
- package/dist/esm/account/index.d.mts +3 -3
- package/dist/esm/account/index.mjs +1 -1
- package/dist/esm/account/utils.d.mts +1 -1
- package/dist/esm/account/utils.mjs +1 -1
- package/dist/esm/{account--Q9z_xMN.d.mts → account-BortO8g2.d.mts} +34 -4
- package/dist/esm/api/account/abstraction.d.mts +1 -1
- package/dist/esm/api/account/abstraction.mjs +1 -1
- package/dist/esm/api/account.d.mts +31 -13
- package/dist/esm/api/account.mjs +1 -1
- package/dist/esm/api/ans.d.mts +2 -2
- package/dist/esm/api/ans.mjs +1 -1
- package/dist/esm/api/aptos.d.mts +4 -3
- package/dist/esm/api/aptos.mjs +1 -1
- package/dist/esm/api/aptosConfig.d.mts +1 -1
- package/dist/esm/api/aptosConfig.mjs +1 -1
- package/dist/esm/api/coin.d.mts +1 -1
- package/dist/esm/api/coin.mjs +1 -1
- package/dist/esm/api/digitalAsset.d.mts +2 -2
- package/dist/esm/api/digitalAsset.mjs +1 -1
- package/dist/esm/api/faucet.d.mts +1 -1
- package/dist/esm/api/faucet.mjs +1 -1
- package/dist/esm/api/fungibleAsset.d.mts +2 -2
- package/dist/esm/api/fungibleAsset.mjs +1 -1
- package/dist/esm/api/general.d.mts +1 -1
- package/dist/esm/api/general.mjs +1 -1
- package/dist/esm/api/index.d.mts +4 -3
- package/dist/esm/api/index.mjs +1 -1
- package/dist/esm/api/keyless.d.mts +3 -3
- package/dist/esm/api/keyless.mjs +1 -1
- package/dist/esm/api/object.d.mts +1 -1
- package/dist/esm/api/object.mjs +1 -1
- package/dist/esm/api/staking.d.mts +1 -1
- package/dist/esm/api/staking.mjs +1 -1
- package/dist/esm/api/table.d.mts +1 -1
- package/dist/esm/api/table.mjs +1 -1
- package/dist/esm/api/transaction.d.mts +56 -36
- package/dist/esm/api/transaction.mjs +1 -1
- package/dist/esm/api/transactionSubmission/build.d.mts +1 -1
- package/dist/esm/api/transactionSubmission/build.mjs +1 -1
- package/dist/esm/api/transactionSubmission/helpers.d.mts +1 -1
- package/dist/esm/api/transactionSubmission/management.d.mts +2 -2
- package/dist/esm/api/transactionSubmission/management.mjs +1 -1
- package/dist/esm/api/transactionSubmission/sign.d.mts +2 -2
- package/dist/esm/api/transactionSubmission/sign.mjs +1 -1
- package/dist/esm/api/transactionSubmission/sign.mjs.map +1 -1
- package/dist/esm/api/transactionSubmission/simulate.d.mts +1 -1
- package/dist/esm/api/transactionSubmission/simulate.mjs +1 -1
- package/dist/esm/api/transactionSubmission/submit.d.mts +1 -1
- package/dist/esm/api/transactionSubmission/submit.mjs +1 -1
- package/dist/esm/api/utils.d.mts +1 -1
- package/dist/esm/api/utils.mjs +1 -1
- package/dist/esm/bcs/consts.d.mts +1 -1
- package/dist/esm/bcs/deserializer.d.mts +1 -1
- package/dist/esm/bcs/index.d.mts +1 -1
- package/dist/esm/bcs/index.mjs +1 -1
- package/dist/esm/bcs/serializable/entryFunctionBytes.d.mts +1 -1
- package/dist/esm/bcs/serializable/fixedBytes.d.mts +1 -1
- package/dist/esm/bcs/serializable/movePrimitives.d.mts +1 -1
- package/dist/esm/bcs/serializable/movePrimitives.mjs +1 -1
- package/dist/esm/bcs/serializable/moveStructs.d.mts +1 -1
- package/dist/esm/bcs/serializable/moveStructs.mjs +1 -1
- package/dist/esm/bcs/serializer.d.mts +1 -1
- package/dist/esm/chunk-2PASUPUO.mjs +2 -0
- package/dist/esm/chunk-2PASUPUO.mjs.map +1 -0
- package/dist/esm/{chunk-6JYQ5P36.mjs → chunk-4AI7KQQ7.mjs} +2 -2
- package/dist/esm/{chunk-V6C6NWFU.mjs → chunk-6OWBKU7N.mjs} +2 -2
- package/dist/esm/{chunk-BPWSOC2Y.mjs → chunk-7EER7GWV.mjs} +2 -2
- package/dist/esm/{chunk-PLI53ZU6.mjs → chunk-AMXZQPUQ.mjs} +2 -2
- package/dist/esm/chunk-CIJA7ONS.mjs +2 -0
- package/dist/esm/{chunk-6SLY7UV2.mjs.map → chunk-CIJA7ONS.mjs.map} +1 -1
- package/dist/esm/chunk-I7XT6L7S.mjs +2 -0
- package/dist/esm/chunk-I7XT6L7S.mjs.map +1 -0
- package/dist/esm/{chunk-UQZTHVWC.mjs → chunk-JABP65XD.mjs} +2 -2
- package/dist/esm/chunk-L72TIN7T.mjs +4 -0
- package/dist/esm/chunk-L72TIN7T.mjs.map +1 -0
- package/dist/esm/{chunk-3BMZKCLH.mjs → chunk-M3AO73ZL.mjs} +2 -2
- package/dist/esm/chunk-MCFQE4GC.mjs +2 -0
- package/dist/esm/chunk-MCFQE4GC.mjs.map +1 -0
- package/dist/esm/chunk-OLILO7VD.mjs +2 -0
- package/dist/esm/{chunk-JCFTAG5Z.mjs.map → chunk-OLILO7VD.mjs.map} +1 -1
- package/dist/esm/{chunk-NF73V673.mjs → chunk-QP2BY4PK.mjs} +2 -2
- package/dist/esm/{chunk-Y7ZQTLH4.mjs → chunk-RCSJFTST.mjs} +2 -2
- package/dist/esm/{chunk-XYXBAU4J.mjs → chunk-SJDCGNWU.mjs} +2 -2
- package/dist/esm/{chunk-HZVN4JSO.mjs → chunk-WHSTLR3F.mjs} +2 -2
- package/dist/esm/chunk-ZP4DWSQA.mjs +2 -0
- package/dist/esm/chunk-ZP4DWSQA.mjs.map +1 -0
- package/dist/esm/cli/index.d.mts +1 -1
- package/dist/esm/cli/index.mjs +1 -1
- package/dist/esm/cli/localNode.mjs +1 -1
- package/dist/esm/cli/move.d.mts +1 -1
- package/dist/esm/client/core.d.mts +1 -1
- package/dist/esm/client/core.mjs +1 -1
- package/dist/esm/client/get.d.mts +1 -1
- package/dist/esm/client/get.mjs +1 -1
- package/dist/esm/client/index.d.mts +1 -1
- package/dist/esm/client/index.mjs +1 -1
- package/dist/esm/client/post.d.mts +1 -1
- package/dist/esm/client/post.mjs +1 -1
- package/dist/esm/core/account/index.d.mts +1 -1
- package/dist/esm/core/account/index.mjs +1 -1
- package/dist/esm/core/account/utils/address.d.mts +1 -1
- package/dist/esm/core/account/utils/address.mjs +1 -1
- package/dist/esm/core/account/utils/index.d.mts +1 -1
- package/dist/esm/core/account/utils/index.mjs +1 -1
- package/dist/esm/core/accountAddress.d.mts +1 -1
- package/dist/esm/core/accountAddress.mjs +1 -1
- package/dist/esm/core/authenticationKey.d.mts +1 -1
- package/dist/esm/core/authenticationKey.mjs +1 -1
- package/dist/esm/core/crypto/abstraction.d.mts +1 -1
- package/dist/esm/core/crypto/abstraction.mjs +1 -1
- package/dist/esm/core/crypto/deserializationUtils.d.mts +1 -1
- package/dist/esm/core/crypto/deserializationUtils.mjs +1 -1
- package/dist/esm/core/crypto/ed25519.d.mts +1 -1
- package/dist/esm/core/crypto/ed25519.mjs +1 -1
- package/dist/esm/core/crypto/ephemeral.d.mts +1 -1
- package/dist/esm/core/crypto/ephemeral.mjs +1 -1
- package/dist/esm/core/crypto/federatedKeyless.d.mts +2 -2
- package/dist/esm/core/crypto/federatedKeyless.mjs +1 -1
- package/dist/esm/core/crypto/index.d.mts +3 -2
- package/dist/esm/core/crypto/index.mjs +1 -1
- package/dist/esm/core/crypto/keyless.d.mts +2 -2
- package/dist/esm/core/crypto/keyless.mjs +1 -1
- package/dist/esm/core/crypto/multiEd25519.d.mts +1 -1
- package/dist/esm/core/crypto/multiEd25519.mjs +1 -1
- package/dist/esm/core/crypto/multiKey.d.mts +1 -1
- package/dist/esm/core/crypto/multiKey.mjs +1 -1
- package/dist/esm/core/crypto/privateKey.d.mts +1 -1
- package/dist/esm/core/crypto/privateKey.mjs +1 -1
- package/dist/esm/core/crypto/proof.d.mts +1 -1
- package/dist/esm/core/crypto/proof.mjs +1 -1
- package/dist/esm/core/crypto/publicKey.d.mts +1 -1
- package/dist/esm/core/crypto/publicKey.mjs +1 -1
- package/dist/esm/core/crypto/secp256k1.d.mts +1 -1
- package/dist/esm/core/crypto/secp256k1.mjs +1 -1
- package/dist/esm/core/crypto/secp256r1.d.mts +306 -0
- package/dist/esm/core/crypto/secp256r1.mjs +2 -0
- package/dist/esm/core/crypto/secp256r1.mjs.map +1 -0
- package/dist/esm/core/crypto/signature.d.mts +1 -1
- package/dist/esm/core/crypto/signature.mjs +1 -1
- package/dist/esm/core/crypto/singleKey.d.mts +1 -1
- package/dist/esm/core/crypto/singleKey.mjs +1 -1
- package/dist/esm/core/crypto/types.d.mts +1 -1
- package/dist/esm/core/crypto/utils.d.mts +5 -2
- package/dist/esm/core/crypto/utils.mjs +1 -1
- package/dist/esm/core/hex.d.mts +1 -1
- package/dist/esm/core/index.d.mts +3 -2
- package/dist/esm/core/index.mjs +1 -1
- package/dist/esm/errors/index.d.mts +1 -1
- package/dist/esm/errors/index.mjs +1 -1
- package/dist/esm/{federatedKeyless-CiyplsOB.d.mts → federatedKeyless-CTzDAQTu.d.mts} +1 -1
- package/dist/esm/index.d.mts +5 -4
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/internal/abstraction.d.mts +1 -1
- package/dist/esm/internal/abstraction.mjs +1 -1
- package/dist/esm/internal/account.d.mts +45 -21
- package/dist/esm/internal/account.mjs +1 -1
- package/dist/esm/internal/ans.d.mts +2 -2
- package/dist/esm/internal/ans.mjs +1 -1
- package/dist/esm/internal/coin.d.mts +1 -1
- package/dist/esm/internal/coin.mjs +1 -1
- package/dist/esm/internal/digitalAsset.d.mts +2 -2
- package/dist/esm/internal/digitalAsset.mjs +1 -1
- package/dist/esm/internal/faucet.d.mts +1 -1
- package/dist/esm/internal/faucet.mjs +1 -1
- package/dist/esm/internal/fungibleAsset.d.mts +2 -2
- package/dist/esm/internal/fungibleAsset.mjs +1 -1
- package/dist/esm/internal/general.d.mts +1 -1
- package/dist/esm/internal/general.mjs +1 -1
- package/dist/esm/internal/keyless.d.mts +3 -3
- package/dist/esm/internal/keyless.mjs +1 -1
- package/dist/esm/internal/object.d.mts +1 -1
- package/dist/esm/internal/object.mjs +1 -1
- package/dist/esm/internal/staking.d.mts +1 -1
- package/dist/esm/internal/staking.mjs +1 -1
- package/dist/esm/internal/table.d.mts +1 -1
- package/dist/esm/internal/table.mjs +1 -1
- package/dist/esm/internal/transaction.d.mts +1 -1
- package/dist/esm/internal/transaction.mjs +1 -1
- package/dist/esm/internal/transactionSubmission.d.mts +2 -2
- package/dist/esm/internal/transactionSubmission.mjs +1 -1
- package/dist/esm/internal/utils/index.d.mts +1 -1
- package/dist/esm/internal/utils/index.mjs +1 -1
- package/dist/esm/internal/utils/utils.d.mts +1 -1
- package/dist/esm/internal/utils/utils.mjs +1 -1
- package/dist/esm/internal/view.d.mts +1 -1
- package/dist/esm/internal/view.mjs +1 -1
- package/dist/esm/transactions/authenticator/account.d.mts +1 -1
- package/dist/esm/transactions/authenticator/account.mjs +1 -1
- package/dist/esm/transactions/authenticator/index.d.mts +1 -1
- package/dist/esm/transactions/authenticator/index.mjs +1 -1
- package/dist/esm/transactions/authenticator/transaction.d.mts +1 -1
- package/dist/esm/transactions/authenticator/transaction.mjs +1 -1
- package/dist/esm/transactions/index.d.mts +1 -1
- package/dist/esm/transactions/index.mjs +1 -1
- package/dist/esm/transactions/instances/chainId.d.mts +1 -1
- package/dist/esm/transactions/instances/identifier.d.mts +1 -1
- package/dist/esm/transactions/instances/index.d.mts +1 -1
- package/dist/esm/transactions/instances/index.mjs +1 -1
- package/dist/esm/transactions/instances/moduleId.d.mts +1 -1
- package/dist/esm/transactions/instances/moduleId.mjs +1 -1
- package/dist/esm/transactions/instances/multiAgentTransaction.d.mts +1 -1
- package/dist/esm/transactions/instances/multiAgentTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/rawTransaction.d.mts +1 -1
- package/dist/esm/transactions/instances/rawTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/rotationProofChallenge.d.mts +1 -1
- package/dist/esm/transactions/instances/rotationProofChallenge.mjs +1 -1
- package/dist/esm/transactions/instances/signedTransaction.d.mts +1 -1
- package/dist/esm/transactions/instances/signedTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/simpleTransaction.d.mts +1 -1
- package/dist/esm/transactions/instances/simpleTransaction.mjs +1 -1
- package/dist/esm/transactions/instances/transactionArgument.d.mts +1 -1
- package/dist/esm/transactions/instances/transactionPayload.d.mts +1 -1
- package/dist/esm/transactions/instances/transactionPayload.mjs +1 -1
- package/dist/esm/transactions/management/accountSequenceNumber.d.mts +2 -2
- package/dist/esm/transactions/management/accountSequenceNumber.mjs +1 -1
- package/dist/esm/transactions/management/index.d.mts +2 -2
- package/dist/esm/transactions/management/index.mjs +1 -1
- package/dist/esm/transactions/management/transactionWorker.d.mts +2 -2
- package/dist/esm/transactions/management/transactionWorker.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/helpers.d.mts +1 -1
- package/dist/esm/transactions/transactionBuilder/helpers.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/index.d.mts +1 -1
- package/dist/esm/transactions/transactionBuilder/index.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/remoteAbi.d.mts +1 -1
- package/dist/esm/transactions/transactionBuilder/remoteAbi.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/signingMessage.d.mts +1 -1
- package/dist/esm/transactions/transactionBuilder/signingMessage.mjs +1 -1
- package/dist/esm/transactions/transactionBuilder/transactionBuilder.d.mts +2 -2
- package/dist/esm/transactions/transactionBuilder/transactionBuilder.mjs +1 -1
- package/dist/esm/transactions/typeTag/index.d.mts +1 -1
- package/dist/esm/transactions/typeTag/index.mjs +1 -1
- package/dist/esm/transactions/typeTag/parser.d.mts +1 -1
- package/dist/esm/transactions/typeTag/parser.mjs +1 -1
- package/dist/esm/transactions/types.d.mts +1 -1
- package/dist/esm/types/abstraction.d.mts +9 -3
- package/dist/esm/types/abstraction.mjs +1 -1
- package/dist/esm/types/index.d.mts +1 -1
- package/dist/esm/types/index.mjs +1 -1
- package/dist/esm/types/types.d.mts +1 -1
- package/dist/esm/types/types.mjs +1 -1
- package/dist/esm/utils/const.d.mts +2 -1
- package/dist/esm/utils/const.mjs +1 -1
- package/dist/esm/utils/helpers.d.mts +1 -1
- package/dist/esm/utils/helpers.mjs +1 -1
- package/dist/esm/utils/index.d.mts +2 -2
- package/dist/esm/utils/index.mjs +1 -1
- package/dist/esm/utils/normalizeBundle.d.mts +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 +27 -28
- package/src/account/AbstractedAccount.ts +16 -3
- package/src/account/DerivableAbstractedAccount.ts +3 -1
- package/src/api/account.ts +36 -23
- package/src/api/transaction.ts +59 -36
- package/src/core/crypto/index.ts +1 -0
- package/src/core/crypto/privateKey.ts +1 -0
- package/src/core/crypto/secp256k1.ts +9 -1
- package/src/core/crypto/secp256r1.ts +495 -0
- package/src/core/crypto/singleKey.ts +11 -0
- package/src/core/crypto/utils.ts +38 -1
- package/src/internal/account.ts +69 -83
- package/src/transactions/authenticator/account.ts +71 -17
- package/src/types/abstraction.ts +9 -2
- package/src/types/types.ts +5 -0
- package/src/utils/const.ts +2 -0
- package/src/version.ts +1 -1
- package/dist/common/chunk-6MMUUJHX.js +0 -4
- package/dist/common/chunk-6MMUUJHX.js.map +0 -1
- package/dist/esm/chunk-4JT5AESZ.mjs +0 -2
- package/dist/esm/chunk-4JT5AESZ.mjs.map +0 -1
- package/dist/esm/chunk-55Q7BSZT.mjs +0 -6
- package/dist/esm/chunk-55Q7BSZT.mjs.map +0 -1
- package/dist/esm/chunk-6SLY7UV2.mjs +0 -2
- package/dist/esm/chunk-DPW6ELCQ.mjs +0 -2
- package/dist/esm/chunk-DPW6ELCQ.mjs.map +0 -1
- package/dist/esm/chunk-IJE2LVZG.mjs +0 -2
- package/dist/esm/chunk-IJE2LVZG.mjs.map +0 -1
- package/dist/esm/chunk-JCFTAG5Z.mjs +0 -2
- package/dist/esm/chunk-K43K3YG7.mjs +0 -2
- package/dist/esm/chunk-K43K3YG7.mjs.map +0 -1
- package/dist/esm/chunk-KJH4KKG6.mjs +0 -2
- package/dist/esm/chunk-KJH4KKG6.mjs.map +0 -1
- package/dist/esm/chunk-MSMFHPDT.mjs +0 -2
- package/dist/esm/chunk-MSMFHPDT.mjs.map +0 -1
- package/dist/esm/chunk-ROT6S6BM.mjs +0 -2
- package/dist/esm/chunk-ROT6S6BM.mjs.map +0 -1
- /package/dist/esm/{chunk-6JYQ5P36.mjs.map → chunk-4AI7KQQ7.mjs.map} +0 -0
- /package/dist/esm/{chunk-V6C6NWFU.mjs.map → chunk-6OWBKU7N.mjs.map} +0 -0
- /package/dist/esm/{chunk-BPWSOC2Y.mjs.map → chunk-7EER7GWV.mjs.map} +0 -0
- /package/dist/esm/{chunk-PLI53ZU6.mjs.map → chunk-AMXZQPUQ.mjs.map} +0 -0
- /package/dist/esm/{chunk-UQZTHVWC.mjs.map → chunk-JABP65XD.mjs.map} +0 -0
- /package/dist/esm/{chunk-3BMZKCLH.mjs.map → chunk-M3AO73ZL.mjs.map} +0 -0
- /package/dist/esm/{chunk-NF73V673.mjs.map → chunk-QP2BY4PK.mjs.map} +0 -0
- /package/dist/esm/{chunk-Y7ZQTLH4.mjs.map → chunk-RCSJFTST.mjs.map} +0 -0
- /package/dist/esm/{chunk-XYXBAU4J.mjs.map → chunk-SJDCGNWU.mjs.map} +0 -0
- /package/dist/esm/{chunk-HZVN4JSO.mjs.map → chunk-WHSTLR3F.mjs.map} +0 -0
package/src/internal/account.ts
CHANGED
|
@@ -93,6 +93,7 @@ import {
|
|
|
93
93
|
EntryFunctionABI,
|
|
94
94
|
InputGenerateTransactionOptions,
|
|
95
95
|
RotationProofChallenge,
|
|
96
|
+
SimpleTransaction,
|
|
96
97
|
TypeTagU8,
|
|
97
98
|
TypeTagVector,
|
|
98
99
|
} from "../transactions";
|
|
@@ -100,6 +101,7 @@ import { U8, MoveVector } from "../bcs";
|
|
|
100
101
|
import { waitForTransaction, waitForIndexer } from "./transaction";
|
|
101
102
|
import { view } from "./view";
|
|
102
103
|
import { getLedgerInfo } from "./general";
|
|
104
|
+
import { accountPublicKeyToBaseAccountPublicKey, accountPublicKeyToSigningScheme } from "../core/crypto/utils";
|
|
103
105
|
|
|
104
106
|
/**
|
|
105
107
|
* Retrieves account information for a specified account address.
|
|
@@ -743,6 +745,39 @@ export async function getAccountCoinsCount(args: {
|
|
|
743
745
|
return data.current_fungible_asset_balances_aggregate.aggregate.count;
|
|
744
746
|
}
|
|
745
747
|
|
|
748
|
+
/**
|
|
749
|
+
* Retrieves an account's balance for the given asset via the fullnode REST API.
|
|
750
|
+
*
|
|
751
|
+
* - `asset` may be a coin type (Move struct ID, e.g. `0x1::aptos_coin::AptosCoin`) or an FA metadata address.
|
|
752
|
+
* - Calls: `GET /accounts/{accountAddress}/balance/{asset}` and returns the numeric balance.
|
|
753
|
+
*
|
|
754
|
+
* @param args - The parameters for the request.
|
|
755
|
+
* @param args.aptosConfig - The Aptos configuration object.
|
|
756
|
+
* @param args.accountAddress - The account address to query.
|
|
757
|
+
* @param args.asset - The asset identifier (coin type or FA metadata address).
|
|
758
|
+
* @returns The balance as a number.
|
|
759
|
+
* @group Implementation
|
|
760
|
+
*/
|
|
761
|
+
export async function getBalance(args: {
|
|
762
|
+
aptosConfig: AptosConfig;
|
|
763
|
+
accountAddress: AccountAddressInput;
|
|
764
|
+
asset: MoveStructId | AccountAddressInput;
|
|
765
|
+
}): Promise<number> {
|
|
766
|
+
const { aptosConfig, accountAddress, asset } = args;
|
|
767
|
+
|
|
768
|
+
const response = await getAptosFullNode<{}, number>({
|
|
769
|
+
aptosConfig,
|
|
770
|
+
originMethod: "getBalance",
|
|
771
|
+
path: `accounts/${accountAddress}/balance/${asset}`,
|
|
772
|
+
params: {
|
|
773
|
+
accountAddress: accountAddress.toString(),
|
|
774
|
+
asset: asset instanceof Uint8Array ? AccountAddress.from(asset).toString() : asset.toString(),
|
|
775
|
+
},
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
return parseInt(response.data.toString(), 10);
|
|
779
|
+
}
|
|
780
|
+
|
|
746
781
|
/**
|
|
747
782
|
* Retrieves the objects owned by a specified account.
|
|
748
783
|
*
|
|
@@ -933,23 +968,15 @@ const rotateAuthKeyAbi: EntryFunctionABI = {
|
|
|
933
968
|
* @param args - The arguments for rotating the authentication key.
|
|
934
969
|
* @param args.aptosConfig - The configuration settings for the Aptos network.
|
|
935
970
|
* @param args.fromAccount - The account from which the authentication key will be rotated.
|
|
936
|
-
* @param args.toAccount - (Optional) The target account to rotate to. Required if not using toNewPrivateKey
|
|
937
|
-
* @param args.toNewPrivateKey - (Optional) The new private key to rotate to. Required if not using toAccount
|
|
938
|
-
* @param args.toAuthKey - (Optional) The new authentication key to rotate to. Can only be used with dangerouslySkipVerification=true.
|
|
939
|
-
* @param args.dangerouslySkipVerification - (Optional) If true, skips verification steps after rotation. Required when using toAuthKey.
|
|
971
|
+
* @param args.toAccount - (Optional) The target account to rotate to. Required if not using toNewPrivateKey.
|
|
972
|
+
* @param args.toNewPrivateKey - (Optional) The new private key to rotate to. Required if not using toAccount.
|
|
940
973
|
*
|
|
941
974
|
* @remarks
|
|
942
975
|
* This function supports three modes of rotation:
|
|
943
976
|
* 1. Using a target Account object (toAccount)
|
|
944
977
|
* 2. Using a new private key (toNewPrivateKey)
|
|
945
|
-
* 3. Using a raw authentication key (toAuthKey) - requires dangerouslySkipVerification=true
|
|
946
|
-
*
|
|
947
|
-
* When not using dangerouslySkipVerification, the function performs additional safety checks and account setup.
|
|
948
978
|
*
|
|
949
|
-
*
|
|
950
|
-
* prevent users from being locked out of the account from loss of knowledge of one of the public keys.
|
|
951
|
-
*
|
|
952
|
-
* @returns A promise that resolves to the pending transaction response.
|
|
979
|
+
* @returns A simple transaction object that can be submitted to the network.
|
|
953
980
|
* @throws Error if the rotation fails or verification fails.
|
|
954
981
|
*
|
|
955
982
|
* @group Implementation
|
|
@@ -959,13 +986,9 @@ export async function rotateAuthKey(
|
|
|
959
986
|
aptosConfig: AptosConfig;
|
|
960
987
|
fromAccount: Account;
|
|
961
988
|
options?: InputGenerateTransactionOptions;
|
|
962
|
-
} & (
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
| { toAuthKey: AuthenticationKey; dangerouslySkipVerification: true }
|
|
966
|
-
),
|
|
967
|
-
): Promise<PendingTransactionResponse> {
|
|
968
|
-
const { aptosConfig, fromAccount, dangerouslySkipVerification, options } = args;
|
|
989
|
+
} & ({ toAccount: Ed25519Account | MultiEd25519Account } | { toNewPrivateKey: Ed25519PrivateKey }),
|
|
990
|
+
): Promise<SimpleTransaction> {
|
|
991
|
+
const { aptosConfig, fromAccount, options } = args;
|
|
969
992
|
if ("toNewPrivateKey" in args) {
|
|
970
993
|
return rotateAuthKeyWithChallenge({
|
|
971
994
|
aptosConfig,
|
|
@@ -973,9 +996,7 @@ export async function rotateAuthKey(
|
|
|
973
996
|
toNewPrivateKey: args.toNewPrivateKey,
|
|
974
997
|
options,
|
|
975
998
|
});
|
|
976
|
-
}
|
|
977
|
-
let authKey: AuthenticationKey;
|
|
978
|
-
if ("toAccount" in args) {
|
|
999
|
+
} else if ("toAccount" in args) {
|
|
979
1000
|
if (args.toAccount instanceof Ed25519Account) {
|
|
980
1001
|
return rotateAuthKeyWithChallenge({
|
|
981
1002
|
aptosConfig,
|
|
@@ -983,52 +1004,12 @@ export async function rotateAuthKey(
|
|
|
983
1004
|
toNewPrivateKey: args.toAccount.privateKey,
|
|
984
1005
|
options,
|
|
985
1006
|
});
|
|
986
|
-
}
|
|
987
|
-
if (args.toAccount instanceof MultiEd25519Account) {
|
|
1007
|
+
} else {
|
|
988
1008
|
return rotateAuthKeyWithChallenge({ aptosConfig, fromAccount, toAccount: args.toAccount, options });
|
|
989
1009
|
}
|
|
990
|
-
authKey = args.toAccount.publicKey.authKey();
|
|
991
|
-
} else if ("toAuthKey" in args) {
|
|
992
|
-
authKey = args.toAuthKey;
|
|
993
1010
|
} else {
|
|
994
1011
|
throw new Error("Invalid arguments");
|
|
995
1012
|
}
|
|
996
|
-
|
|
997
|
-
const pendingTxn = await rotateAuthKeyUnverified({
|
|
998
|
-
aptosConfig,
|
|
999
|
-
fromAccount,
|
|
1000
|
-
toAuthKey: authKey,
|
|
1001
|
-
options,
|
|
1002
|
-
});
|
|
1003
|
-
|
|
1004
|
-
if (dangerouslySkipVerification === true) {
|
|
1005
|
-
return pendingTxn;
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
const rotateAuthKeyTxnResponse = await waitForTransaction({
|
|
1009
|
-
aptosConfig,
|
|
1010
|
-
transactionHash: pendingTxn.hash,
|
|
1011
|
-
});
|
|
1012
|
-
if (!rotateAuthKeyTxnResponse.success) {
|
|
1013
|
-
throw new Error(`Failed to rotate authentication key - ${rotateAuthKeyTxnResponse}`);
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
// Verify the rotation by setting the originating address to the new account.
|
|
1017
|
-
// This verifies the rotation even if the transaction payload fails to execute successfully.
|
|
1018
|
-
const verificationTxn = await generateTransaction({
|
|
1019
|
-
aptosConfig,
|
|
1020
|
-
sender: fromAccount.accountAddress,
|
|
1021
|
-
data: {
|
|
1022
|
-
function: "0x1::account::set_originating_address",
|
|
1023
|
-
functionArguments: [],
|
|
1024
|
-
},
|
|
1025
|
-
});
|
|
1026
|
-
|
|
1027
|
-
return signAndSubmitTransaction({
|
|
1028
|
-
aptosConfig,
|
|
1029
|
-
signer: args.toAccount, // Use the new account to sign
|
|
1030
|
-
transaction: verificationTxn,
|
|
1031
|
-
});
|
|
1032
1013
|
}
|
|
1033
1014
|
|
|
1034
1015
|
async function rotateAuthKeyWithChallenge(
|
|
@@ -1037,7 +1018,7 @@ async function rotateAuthKeyWithChallenge(
|
|
|
1037
1018
|
fromAccount: Account;
|
|
1038
1019
|
options?: InputGenerateTransactionOptions;
|
|
1039
1020
|
} & ({ toNewPrivateKey: Ed25519PrivateKey } | { toAccount: MultiEd25519Account }),
|
|
1040
|
-
): Promise<
|
|
1021
|
+
): Promise<SimpleTransaction> {
|
|
1041
1022
|
const { aptosConfig, fromAccount, options } = args;
|
|
1042
1023
|
const accountInfo = await getInfo({
|
|
1043
1024
|
aptosConfig,
|
|
@@ -1064,7 +1045,7 @@ async function rotateAuthKeyWithChallenge(
|
|
|
1064
1045
|
const proofSignedByNewKey = newAccount.sign(challengeHex);
|
|
1065
1046
|
|
|
1066
1047
|
// Generate transaction
|
|
1067
|
-
|
|
1048
|
+
return generateTransaction({
|
|
1068
1049
|
aptosConfig,
|
|
1069
1050
|
sender: fromAccount.accountAddress,
|
|
1070
1051
|
data: {
|
|
@@ -1081,41 +1062,46 @@ async function rotateAuthKeyWithChallenge(
|
|
|
1081
1062
|
},
|
|
1082
1063
|
options,
|
|
1083
1064
|
});
|
|
1084
|
-
return signAndSubmitTransaction({
|
|
1085
|
-
aptosConfig,
|
|
1086
|
-
signer: fromAccount,
|
|
1087
|
-
transaction: rawTxn,
|
|
1088
|
-
});
|
|
1089
1065
|
}
|
|
1090
1066
|
|
|
1091
1067
|
const rotateAuthKeyUnverifiedAbi: EntryFunctionABI = {
|
|
1092
1068
|
typeParameters: [],
|
|
1093
|
-
parameters: [TypeTagVector.u8()],
|
|
1069
|
+
parameters: [new TypeTagU8(), TypeTagVector.u8()],
|
|
1094
1070
|
};
|
|
1095
1071
|
|
|
1096
|
-
|
|
1072
|
+
/**
|
|
1073
|
+
* Rotates the authentication key for a given account without verifying the new key.
|
|
1074
|
+
*
|
|
1075
|
+
* @param args - The arguments for rotating the authentication key.
|
|
1076
|
+
* @param args.aptosConfig - The configuration settings for the Aptos network.
|
|
1077
|
+
* @param args.fromAccount - The account from which the authentication key will be rotated.
|
|
1078
|
+
* @param args.toNewPublicKey - The new public key to rotate to.
|
|
1079
|
+
* @returns A simple transaction object that can be submitted to the network.
|
|
1080
|
+
* @throws Error if the rotation fails or verification fails.
|
|
1081
|
+
*
|
|
1082
|
+
* @group Implementation
|
|
1083
|
+
*/
|
|
1084
|
+
export async function rotateAuthKeyUnverified(args: {
|
|
1097
1085
|
aptosConfig: AptosConfig;
|
|
1098
1086
|
fromAccount: Account;
|
|
1099
|
-
|
|
1087
|
+
toNewPublicKey: AccountPublicKey;
|
|
1100
1088
|
options?: InputGenerateTransactionOptions;
|
|
1101
|
-
}): Promise<
|
|
1102
|
-
const { aptosConfig, fromAccount,
|
|
1103
|
-
|
|
1104
|
-
|
|
1089
|
+
}): Promise<SimpleTransaction> {
|
|
1090
|
+
const { aptosConfig, fromAccount, toNewPublicKey, options } = args;
|
|
1091
|
+
|
|
1092
|
+
return generateTransaction({
|
|
1105
1093
|
aptosConfig,
|
|
1106
1094
|
sender: fromAccount.accountAddress,
|
|
1107
1095
|
data: {
|
|
1108
|
-
function: "0x1::account::
|
|
1109
|
-
functionArguments: [
|
|
1096
|
+
function: "0x1::account::rotate_authentication_key_from_public_key",
|
|
1097
|
+
functionArguments: [
|
|
1098
|
+
new U8(accountPublicKeyToSigningScheme(toNewPublicKey)), // to scheme
|
|
1099
|
+
MoveVector.U8(accountPublicKeyToBaseAccountPublicKey(toNewPublicKey).toUint8Array()),
|
|
1100
|
+
],
|
|
1110
1101
|
abi: rotateAuthKeyUnverifiedAbi,
|
|
1111
1102
|
},
|
|
1112
1103
|
options,
|
|
1113
1104
|
});
|
|
1114
|
-
return signAndSubmitTransaction({
|
|
1115
|
-
aptosConfig,
|
|
1116
|
-
signer: fromAccount,
|
|
1117
|
-
transaction: rawTxn,
|
|
1118
|
-
});
|
|
1119
1105
|
}
|
|
1120
1106
|
|
|
1121
1107
|
export type AccountInfo = {
|
|
@@ -9,7 +9,7 @@ import { Ed25519PublicKey, Ed25519Signature } from "../../core/crypto/ed25519";
|
|
|
9
9
|
import { MultiEd25519PublicKey, MultiEd25519Signature } from "../../core/crypto/multiEd25519";
|
|
10
10
|
import { MultiKey, MultiKeySignature } from "../../core/crypto/multiKey";
|
|
11
11
|
import { AccountAuthenticatorVariant, HexInput, MoveFunctionId } from "../../types";
|
|
12
|
-
import {
|
|
12
|
+
import { AASigningDataVariant, AbstractAuthenticationDataVariant } from "../../types/abstraction";
|
|
13
13
|
import { AccountAddress, Hex } from "../../core";
|
|
14
14
|
import { getFunctionParts, isValidFunctionInfo } from "../../utils/helpers";
|
|
15
15
|
|
|
@@ -269,12 +269,22 @@ export class AccountAuthenticatorNoAccountAuthenticator extends AccountAuthentic
|
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Represents an account authenticator that supports abstract authentication.
|
|
274
|
+
*
|
|
275
|
+
* @param functionInfo - The function info of the authentication function.
|
|
276
|
+
* @param signingMessageDigest - The digest of the signing message.
|
|
277
|
+
* @param abstractionSignature - The signature of the authentication function.
|
|
278
|
+
* @param accountIdentity - optional. The account identity for DAA.
|
|
279
|
+
* @group Implementation
|
|
280
|
+
* @category Transactions
|
|
281
|
+
*/
|
|
272
282
|
export class AccountAuthenticatorAbstraction extends AccountAuthenticator {
|
|
273
283
|
public readonly functionInfo: string;
|
|
274
284
|
|
|
275
285
|
public readonly signingMessageDigest: Hex;
|
|
276
286
|
|
|
277
|
-
public readonly
|
|
287
|
+
public readonly abstractionSignature: Uint8Array;
|
|
278
288
|
|
|
279
289
|
/**
|
|
280
290
|
* DAA, which is extended of the AA module, requires an account identity
|
|
@@ -284,7 +294,7 @@ export class AccountAuthenticatorAbstraction extends AccountAuthenticator {
|
|
|
284
294
|
constructor(
|
|
285
295
|
functionInfo: string,
|
|
286
296
|
signingMessageDigest: HexInput,
|
|
287
|
-
|
|
297
|
+
abstractionSignature: Uint8Array,
|
|
288
298
|
accountIdentity?: Uint8Array,
|
|
289
299
|
) {
|
|
290
300
|
super();
|
|
@@ -292,7 +302,7 @@ export class AccountAuthenticatorAbstraction extends AccountAuthenticator {
|
|
|
292
302
|
throw new Error(`Invalid function info ${functionInfo} passed into AccountAuthenticatorAbstraction`);
|
|
293
303
|
}
|
|
294
304
|
this.functionInfo = functionInfo;
|
|
295
|
-
this.
|
|
305
|
+
this.abstractionSignature = abstractionSignature;
|
|
296
306
|
this.signingMessageDigest = Hex.fromHexInput(Hex.fromHexInput(signingMessageDigest).toUint8Array());
|
|
297
307
|
this.accountIdentity = accountIdentity;
|
|
298
308
|
}
|
|
@@ -304,15 +314,15 @@ export class AccountAuthenticatorAbstraction extends AccountAuthenticator {
|
|
|
304
314
|
serializer.serializeStr(moduleName);
|
|
305
315
|
serializer.serializeStr(functionName);
|
|
306
316
|
if (this.accountIdentity) {
|
|
307
|
-
serializer.serializeU32AsUleb128(
|
|
317
|
+
serializer.serializeU32AsUleb128(AbstractAuthenticationDataVariant.DerivableV1);
|
|
308
318
|
} else {
|
|
309
|
-
serializer.serializeU32AsUleb128(
|
|
319
|
+
serializer.serializeU32AsUleb128(AbstractAuthenticationDataVariant.V1);
|
|
310
320
|
}
|
|
311
321
|
serializer.serializeBytes(this.signingMessageDigest.toUint8Array());
|
|
312
322
|
if (this.accountIdentity) {
|
|
313
|
-
serializer.serializeBytes(this.
|
|
323
|
+
serializer.serializeBytes(this.abstractionSignature);
|
|
314
324
|
} else {
|
|
315
|
-
serializer.serializeFixedBytes(this.
|
|
325
|
+
serializer.serializeFixedBytes(this.abstractionSignature);
|
|
316
326
|
}
|
|
317
327
|
|
|
318
328
|
if (this.accountIdentity) {
|
|
@@ -321,31 +331,75 @@ export class AccountAuthenticatorAbstraction extends AccountAuthenticator {
|
|
|
321
331
|
}
|
|
322
332
|
|
|
323
333
|
static load(deserializer: Deserializer): AccountAuthenticatorAbstraction {
|
|
334
|
+
// deserialize the function info
|
|
324
335
|
const moduleAddress = AccountAddress.deserialize(deserializer);
|
|
325
336
|
const moduleName = deserializer.deserializeStr();
|
|
326
337
|
const functionName = deserializer.deserializeStr();
|
|
338
|
+
// deserialize the variant
|
|
327
339
|
const variant = deserializer.deserializeUleb128AsU32();
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
340
|
+
// deserialize the signing message digest
|
|
341
|
+
const signingMessageDigest = deserializer.deserializeBytes();
|
|
342
|
+
|
|
343
|
+
if (variant === AbstractAuthenticationDataVariant.V1) {
|
|
344
|
+
const abstractionSignature = deserializer.deserializeFixedBytes(deserializer.remaining());
|
|
331
345
|
return new AccountAuthenticatorAbstraction(
|
|
332
346
|
`${moduleAddress}::${moduleName}::${functionName}`,
|
|
333
347
|
signingMessageDigest,
|
|
334
|
-
|
|
348
|
+
abstractionSignature,
|
|
335
349
|
);
|
|
336
350
|
}
|
|
337
|
-
if (variant ===
|
|
338
|
-
const
|
|
339
|
-
const abstractSignature = deserializer.deserializeBytes();
|
|
340
|
-
|
|
351
|
+
if (variant === AbstractAuthenticationDataVariant.DerivableV1) {
|
|
352
|
+
const abstractionSignature = deserializer.deserializeBytes();
|
|
341
353
|
const abstractPublicKey = deserializer.deserializeBytes();
|
|
342
354
|
return new AccountAuthenticatorAbstraction(
|
|
343
355
|
`${moduleAddress}::${moduleName}::${functionName}`,
|
|
344
356
|
signingMessageDigest,
|
|
345
|
-
|
|
357
|
+
abstractionSignature,
|
|
346
358
|
abstractPublicKey,
|
|
347
359
|
);
|
|
348
360
|
}
|
|
349
361
|
throw new Error(`Unknown variant index for AccountAuthenticatorAbstraction: ${variant}`);
|
|
350
362
|
}
|
|
351
363
|
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Represents an account abstraction message that contains the original signing message and the function info.
|
|
367
|
+
*
|
|
368
|
+
* @param originalSigningMessage - The original signing message.
|
|
369
|
+
* @param functionInfo - The function info of the authentication function.
|
|
370
|
+
* @group Implementation
|
|
371
|
+
* @category Transactions
|
|
372
|
+
*/
|
|
373
|
+
export class AccountAbstractionMessage extends Serializable {
|
|
374
|
+
public readonly originalSigningMessage: Hex;
|
|
375
|
+
|
|
376
|
+
public readonly functionInfo: string;
|
|
377
|
+
|
|
378
|
+
constructor(originalSigningMessage: HexInput, functionInfo: string) {
|
|
379
|
+
super();
|
|
380
|
+
this.originalSigningMessage = Hex.fromHexInput(Hex.fromHexInput(originalSigningMessage).toUint8Array());
|
|
381
|
+
this.functionInfo = functionInfo;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
serialize(serializer: Serializer): void {
|
|
385
|
+
serializer.serializeU32AsUleb128(AASigningDataVariant.V1);
|
|
386
|
+
serializer.serializeBytes(this.originalSigningMessage.toUint8Array());
|
|
387
|
+
const { moduleAddress, moduleName, functionName } = getFunctionParts(this.functionInfo as MoveFunctionId);
|
|
388
|
+
AccountAddress.fromString(moduleAddress).serialize(serializer);
|
|
389
|
+
serializer.serializeStr(moduleName);
|
|
390
|
+
serializer.serializeStr(functionName);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
static deserialize(deserializer: Deserializer): AccountAbstractionMessage {
|
|
394
|
+
const variant = deserializer.deserializeUleb128AsU32();
|
|
395
|
+
if (variant !== AASigningDataVariant.V1) {
|
|
396
|
+
throw new Error(`Unknown variant index for AccountAbstractionMessage: ${variant}`);
|
|
397
|
+
}
|
|
398
|
+
const originalSigningMessage = deserializer.deserializeBytes();
|
|
399
|
+
const functionInfoModuleAddress = AccountAddress.deserialize(deserializer);
|
|
400
|
+
const functionInfoModuleName = deserializer.deserializeStr();
|
|
401
|
+
const functionInfoFunctionName = deserializer.deserializeStr();
|
|
402
|
+
const functionInfo = `${functionInfoModuleAddress}::${functionInfoModuleName}::${functionInfoFunctionName}`;
|
|
403
|
+
return new AccountAbstractionMessage(originalSigningMessage, functionInfo);
|
|
404
|
+
}
|
|
405
|
+
}
|
package/src/types/abstraction.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The variant for the
|
|
2
|
+
* The variant for the AbstractAuthenticationData enum.
|
|
3
3
|
*/
|
|
4
|
-
export enum
|
|
4
|
+
export enum AbstractAuthenticationDataVariant {
|
|
5
5
|
V1 = 0,
|
|
6
6
|
DerivableV1 = 1,
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The variant for the AASigningData enum.
|
|
11
|
+
*/
|
|
12
|
+
export enum AASigningDataVariant {
|
|
13
|
+
V1 = 0,
|
|
14
|
+
}
|
package/src/types/types.ts
CHANGED
|
@@ -147,6 +147,7 @@ export enum AccountAuthenticatorVariant {
|
|
|
147
147
|
export enum PrivateKeyVariants {
|
|
148
148
|
Ed25519 = "ed25519",
|
|
149
149
|
Secp256k1 = "secp256k1",
|
|
150
|
+
Secp256r1 = "secp256r1",
|
|
150
151
|
}
|
|
151
152
|
|
|
152
153
|
/**
|
|
@@ -155,6 +156,7 @@ export enum PrivateKeyVariants {
|
|
|
155
156
|
export enum AnyPublicKeyVariant {
|
|
156
157
|
Ed25519 = 0,
|
|
157
158
|
Secp256k1 = 1,
|
|
159
|
+
Secp256r1 = 2,
|
|
158
160
|
Keyless = 3,
|
|
159
161
|
FederatedKeyless = 4,
|
|
160
162
|
}
|
|
@@ -165,6 +167,8 @@ export function anyPublicKeyVariantToString(variant: AnyPublicKeyVariant): strin
|
|
|
165
167
|
return "ed25519";
|
|
166
168
|
case AnyPublicKeyVariant.Secp256k1:
|
|
167
169
|
return "secp256k1";
|
|
170
|
+
case AnyPublicKeyVariant.Secp256r1:
|
|
171
|
+
return "secp256r1";
|
|
168
172
|
case AnyPublicKeyVariant.Keyless:
|
|
169
173
|
return "keyless";
|
|
170
174
|
case AnyPublicKeyVariant.FederatedKeyless:
|
|
@@ -180,6 +184,7 @@ export function anyPublicKeyVariantToString(variant: AnyPublicKeyVariant): strin
|
|
|
180
184
|
export enum AnySignatureVariant {
|
|
181
185
|
Ed25519 = 0,
|
|
182
186
|
Secp256k1 = 1,
|
|
187
|
+
WebAuthn = 2,
|
|
183
188
|
Keyless = 3,
|
|
184
189
|
}
|
|
185
190
|
|
package/src/utils/const.ts
CHANGED
|
@@ -70,6 +70,8 @@ export const RAW_TRANSACTION_SALT = "APTOS::RawTransaction";
|
|
|
70
70
|
*/
|
|
71
71
|
export const RAW_TRANSACTION_WITH_DATA_SALT = "APTOS::RawTransactionWithData";
|
|
72
72
|
|
|
73
|
+
export const ACCOUNT_ABSTRACTION_SIGNING_DATA_SALT = "APTOS::AASigningData";
|
|
74
|
+
|
|
73
75
|
/**
|
|
74
76
|
* Supported processor types for the indexer API, sourced from the processor_status table in the indexer database.
|
|
75
77
|
* {@link https://cloud.hasura.io/public/graphiql?endpoint=https://api.mainnet.aptoslabs.com/v1/graphql}
|
package/src/version.ts
CHANGED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var N=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var h=(r,e,t,n)=>{for(var s=n>1?void 0:n?C(e,t):e,i=r.length-1,u;i>=0;i--)(u=r[i])&&(s=(n?u(e,t,s):u(s))||s);return n&&s&&N(e,t,s),s};var c=class extends Error{constructor(e,t){super(e),this.invalidReason=t}};var _utils = require('@noble/hashes/utils');var O=(n=>(n.TOO_SHORT="too_short",n.INVALID_LENGTH="invalid_length",n.INVALID_HEX_CHARS="invalid_hex_chars",n))(O||{}),_= exports.j =class r{constructor(e){this.data=e}toUint8Array(){return this.data}toStringWithoutPrefix(){return _utils.bytesToHex.call(void 0, this.data)}toString(){return`0x${this.toStringWithoutPrefix()}`}static fromHexString(e){let t=e;if(t.startsWith("0x")&&(t=t.slice(2)),t.length===0)throw new c("Hex string is too short, must be at least 1 char long, excluding the optional leading 0x.","too_short");if(t.length%2!==0)throw new c("Hex string must be an even number of hex characters.","invalid_length");try{return new r(_utils.hexToBytes.call(void 0, t))}catch(n){throw new c(`Hex string contains invalid hex characters: ${_optionalChain([n, 'optionalAccess', _2 => _2.message])}`,"invalid_hex_chars")}}static fromHexInput(e){return e instanceof Uint8Array?new r(e):r.fromHexString(e)}static hexInputToUint8Array(e){return e instanceof Uint8Array?e:r.fromHexString(e).toUint8Array()}static hexInputToString(e){return r.fromHexInput(e).toString()}static hexInputToStringWithoutPrefix(e){return r.fromHexInput(e).toStringWithoutPrefix()}static isValid(e){try{return r.fromHexString(e),{valid:!0}}catch(t){return{valid:!1,invalidReason:_optionalChain([t, 'optionalAccess', _3 => _3.invalidReason]),invalidReasonMessage:_optionalChain([t, 'optionalAccess', _4 => _4.message])}}}equals(e){return this.data.length!==e.data.length?!1:this.data.every((t,n)=>t===e.data[n])}},_e= exports.k =r=>new TextDecoder().decode(_.fromHexInput(r).toUint8Array());var R=255,U= exports.c =65535,x= exports.d =4294967295,S= exports.e =18446744073709551615n,b= exports.f =340282366920938463463374607431768211455n,v= exports.g =115792089237316195423570985008687907853269984665640564039457584007913129639935n;var m=class{bcsToBytes(){let e=new l;return this.serialize(e),e.toUint8Array()}bcsToHex(){let e=this.bcsToBytes();return _.fromHexInput(e)}toStringWithoutPrefix(){return this.bcsToHex().toStringWithoutPrefix()}toString(){return`0x${this.toStringWithoutPrefix()}`}},l= exports.m =class{constructor(e=64){if(e<=0)throw new Error("Length needs to be greater than 0");this.buffer=new ArrayBuffer(e),this.offset=0}ensureBufferWillHandleSize(e){for(;this.buffer.byteLength<this.offset+e;){let t=new ArrayBuffer(this.buffer.byteLength*2);new Uint8Array(t).set(new Uint8Array(this.buffer)),this.buffer=t}}appendToBuffer(e){this.ensureBufferWillHandleSize(e.length),new Uint8Array(this.buffer,this.offset).set(e),this.offset+=e.length}serializeWithFunction(e,t,n){this.ensureBufferWillHandleSize(t);let s=new DataView(this.buffer,this.offset);e.apply(s,[0,n,!0]),this.offset+=t}serializeStr(e){let t=new TextEncoder;this.serializeBytes(t.encode(e))}serializeBytes(e){this.serializeU32AsUleb128(e.length),this.appendToBuffer(e)}serializeFixedBytes(e){this.appendToBuffer(e)}serializeBool(e){H(e);let t=e?1:0;this.appendToBuffer(new Uint8Array([t]))}serializeU8(e){this.appendToBuffer(new Uint8Array([e]))}serializeU16(e){this.serializeWithFunction(DataView.prototype.setUint16,2,e)}serializeU32(e){this.serializeWithFunction(DataView.prototype.setUint32,4,e)}serializeU64(e){let t=BigInt(e)&BigInt(x),n=BigInt(e)>>BigInt(32);this.serializeU32(Number(t)),this.serializeU32(Number(n))}serializeU128(e){let t=BigInt(e)&S,n=BigInt(e)>>BigInt(64);this.serializeU64(t),this.serializeU64(n)}serializeU256(e){let t=BigInt(e)&b,n=BigInt(e)>>BigInt(128);this.serializeU128(t),this.serializeU128(n)}serializeU32AsUleb128(e){let t=e,n=[];for(;t>>>7;)n.push(t&127|128),t>>>=7;n.push(t),this.appendToBuffer(new Uint8Array(n))}toUint8Array(){return new Uint8Array(this.buffer).slice(0,this.offset)}serialize(e){e.serialize(this)}serializeVector(e){this.serializeU32AsUleb128(e.length),e.forEach(t=>{t.serialize(this)})}serializeOption(e,t){let n=e!==void 0;this.serializeBool(n),n&&(typeof e=="string"?this.serializeStr(e):e instanceof Uint8Array?t!==void 0?this.serializeFixedBytes(e):this.serializeBytes(e):e.serialize(this))}serializeOptionStr(e){e===void 0?this.serializeU32AsUleb128(0):(this.serializeU32AsUleb128(1),this.serializeStr(e))}};h([f(0,R)],l.prototype,"serializeU8",1),h([f(0,U)],l.prototype,"serializeU16",1),h([f(0,x)],l.prototype,"serializeU32",1),h([f(BigInt(0),S)],l.prototype,"serializeU64",1),h([f(BigInt(0),b)],l.prototype,"serializeU128",1),h([f(BigInt(0),v)],l.prototype,"serializeU256",1),h([f(0,x)],l.prototype,"serializeU32AsUleb128",1);function H(r){if(typeof r!="boolean")throw new Error(`${r} is not a boolean value`)}var D=(r,e,t)=>`${r} is out of range: [${e}, ${t}]`;function P(r,e,t){let n=BigInt(r);if(n>BigInt(t)||n<BigInt(e))throw new Error(D(r,e,t))}function f(r,e){return(t,n,s)=>{let i=s.value;return s.value=function(d){return P(d,r,e),i.apply(this,[d])},s}}var F=(s=>(s.JSON="application/json",s.BCS="application/x-bcs",s.BCS_SIGNED_TRANSACTION="application/x.aptos.signed_transaction+bcs",s.BCS_VIEW_FUNCTION="application/x.aptos.view_function+bcs",s))(F||{}),W= exports.r =(a=>(a[a.Bool=0]="Bool",a[a.U8=1]="U8",a[a.U64=2]="U64",a[a.U128=3]="U128",a[a.Address=4]="Address",a[a.Signer=5]="Signer",a[a.Vector=6]="Vector",a[a.Struct=7]="Struct",a[a.U16=8]="U16",a[a.U32=9]="U32",a[a.U256=10]="U256",a[a.Reference=254]="Reference",a[a.Generic=255]="Generic",a))(W||{}),I= exports.s =(p=>(p[p.U8=0]="U8",p[p.U64=1]="U64",p[p.U128=2]="U128",p[p.Address=3]="Address",p[p.U8Vector=4]="U8Vector",p[p.Bool=5]="Bool",p[p.U16=6]="U16",p[p.U32=7]="U32",p[p.U256=8]="U256",p[p.Serialized=9]="Serialized",p))(I||{}),z= exports.t =(s=>(s[s.Script=0]="Script",s[s.EntryFunction=2]="EntryFunction",s[s.Multisig=3]="Multisig",s[s.Payload=4]="Payload",s))(z||{}),G= exports.u =(e=>(e[e.V1=0]="V1",e))(G||{}),L= exports.v =(n=>(n[n.Script=0]="Script",n[n.EntryFunction=1]="EntryFunction",n[n.Empty=2]="Empty",n))(L||{}),$= exports.w =(e=>(e[e.V1=0]="V1",e))($||{}),q= exports.x =(t=>(t[t.MultiAgentTransaction=0]="MultiAgentTransaction",t[t.FeePayerTransaction=1]="FeePayerTransaction",t))(q||{}),X= exports.y =(i=>(i[i.Ed25519=0]="Ed25519",i[i.MultiEd25519=1]="MultiEd25519",i[i.MultiAgent=2]="MultiAgent",i[i.FeePayer=3]="FeePayer",i[i.SingleSender=4]="SingleSender",i))(X||{}),K= exports.z =(u=>(u[u.Ed25519=0]="Ed25519",u[u.MultiEd25519=1]="MultiEd25519",u[u.SingleKey=2]="SingleKey",u[u.MultiKey=3]="MultiKey",u[u.NoAccountAuthenticator=4]="NoAccountAuthenticator",u[u.Abstraction=5]="Abstraction",u))(K||{}),Y= exports.A =(t=>(t.Ed25519="ed25519",t.Secp256k1="secp256k1",t))(Y||{}),j= exports.B =(s=>(s[s.Ed25519=0]="Ed25519",s[s.Secp256k1=1]="Secp256k1",s[s.Keyless=3]="Keyless",s[s.FederatedKeyless=4]="FederatedKeyless",s))(j||{});function Re(r){switch(r){case 0:return"ed25519";case 1:return"secp256k1";case 3:return"keyless";case 4:return"federated_keyless";default:throw new Error("Unknown public key variant")}}var Z=(n=>(n[n.Ed25519=0]="Ed25519",n[n.Secp256k1=1]="Secp256k1",n[n.Keyless=3]="Keyless",n))(Z||{}),Q= exports.E =(e=>(e[e.Ed25519=0]="Ed25519",e))(Q||{}),J= exports.F =(e=>(e[e.Ed25519=0]="Ed25519",e))(J||{}),V= exports.G =(e=>(e[e.ZkProof=0]="ZkProof",e))(V||{}),ee= exports.H =(e=>(e[e.Groth16=0]="Groth16",e))(ee||{}),te= exports.I =(d=>(d.Pending="pending_transaction",d.User="user_transaction",d.Genesis="genesis_transaction",d.BlockMetadata="block_metadata_transaction",d.StateCheckpoint="state_checkpoint_transaction",d.Validator="validator_transaction",d.BlockEpilogue="block_epilogue_transaction",d))(te||{});function Ue(r){return r.type==="pending_transaction"}function ve(r){return r.type==="user_transaction"}function Ie(r){return r.type==="genesis_transaction"}function Me(r){return r.type==="block_metadata_transaction"}function Ee(r){return r.type==="state_checkpoint_transaction"}function Be(r){return r.type==="validator_transaction"}function Ne(r){return r.type==="block_epilogue_transaction"}function Ce(r){return"signature"in r&&r.type==="ed25519_signature"}function ke(r){return"signature"in r&&r.signature==="secp256k1_ecdsa_signature"}function we(r){return r.type==="multi_agent_signature"}function Oe(r){return r.type==="fee_payer_signature"}function He(r){return r.type==="multi_ed25519_signature"}function De(r){return r.type==="single_sender"}var re=(n=>(n.PRIVATE="private",n.PUBLIC="public",n.FRIEND="friend",n))(re||{}),ne= exports.X =(s=>(s.STORE="store",s.DROP="drop",s.KEY="key",s.COPY="copy",s))(ne||{}),se= exports.Y =(t=>(t.VALIDATOR="validator",t.FULL_NODE="full_node",t))(se||{}),ie= exports.Z =(s=>(s[s.Ed25519=0]="Ed25519",s[s.MultiEd25519=1]="MultiEd25519",s[s.SingleKey=2]="SingleKey",s[s.MultiKey=3]="MultiKey",s))(ie||{}),oe= exports._ =(t=>(t[t.Ed25519=0]="Ed25519",t[t.Secp256k1Ecdsa=2]="Secp256k1Ecdsa",t))(oe||{}),M= exports.$ =(i=>(i[i.DeriveAuid=251]="DeriveAuid",i[i.DeriveObjectAddressFromObject=252]="DeriveObjectAddressFromObject",i[i.DeriveObjectAddressFromGuid=253]="DeriveObjectAddressFromGuid",i[i.DeriveObjectAddressFromSeed=254]="DeriveObjectAddressFromSeed",i[i.DeriveResourceAccountAddress=255]="DeriveResourceAccountAddress",i))(M||{});var pe=(y=>(y.INCORRECT_NUMBER_OF_BYTES="incorrect_number_of_bytes",y.INVALID_HEX_CHARS="invalid_hex_chars",y.TOO_SHORT="too_short",y.TOO_LONG="too_long",y.LEADING_ZERO_X_REQUIRED="leading_zero_x_required",y.LONG_FORM_REQUIRED_UNLESS_SPECIAL="long_form_required_unless_special",y.INVALID_PADDING_ZEROES="INVALID_PADDING_ZEROES",y.INVALID_PADDING_STRICTNESS="INVALID_PADDING_STRICTNESS",y))(pe||{}),o=class o extends m{constructor(e){if(super(),e.length!==o.LENGTH)throw new c("AccountAddress data should be exactly 32 bytes long","incorrect_number_of_bytes");this.data=e}isSpecial(){return this.data.slice(0,this.data.length-1).every(e=>e===0)&&this.data[this.data.length-1]<16}toString(){return`0x${this.toStringWithoutPrefix()}`}toStringWithoutPrefix(){let e=_utils.bytesToHex.call(void 0, this.data);return this.isSpecial()&&(e=e[e.length-1]),e}toStringLong(){return`0x${this.toStringLongWithoutPrefix()}`}toStringLongWithoutPrefix(){return _utils.bytesToHex.call(void 0, this.data)}toStringShort(){return`0x${this.toStringShortWithoutPrefix()}`}toStringShortWithoutPrefix(){let e=_utils.bytesToHex.call(void 0, this.data).replace(/^0+/,"");return e===""?"0":e}toUint8Array(){return this.data}serialize(e){e.serializeFixedBytes(this.data)}serializeForEntryFunction(e){let t=this.bcsToBytes();e.serializeBytes(t)}serializeForScriptFunction(e){e.serializeU32AsUleb128(3),e.serialize(this)}static deserialize(e){let t=e.deserializeFixedBytes(o.LENGTH);return new o(t)}static fromStringStrict(e){if(!e.startsWith("0x"))throw new c("Hex string must start with a leading 0x.","leading_zero_x_required");let t=o.fromString(e);if(e.length!==o.LONG_STRING_LENGTH+2)if(t.isSpecial()){if(e.length!==3)throw new c(`The given hex string ${e} is a special address not in LONG form, it must be 0x0 to 0xf without padding zeroes.`,"INVALID_PADDING_ZEROES")}else throw new c(`The given hex string ${e} is not a special address, it must be represented as 0x + 64 chars.`,"long_form_required_unless_special");return t}static fromString(e,{maxMissingChars:t=4}={}){let n=e;if(e.startsWith("0x")&&(n=e.slice(2)),n.length===0)throw new c("Hex string is too short, must be 1 to 64 chars long, excluding the leading 0x.","too_short");if(n.length>64)throw new c("Hex string is too long, must be 1 to 64 chars long, excluding the leading 0x.","too_long");if(t>63||t<0)throw new c(`maxMissingChars must be between or equal to 0 and 63. Received ${t}`,"INVALID_PADDING_STRICTNESS");let s;try{s=_utils.hexToBytes.call(void 0, n.padStart(64,"0"))}catch(u){throw new c(`Hex characters are invalid: ${_optionalChain([u, 'optionalAccess', _5 => _5.message])}`,"invalid_hex_chars")}let i=new o(s);if(n.length<64-t&&!i.isSpecial())throw new c(`Hex string is too short, must be ${64-t} to 64 chars long, excluding the leading 0x. You may need to fix
|
|
2
|
-
the addresss by padding it with 0s before passing it to \`fromString\` (e.g. <addressString>.padStart(64, '0')).
|
|
3
|
-
Received ${e}`,"too_short");return i}static from(e,{maxMissingChars:t=4}={}){return typeof e=="string"?o.fromString(e,{maxMissingChars:t}):e instanceof Uint8Array?new o(e):e}static fromStrict(e){return typeof e=="string"?o.fromStringStrict(e):e instanceof Uint8Array?new o(e):e}static isValid(e){try{return e.strict?o.fromStrict(e.input):o.from(e.input),{valid:!0}}catch(t){return{valid:!1,invalidReason:_optionalChain([t, 'optionalAccess', _6 => _6.invalidReason]),invalidReasonMessage:_optionalChain([t, 'optionalAccess', _7 => _7.message])}}}equals(e){return this.data.length!==e.data.length?!1:this.data.every((t,n)=>t===e.data[n])}};o.LENGTH=32,o.LONG_STRING_LENGTH=64,o.ZERO=o.from("0x0"),o.ONE=o.from("0x1"),o.TWO=o.from("0x2"),o.THREE=o.from("0x3"),o.FOUR=o.from("0x4"),o.A=o.from("0xA");var g=o;var _sha3 = require('@noble/hashes/sha3');var T=(r,e)=>{let t=r.bcsToBytes(),n=typeof e=="string"?Buffer.from(e,"utf8"):e,s=new Uint8Array([...t,...n,254]);return new g(_sha3.sha3_256.call(void 0, s))},Ve= exports.da =(r,e)=>{let t=r.bcsToBytes(),n=typeof e=="string"?Buffer.from(e,"utf8"):e,s=new Uint8Array([...t,...n,255]);return new g(_sha3.sha3_256.call(void 0, s))},et= exports.ea =(r,e,t)=>{let n=`${e}::${t}`;return T(r,n)};var _jsbase64 = require('js-base64');async function it(r){return new Promise(e=>{setTimeout(e,r)})}function ot(r){return r instanceof Error?r.message:String(r)}var at=()=>Math.floor(Date.now()/1e3);function pt(r){let e=new Date(r*1e3);return e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),Math.floor(e.getTime()/1e3)}function ut(r){let e=r.replace(/-/g,"+").replace(/_/g,"/"),t=e+"==".substring(0,(3-e.length%3)%3);return _jsbase64.decode.call(void 0, t)}function ct(r){let e=r.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4!==0;)e+="=";return new Uint8Array(Buffer.from(e,"base64"))}var gt=(r,e)=>r*10**e,dt= exports.ma =(r,e)=>r/10**e,B=r=>{let e="";for(let t=2;t<r.length;t+=2)e+=String.fromCharCode(parseInt(r.substring(t,t+2),16));return e},lt= exports.na =r=>{let{account_address:e,module_name:t,struct_name:n}=r,s=B(t),i=B(n);return`${e}::${s}::${i}`},yt= exports.oa =r=>typeof r=="object"&&!Array.isArray(r)&&r!==null&&"account_address"in r&&"module_name"in r&&"struct_name"in r&&typeof r.account_address=="string"&&typeof r.module_name=="string"&&typeof r.struct_name=="string";function ht(r){let e=r.split("::");if(e.length!==3)throw new Error(`Invalid function ${r}`);let t=e[0],n=e[1],s=e[2];return{moduleAddress:t,moduleName:n,functionName:s}}function ft(r){let e=r.split("::");return e.length===3&&g.isValid({input:e[0]}).valid}function _t(r,e=6,t=5){return`${r.slice(0,e)}...${r.slice(-t)}`}var ce="0x1::aptos_coin::AptosCoin",xt=g.A.toStringLong();function ge(r){let e=/0x[0-9a-fA-F]+/g;return r.replace(e,t=>g.from(t,{maxMissingChars:63}).toStringShort())}function mt(r){let e=ge(r);return e===ce?g.A:T(g.A,e)}exports.a = h; exports.b = R; exports.c = U; exports.d = x; exports.e = S; exports.f = b; exports.g = v; exports.h = c; exports.i = O; exports.j = _; exports.k = _e; exports.l = m; exports.m = l; exports.n = H; exports.o = D; exports.p = P; exports.q = F; exports.r = W; exports.s = I; exports.t = z; exports.u = G; exports.v = L; exports.w = $; exports.x = q; exports.y = X; exports.z = K; exports.A = Y; exports.B = j; exports.C = Re; exports.D = Z; exports.E = Q; exports.F = J; exports.G = V; exports.H = ee; exports.I = te; exports.J = Ue; exports.K = ve; exports.L = Ie; exports.M = Me; exports.N = Ee; exports.O = Be; exports.P = Ne; exports.Q = Ce; exports.R = ke; exports.S = we; exports.T = Oe; exports.U = He; exports.V = De; exports.W = re; exports.X = ne; exports.Y = se; exports.Z = ie; exports._ = oe; exports.$ = M; exports.aa = pe; exports.ba = g; exports.ca = T; exports.da = Ve; exports.ea = et; exports.fa = it; exports.ga = ot; exports.ha = at; exports.ia = pt; exports.ja = ut; exports.ka = ct; exports.la = gt; exports.ma = dt; exports.na = lt; exports.oa = yt; exports.pa = ht; exports.qa = ft; exports.ra = _t; exports.sa = mt;
|
|
4
|
-
//# sourceMappingURL=chunk-6MMUUJHX.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/reneetso/aptos-ts-sdk/dist/common/chunk-6MMUUJHX.js","../../src/core/common.ts","../../src/core/hex.ts","../../src/core/accountAddress.ts"],"names":["ParsingError","message","invalidReason","HexInvalidReason","Hex","_Hex","data","bytesToHex"],"mappings":"AAAA,ilBAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CCQhM,IAAMA,CAAAA,CAAN,MAAA,QAA8B,KAAM,CAkBzC,WAAA,CAAYC,CAAAA,CAAiBC,CAAAA,CAAkB,CAC7C,KAAA,CAAMD,CAAO,CAAA,CACb,IAAA,CAAK,aAAA,CAAgBC,CACvB,CACF,CAAA,CC3BA,4CAAuC,IAS3BC,CAAAA,CAAAA,CAAAA,CAAAA,EAAAA,CACVA,CAAAA,CAAA,SAAA,CAAY,WAAA,CACZA,CAAAA,CAAA,cAAA,CAAiB,gBAAA,CACjBA,CAAAA,CAAA,iBAAA,CAAoB,mBAAA,CAHVA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,EAAA,CAAA,CAAA,CAAA,CAgCCC,CAAAA,aAAN,MAAMC,CAAI,CAUf,WAAA,CAAYC,CAAAA,CAAkB,CAC5B,IAAA,CAAK,IAAA,CAAOA,CACd,CAaA,YAAA,CAAA,CAA2B,CACzB,OAAO,IAAA,CAAK,IACd,CASA,qBAAA,CAAA,CAAgC,CAC9B,OAAOC,+BAAAA,IAAW,CAAK,IAAI,CAC7B,CASA,QAAA,CAAA,CAAmB,CACjB,MAAO,CAAA,EAAA,EAAK,IAAA,CAAK,qBAAA,CAAsB,CAAC,CAAA,CAAA;ACkVsB;AAnWV,SAAA","file":"/Users/reneetso/aptos-ts-sdk/dist/common/chunk-6MMUUJHX.js","sourcesContent":[null,"// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * This error is used to explain why parsing failed.\n * @group Implementation\n * @category Serialization\n */\nexport class ParsingError<T> extends Error {\n /**\n * This provides a programmatic way to access why parsing failed. Downstream devs\n * might want to use this to build their own error messages if the default error\n * messages are not suitable for their use case. This should be an enum.\n * @group Implementation\n * @category Serialization\n */\n public invalidReason: T;\n\n /**\n * Creates an instance of the error with a specified message and invalid reason.\n *\n * @param message The error message that describes the issue.\n * @param invalidReason The reason why the input is considered invalid.\n * @group Implementation\n * @category Serialization\n */\n constructor(message: string, invalidReason: T) {\n super(message);\n this.invalidReason = invalidReason;\n }\n}\n\n/**\n * Whereas ParsingError is thrown when parsing fails, e.g. in a fromString function,\n * this type is returned from \"defensive\" functions like isValid.\n * @group Implementation\n * @category Serialization\n */\nexport type ParsingResult<T> = {\n /**\n * True if valid, false otherwise.\n * @group Implementation\n * @category Serialization\n */\n valid: boolean;\n\n /**\n * If valid is false, this will be a code explaining why parsing failed.\n * @group Implementation\n * @category Serialization\n */\n invalidReason?: T;\n\n /**\n * If valid is false, this will be a string explaining why parsing failed.\n * @group Implementation\n * @category Serialization\n */\n invalidReasonMessage?: string;\n};\n","// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bytesToHex, hexToBytes } from \"@noble/hashes/utils\";\nimport { ParsingError, ParsingResult } from \"./common\";\nimport { HexInput } from \"../types\";\n\n/**\n * Provides reasons for parsing failures related to hexadecimal values.\n * @group Implementation\n * @category Serialization\n */\nexport enum HexInvalidReason {\n TOO_SHORT = \"too_short\",\n INVALID_LENGTH = \"invalid_length\",\n INVALID_HEX_CHARS = \"invalid_hex_chars\",\n}\n\n/**\n * NOTE: Do not use this class when working with account addresses; use AccountAddress instead.\n * When accepting hex data as input to a function, prefer to accept HexInput and\n *\n * A helper class for working with hex data. Hex data, when represented as a string,\n * generally looks like this, for example: 0xaabbcc, 45cd32, etc.\n *\n * then use the static helper methods of this class to convert it into the desired\n * format. This enables the greatest flexibility for the developer.\n *\n * Example usage:\n * ```typescript\n * getTransactionByHash(txnHash: HexInput): Promise<Transaction> {\n * const txnHashString = Hex.fromHexInput(txnHash).toString();\n * return await getTransactionByHashInner(txnHashString);\n * }\n * ```\n * This call to `Hex.fromHexInput().toString()` converts the HexInput to a hex string\n * with a leading 0x prefix, regardless of what the input format was.\n *\n * Other ways to chain the functions together:\n * - `Hex.fromHexString({ hexInput: \"0x1f\" }).toUint8Array()`\n * - `new Hex([1, 3]).toStringWithoutPrefix()`\n * @group Implementation\n * @category Serialization\n */\nexport class Hex {\n private readonly data: Uint8Array;\n\n /**\n * Create a new Hex instance from a Uint8Array.\n *\n * @param data - The Uint8Array containing the data to initialize the Hex instance.\n * @group Implementation\n * @category Serialization\n */\n constructor(data: Uint8Array) {\n this.data = data;\n }\n\n // ===\n // Methods for representing an instance of Hex as other types.\n // ===\n\n /**\n * Get the inner hex data as a Uint8Array. The inner data is already a Uint8Array, so no conversion takes place.\n *\n * @returns Hex data as Uint8Array\n * @group Implementation\n * @category Serialization\n */\n toUint8Array(): Uint8Array {\n return this.data;\n }\n\n /**\n * Get the hex data as a string without the 0x prefix.\n *\n * @returns Hex string without 0x prefix\n * @group Implementation\n * @category Serialization\n */\n toStringWithoutPrefix(): string {\n return bytesToHex(this.data);\n }\n\n /**\n * Get the hex data as a string with the 0x prefix.\n *\n * @returns Hex string with 0x prefix\n * @group Implementation\n * @category Serialization\n */\n toString(): string {\n return `0x${this.toStringWithoutPrefix()}`;\n }\n\n // ===\n // Methods for creating an instance of Hex from other types.\n // ===\n\n /**\n * Converts a hex string into a Hex instance, allowing for both prefixed and non-prefixed formats.\n *\n * @param str - A hex string, with or without the 0x prefix.\n *\n * @throws ParsingError - If the hex string is too short, has an odd number of characters, or contains invalid hex characters.\n *\n * @returns Hex - The resulting Hex instance created from the provided string.\n * @group Implementation\n * @category Serialization\n */\n static fromHexString(str: string): Hex {\n let input = str;\n\n if (input.startsWith(\"0x\")) {\n input = input.slice(2);\n }\n\n if (input.length === 0) {\n throw new ParsingError(\n \"Hex string is too short, must be at least 1 char long, excluding the optional leading 0x.\",\n HexInvalidReason.TOO_SHORT,\n );\n }\n\n if (input.length % 2 !== 0) {\n throw new ParsingError(\"Hex string must be an even number of hex characters.\", HexInvalidReason.INVALID_LENGTH);\n }\n\n try {\n return new Hex(hexToBytes(input));\n } catch (error: any) {\n throw new ParsingError(\n `Hex string contains invalid hex characters: ${error?.message}`,\n HexInvalidReason.INVALID_HEX_CHARS,\n );\n }\n }\n\n /**\n * Converts an instance of HexInput, which can be a string or a Uint8Array, into a Hex instance.\n * This function is useful for transforming hexadecimal representations into a structured Hex object for further manipulation.\n *\n * @param hexInput - A HexInput which can be a string or Uint8Array.\n * @returns A Hex instance created from the provided hexInput.\n * @group Implementation\n * @category Serialization\n */\n static fromHexInput(hexInput: HexInput): Hex {\n if (hexInput instanceof Uint8Array) return new Hex(hexInput);\n return Hex.fromHexString(hexInput);\n }\n\n /**\n * Converts an instance of HexInput, which can be a string or a Uint8Array, into a Uint8Array.\n *\n * @param hexInput - A HexInput which can be a string or Uint8Array.\n * @returns A Uint8Array created from the provided hexInput.\n */\n static hexInputToUint8Array(hexInput: HexInput): Uint8Array {\n if (hexInput instanceof Uint8Array) return hexInput;\n return Hex.fromHexString(hexInput).toUint8Array();\n }\n\n /**\n * Converts a HexInput (string or Uint8Array) to a hex string with '0x' prefix.\n *\n * @param hexInput - The input to convert, either a hex string (with/without '0x' prefix) or Uint8Array\n * @returns A hex string with '0x' prefix (e.g., \"0x1234\")\n *\n * @example\n * ```typescript\n * Hex.hexInputToString(\"1234\") // returns \"0x1234\"\n * Hex.hexInputToString(\"0x1234\") // returns \"0x1234\"\n * Hex.hexInputToString(new Uint8Array([0x12, 0x34])) // returns \"0x1234\"\n * ```\n */\n static hexInputToString(hexInput: HexInput): string {\n return Hex.fromHexInput(hexInput).toString();\n }\n\n /**\n * Converts a HexInput (string or Uint8Array) to a hex string without '0x' prefix.\n *\n * @param hexInput - The input to convert, either a hex string (with/without '0x' prefix) or Uint8Array\n * @returns A hex string without '0x' prefix (e.g., \"1234\")\n *\n * @example\n * ```typescript\n * Hex.hexInputToStringWithoutPrefix(\"1234\") // returns \"1234\"\n * Hex.hexInputToStringWithoutPrefix(\"0x1234\") // returns \"1234\"\n * Hex.hexInputToStringWithoutPrefix(new Uint8Array([0x12, 0x34])) // returns \"1234\"\n * ```\n */\n static hexInputToStringWithoutPrefix(hexInput: HexInput): string {\n return Hex.fromHexInput(hexInput).toStringWithoutPrefix();\n }\n\n // ===\n // Methods for checking validity.\n // ===\n\n /**\n * Check if the provided string is a valid hexadecimal representation.\n *\n * @param str - A hex string representing byte data.\n *\n * @returns An object containing:\n * - valid: A boolean indicating whether the string is valid.\n * - invalidReason: The reason for invalidity if the string is not valid.\n * - invalidReasonMessage: A message explaining why the string is invalid.\n * @group Implementation\n * @category Serialization\n */\n static isValid(str: string): ParsingResult<HexInvalidReason> {\n try {\n Hex.fromHexString(str);\n return { valid: true };\n } catch (error: any) {\n return {\n valid: false,\n invalidReason: error?.invalidReason,\n invalidReasonMessage: error?.message,\n };\n }\n }\n\n /**\n * Determine if two Hex instances are equal by comparing their underlying byte data.\n *\n * @param other The Hex instance to compare to.\n * @returns true if the Hex instances are equal, false if not.\n * @group Implementation\n * @category Serialization\n */\n equals(other: Hex): boolean {\n if (this.data.length !== other.data.length) return false;\n return this.data.every((value, index) => value === other.data[index]);\n }\n}\n\nexport const hexToAsciiString = (hex: string) => new TextDecoder().decode(Hex.fromHexInput(hex).toUint8Array());\n","// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bytesToHex, hexToBytes } from \"@noble/hashes/utils\";\nimport { Serializable, Serializer } from \"../bcs/serializer\";\nimport { Deserializer } from \"../bcs/deserializer\";\nimport { ParsingError, ParsingResult } from \"./common\";\nimport { TransactionArgument } from \"../transactions/instances/transactionArgument\";\nimport { HexInput, ScriptTransactionArgumentVariants } from \"../types\";\n\n/**\n * Provides reasons for an address was invalid.\n * @group Implementation\n * @category Serialization\n */\nexport enum AddressInvalidReason {\n INCORRECT_NUMBER_OF_BYTES = \"incorrect_number_of_bytes\",\n INVALID_HEX_CHARS = \"invalid_hex_chars\",\n TOO_SHORT = \"too_short\",\n TOO_LONG = \"too_long\",\n LEADING_ZERO_X_REQUIRED = \"leading_zero_x_required\",\n LONG_FORM_REQUIRED_UNLESS_SPECIAL = \"long_form_required_unless_special\",\n INVALID_PADDING_ZEROES = \"INVALID_PADDING_ZEROES\",\n INVALID_PADDING_STRICTNESS = \"INVALID_PADDING_STRICTNESS\",\n}\n\n/**\n * The input for an account address, which can be either a hexadecimal string or a standard account address.\n * @group Implementation\n * @category Serialization\n */\nexport type AccountAddressInput = HexInput | AccountAddress;\n\n/**\n * NOTE: Only use this class for account addresses. For other hex data, e.g. transaction\n * hashes, use the Hex class.\n *\n * AccountAddress is used for working with account addresses. Account addresses, when\n * represented as a string, generally look like these examples:\n * - 0x1\n * - 0xaa86fe99004361f747f91342ca13c426ca0cccb0c1217677180c9493bad6ef0c\n *\n * Proper formatting and parsing of account addresses is defined by AIP-40.\n * To learn more about the standard, read the AIP here:\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * The comments in this class make frequent reference to the LONG and SHORT formats,\n * as well as \"special\" addresses. To learn what these refer to see AIP-40.\n * @group Implementation\n * @category Serialization\n */\nexport class AccountAddress extends Serializable implements TransactionArgument {\n /**\n * This is the internal representation of an account address.\n * @group Implementation\n * @category Serialization\n */\n readonly data: Uint8Array;\n\n /**\n * The number of bytes that make up an account address.\n * @group Implementation\n * @category Serialization\n */\n static readonly LENGTH: number = 32;\n\n /**\n * The length of an address string in LONG form without a leading 0x.\n * @group Implementation\n * @category Serialization\n */\n static readonly LONG_STRING_LENGTH: number = 64;\n\n static ZERO: AccountAddress = AccountAddress.from(\"0x0\");\n\n static ONE: AccountAddress = AccountAddress.from(\"0x1\");\n\n static TWO: AccountAddress = AccountAddress.from(\"0x2\");\n\n static THREE: AccountAddress = AccountAddress.from(\"0x3\");\n\n static FOUR: AccountAddress = AccountAddress.from(\"0x4\");\n\n static A: AccountAddress = AccountAddress.from(\"0xA\");\n\n /**\n * Creates an instance of AccountAddress from a Uint8Array.\n *\n * This function ensures that the input data is exactly 32 bytes long, which is required for a valid account address.\n *\n * @param input A Uint8Array representing an account address.\n * @throws ParsingError if the input length is not equal to 32 bytes.\n * @group Implementation\n * @category Serialization\n */\n constructor(input: Uint8Array) {\n super();\n if (input.length !== AccountAddress.LENGTH) {\n throw new ParsingError(\n \"AccountAddress data should be exactly 32 bytes long\",\n AddressInvalidReason.INCORRECT_NUMBER_OF_BYTES,\n );\n }\n this.data = input;\n }\n\n /**\n * Determines if the address is classified as special, which is defined as 0x0 to 0xf inclusive.\n * In other words, the last byte of the address must be < 0b10000 (16)\n * and every other byte must be zero.\n *\n * For more information on how special addresses are defined, see AIP-40:\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * @returns true if the address is special, false otherwise.\n * @group Implementation\n * @category Serialization\n */\n isSpecial(): boolean {\n return (\n this.data.slice(0, this.data.length - 1).every((byte) => byte === 0) && this.data[this.data.length - 1] < 0b10000\n );\n }\n // ===\n // Methods for representing an instance of AccountAddress as other types.\n // ===\n\n /**\n * Return the AccountAddress as a string as per AIP-40.\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n * This representation returns special addresses in SHORT form (0xf)\n * and other addresses in LONG form (0x + 64 characters).\n *\n * @returns AccountAddress as a string conforming to AIP-40.\n * @group Implementation\n * @category Serialization\n */\n toString(): `0x${string}` {\n return `0x${this.toStringWithoutPrefix()}`;\n }\n\n /**\n * Return the AccountAddress as a string conforming to AIP-40 but without the leading 0x.\n *\n * NOTE: Prefer to use `toString` where possible.\n *\n * @returns AccountAddress as a string without the leading 0x.\n * @group Implementation\n * @category Serialization\n */\n toStringWithoutPrefix(): string {\n let hex = bytesToHex(this.data);\n if (this.isSpecial()) {\n hex = hex[hex.length - 1];\n }\n return hex;\n }\n\n /**\n * Convert the account address to a string in LONG format, which is always 0x followed by 64 hex characters.\n *\n * NOTE: Prefer to use `toString` where possible, as it formats special addresses using the SHORT form (no leading 0s).\n *\n * @returns AccountAddress as a string in LONG form.\n * @group Implementation\n * @category Serialization\n */\n toStringLong(): `0x${string}` {\n return `0x${this.toStringLongWithoutPrefix()}`;\n }\n\n /**\n * Returns the account address as a string in LONG form without a leading 0x.\n * This function will include leading zeroes and will produce a string of 64 hex characters.\n *\n * NOTE: Prefer to use `toString` where possible, as it formats special addresses using the SHORT form (no leading 0s).\n *\n * @returns {string} The account address in LONG form.\n * @group Implementation\n * @category Serialization\n */\n toStringLongWithoutPrefix(): string {\n return bytesToHex(this.data);\n }\n\n /**\n * Convert the account address to a string in SHORT format, which is 0x followed by the shortest\n * possible representation (no leading zeros).\n *\n * @returns AccountAddress as a string in SHORT form.\n * @group Implementation\n * @category Serialization\n */\n toStringShort(): `0x${string}` {\n return `0x${this.toStringShortWithoutPrefix()}`;\n }\n\n /**\n * Returns a lossless short string representation of the address by trimming leading zeros.\n * If the address consists of all zeros, returns \"0\".\n *\n * @returns A string representation of the address without leading zeros\n * @group Implementation\n * @category Serialization\n */\n toStringShortWithoutPrefix(): string {\n const hex = bytesToHex(this.data).replace(/^0+/, \"\");\n return hex === \"\" ? \"0\" : hex;\n }\n\n /**\n * Get the inner data as a Uint8Array.\n * The inner data is already a Uint8Array, so no conversion takes place.\n *\n * @returns Hex data as Uint8Array\n * @group Implementation\n * @category Serialization\n */\n toUint8Array(): Uint8Array {\n return this.data;\n }\n\n /**\n * Serialize the AccountAddress to a Serializer instance's data buffer.\n * @param serializer The serializer to serialize the AccountAddress to.\n * @returns void\n * @example\n * const serializer = new Serializer();\n * const address = AccountAddress.fromString(\"0x1\");\n * address.serialize(serializer);\n * const bytes = serializer.toUint8Array();\n * // `bytes` is now the BCS-serialized address.\n * @group Implementation\n * @category Serialization\n */\n serialize(serializer: Serializer): void {\n serializer.serializeFixedBytes(this.data);\n }\n\n /**\n * Serializes the current instance into a byte sequence suitable for entry functions.\n * This allows for the proper encoding of data when interacting with entry functions in the blockchain.\n *\n * @param serializer - The serializer instance used to convert the data into bytes.\n * @group Implementation\n * @category Serialization\n */\n serializeForEntryFunction(serializer: Serializer): void {\n const bcsBytes = this.bcsToBytes();\n serializer.serializeBytes(bcsBytes);\n }\n\n /**\n * Serializes the current instance for use in a script function by encoding it into a byte sequence.\n * This process involves serializing the variant index and the instance data, making it suitable for transmission.\n *\n * @param serializer - The serializer instance used to perform the serialization.\n * @group Implementation\n * @category Serialization\n */\n serializeForScriptFunction(serializer: Serializer): void {\n serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.Address);\n serializer.serialize(this);\n }\n\n /**\n * Deserialize an AccountAddress from the byte buffer in a Deserializer instance.\n * This function allows you to convert a byte representation of an AccountAddress into an instance of AccountAddress.\n * @param deserializer The deserializer to deserialize the AccountAddress from.\n * @returns An instance of AccountAddress.\n * @example\n * const bytes = hexToBytes(\"0x0102030405060708091011121314151617181920212223242526272829303132\");\n * const deserializer = new Deserializer(bytes);\n * const address = AccountAddress.deserialize(deserializer);\n * // `address` is now an instance of AccountAddress.\n * @group Implementation\n * @category Serialization\n */\n static deserialize(deserializer: Deserializer): AccountAddress {\n const bytes = deserializer.deserializeFixedBytes(AccountAddress.LENGTH);\n return new AccountAddress(bytes);\n }\n\n // ===\n // Methods for creating an instance of AccountAddress from other types.\n // ===\n\n /**\n * NOTE: This function has strict parsing behavior. For relaxed behavior, please use\n * the `fromString` function.\n *\n * Creates an instance of AccountAddress from a hex string.\n *\n * This function allows only the strictest formats defined by AIP-40. In short this\n * means only the following formats are accepted:\n *\n * - LONG\n * - SHORT for special addresses\n *\n * Where:\n * - LONG is defined as 0x + 64 hex characters.\n * - SHORT for special addresses is 0x0 to 0xf inclusive without padding zeroes.\n *\n * This means the following are not accepted:\n * - SHORT for non-special addresses.\n * - Any address without a leading 0x.\n *\n * @param input - A hex string representing an account address.\n *\n * @throws {ParsingError} If the hex string does not start with 0x or is not in a valid format.\n *\n * @remarks\n *\n * This function has strict parsing behavior. For relaxed behavior, please use the `fromString` function.\n *\n * @see AIP-40 documentation for more details on address formats:\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * @returns An instance of AccountAddress.\n * @group Implementation\n * @category Serialization\n */\n static fromStringStrict(input: string): AccountAddress {\n // Assert the string starts with 0x.\n if (!input.startsWith(\"0x\")) {\n throw new ParsingError(\"Hex string must start with a leading 0x.\", AddressInvalidReason.LEADING_ZERO_X_REQUIRED);\n }\n\n const address = AccountAddress.fromString(input);\n\n // Check if the address is in LONG form. If it is not, this is only allowed for\n // special addresses, in which case we check it is in proper SHORT form.\n if (input.length !== AccountAddress.LONG_STRING_LENGTH + 2) {\n if (!address.isSpecial()) {\n throw new ParsingError(\n `The given hex string ${input} is not a special address, it must be represented as 0x + 64 chars.`,\n AddressInvalidReason.LONG_FORM_REQUIRED_UNLESS_SPECIAL,\n );\n } else if (input.length !== 3) {\n // 0x + one hex char is the only valid SHORT form for special addresses.\n throw new ParsingError(\n // eslint-disable-next-line max-len\n `The given hex string ${input} is a special address not in LONG form, it must be 0x0 to 0xf without padding zeroes.`,\n AddressInvalidReason.INVALID_PADDING_ZEROES,\n );\n }\n }\n\n return address;\n }\n\n /**\n * NOTE: This function has relaxed parsing behavior. For strict behavior, please use\n * the `fromStringStrict` function. Where possible use `fromStringStrict` rather than this\n * function, `fromString`.\n *\n * Creates an instance of AccountAddress from a hex string.\n *\n * This function allows all formats defined by AIP-40. In short this means the\n * following formats are accepted:\n *\n * - LONG, with or without leading 0x\n * - SHORT*, with or without leading 0x\n *\n * Where:\n * - LONG is 64 hex characters.\n * - SHORT* is 1 to 63 hex characters inclusive. The address can have missing values up to `maxMissingChars` before it is padded.\n * - Padding zeroes are allowed, e.g. 0x0123 is valid.\n *\n * Learn more about the different address formats by reading AIP-40:\n * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.\n *\n * @param input A hex string representing an account address.\n * @param args.maxMissingChars The number of characters that can be missing in a padded address before it is invalid.\n *\n * @returns An instance of AccountAddress.\n *\n * @throws ParsingError if the hex string is too short, too long, or contains invalid characters.\n * @group Implementation\n * @category Serialization\n */\n static fromString(input: string, { maxMissingChars = 4 }: { maxMissingChars?: number } = {}): AccountAddress {\n let parsedInput = input;\n // Remove leading 0x for parsing.\n if (input.startsWith(\"0x\")) {\n parsedInput = input.slice(2);\n }\n\n // Ensure the address string is at least 1 character long.\n if (parsedInput.length === 0) {\n throw new ParsingError(\n \"Hex string is too short, must be 1 to 64 chars long, excluding the leading 0x.\",\n AddressInvalidReason.TOO_SHORT,\n );\n }\n\n // Ensure the address string is not longer than 64 characters.\n if (parsedInput.length > 64) {\n throw new ParsingError(\n \"Hex string is too long, must be 1 to 64 chars long, excluding the leading 0x.\",\n AddressInvalidReason.TOO_LONG,\n );\n }\n\n // Ensure that the maxMissingChars is between or equal to 0 and 63.\n if (maxMissingChars > 63 || maxMissingChars < 0) {\n throw new ParsingError(\n `maxMissingChars must be between or equal to 0 and 63. Received ${maxMissingChars}`,\n AddressInvalidReason.INVALID_PADDING_STRICTNESS,\n );\n }\n\n let addressBytes: Uint8Array;\n try {\n // Pad the address with leading zeroes, so it is 64 chars long and then convert\n // the hex string to bytes. Every two characters in a hex string constitutes a\n // single byte. So a 64 length hex string becomes a 32 byte array.\n addressBytes = hexToBytes(parsedInput.padStart(64, \"0\"));\n } catch (error: any) {\n // At this point the only way this can fail is if the hex string contains\n // invalid characters.\n throw new ParsingError(`Hex characters are invalid: ${error?.message}`, AddressInvalidReason.INVALID_HEX_CHARS);\n }\n\n const address = new AccountAddress(addressBytes);\n\n // Cannot pad the address if it has more than maxMissingChars missing.\n if (parsedInput.length < 64 - maxMissingChars) {\n if (!address.isSpecial()) {\n throw new ParsingError(\n `Hex string is too short, must be ${64 - maxMissingChars} to 64 chars long, excluding the leading 0x. You may need to fix \nthe addresss by padding it with 0s before passing it to \\`fromString\\` (e.g. <addressString>.padStart(64, '0')). \nReceived ${input}`,\n AddressInvalidReason.TOO_SHORT,\n );\n }\n }\n\n return address;\n }\n\n /**\n * Convenience method for creating an AccountAddress from various input types.\n * This function accepts a string, Uint8Array, or an existing AccountAddress instance and returns the corresponding\n * AccountAddress.\n *\n * @param input - The input to convert into an AccountAddress. This can be a string representation of an address, a Uint8Array,\n * or an existing AccountAddress.\n * @param args.maxMissingChars The number of characters that can be missing in a padded address before it is invalid.\n * @group Implementation\n * @category Serialization\n */\n static from(input: AccountAddressInput, { maxMissingChars = 4 }: { maxMissingChars?: number } = {}): AccountAddress {\n if (typeof input === \"string\") {\n return AccountAddress.fromString(input, { maxMissingChars });\n }\n if (input instanceof Uint8Array) {\n return new AccountAddress(input);\n }\n return input;\n }\n\n /**\n * Create an AccountAddress from various input types, including strings, Uint8Array, and AccountAddress instances.\n *\n * @param input - The input to convert into an AccountAddress, which can be a string, a Uint8Array, or an AccountAddress.\n * @group Implementation\n * @category Serialization\n */\n static fromStrict(input: AccountAddressInput): AccountAddress {\n if (typeof input === \"string\") {\n return AccountAddress.fromStringStrict(input);\n }\n if (input instanceof Uint8Array) {\n return new AccountAddress(input);\n }\n return input;\n }\n // ===\n // Methods for checking validity.\n // ===\n\n /**\n * Check if the provided input is a valid AccountAddress.\n *\n * @param args - The arguments for validation.\n * @param args.input - A hex string representing an account address.\n * @param args.strict - If true, use strict parsing behavior; if false, use relaxed parsing behavior.\n *\n * @returns An object indicating whether the address is valid. If valid, valid = true; if not, valid = false with additional details.\n * If the address is invalid, invalidReason will explain why it is invalid, and invalidReasonMessage will provide the error message.\n * @group Implementation\n * @category Serialization\n */\n static isValid(args: { input: AccountAddressInput; strict?: boolean }): ParsingResult<AddressInvalidReason> {\n try {\n if (args.strict) {\n AccountAddress.fromStrict(args.input);\n } else {\n AccountAddress.from(args.input);\n }\n return { valid: true };\n } catch (error: any) {\n return {\n valid: false,\n invalidReason: error?.invalidReason,\n invalidReasonMessage: error?.message,\n };\n }\n }\n\n /**\n * Determine if two AccountAddresses are equal based on their underlying byte data.\n *\n * @param other - The AccountAddress to compare to.\n * @returns true if the AccountAddresses are equal, false if not.\n * @group Implementation\n * @category Serialization\n */\n equals(other: AccountAddress): boolean {\n if (this.data.length !== other.data.length) return false;\n return this.data.every((value, index) => value === other.data[index]);\n }\n}\n"]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as p}from"./chunk-DPW6ELCQ.mjs";import{a as u}from"./chunk-ROT6S6BM.mjs";import{a as h}from"./chunk-WCMW2L3P.mjs";import{a as f}from"./chunk-WSR5EBJM.mjs";import{e as d,j as S}from"./chunk-C3Q23D22.mjs";import{a as g}from"./chunk-EBMEXURY.mjs";import{b as s}from"./chunk-STY74NUA.mjs";import{sha3_256 as H}from"@noble/hashes/sha3";import{secp256k1 as y}from"@noble/curves/secp256k1";import{HDKey as A}from"@scure/bip32";var i=class i extends f{constructor(e){super();let t=s.fromHexInput(e),{length:r}=t.toUint8Array();if(r===i.LENGTH)this.key=t;else if(r===i.COMPRESSED_LENGTH){let o=y.ProjectivePoint.fromHex(t.toUint8Array());this.key=s.fromHexInput(o.toRawBytes(!1))}else throw new Error(`PublicKey length should be ${i.LENGTH} or ${i.COMPRESSED_LENGTH}, received ${r}`)}verifySignature(e){let{message:t,signature:r}=e,o=p(t),c=s.fromHexInput(o).toUint8Array(),P=H(c),x=r.toUint8Array();return y.verify(x,P,this.key.toUint8Array(),{lowS:!0})}async verifySignatureAsync(e){return this.verifySignature(e)}toUint8Array(){return this.key.toUint8Array()}serialize(e){e.serializeBytes(this.key.toUint8Array())}deserialize(e){let t=e.deserializeBytes();return new l(t)}static deserialize(e){let t=e.deserializeBytes();return new i(t)}static isPublicKey(e){return e instanceof i}static isInstance(e){return"key"in e&&e.key?.data?.length===i.LENGTH}};i.LENGTH=65,i.COMPRESSED_LENGTH=33;var m=i,n=class n extends g{constructor(e,t){super();let r=u.parseHexInput(e,"secp256k1",t);if(r.toUint8Array().length!==n.LENGTH)throw new Error(`PrivateKey length should be ${n.LENGTH}`);this.key=r}static generate(){let e=y.utils.randomPrivateKey();return new n(e,!1)}static fromDerivationPath(e,t){if(!d(e))throw new Error(`Invalid derivation path ${e}`);return n.fromDerivationPathInner(e,S(t))}static fromDerivationPathInner(e,t){let{privateKey:r}=A.fromMasterSeed(t).derive(e);if(r===null)throw new Error("Invalid key");return new n(r,!1)}sign(e){let t=p(e),r=s.fromHexInput(t),o=H(r.toUint8Array()),c=y.sign(o,this.key.toUint8Array(),{lowS:!0});return new l(c.toCompactRawBytes())}publicKey(){let e=y.getPublicKey(this.key.toUint8Array(),!1);return new m(e)}toUint8Array(){return this.key.toUint8Array()}toString(){return this.toAIP80String()}toHexString(){return this.key.toString()}toAIP80String(){return u.formatPrivateKey(this.key.toString(),"secp256k1")}serialize(e){e.serializeBytes(this.toUint8Array())}static deserialize(e){let t=e.deserializeBytes();return new n(t,!1)}static isPrivateKey(e){return e instanceof n}};n.LENGTH=32;var v=n,a=class a extends h{constructor(e){super();let t=s.fromHexInput(e);if(t.toUint8Array().length!==a.LENGTH)throw new Error(`Signature length should be ${a.LENGTH}, received ${t.toUint8Array().length}`);this.data=t}toUint8Array(){return this.data.toUint8Array()}serialize(e){e.serializeBytes(this.data.toUint8Array())}static deserialize(e){let t=e.deserializeBytes();return new a(t)}};a.LENGTH=64;var l=a;export{m as a,v as b,l as c};
|
|
2
|
-
//# sourceMappingURL=chunk-4JT5AESZ.mjs.map
|