@aptos-labs/ts-sdk 4.0.0 → 5.0.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-BDwBREvt.d.ts} +29 -3
- package/dist/common/chunk-6MMUUJHX.js.map +1 -1
- package/dist/common/cli/index.d.ts +1 -1
- package/dist/common/cli/index.js.map +1 -1
- package/dist/common/index.d.ts +55 -39
- package/dist/common/index.js +30 -32
- package/dist/common/index.js.map +1 -1
- package/dist/esm/{Ed25519Account-ndmdpFe9.d.mts → Ed25519Account-8ETkcAk_.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-ClxOwjdh.d.mts} +28 -3
- 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 +3 -6
- 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/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-5FI4545P.mjs +2 -0
- package/dist/esm/{chunk-6SLY7UV2.mjs.map → chunk-5FI4545P.mjs.map} +1 -1
- package/dist/esm/chunk-DIGP2ALY.mjs +4 -0
- package/dist/esm/chunk-DIGP2ALY.mjs.map +1 -0
- package/dist/esm/{chunk-BPWSOC2Y.mjs → chunk-DNRUDMMV.mjs} +2 -2
- package/dist/esm/{chunk-3BMZKCLH.mjs → chunk-EM52Z7T7.mjs} +2 -2
- package/dist/esm/{chunk-HZVN4JSO.mjs → chunk-ES2KP6BS.mjs} +2 -2
- package/dist/esm/{chunk-6JYQ5P36.mjs → chunk-GFFKEZ56.mjs} +2 -2
- package/dist/esm/{chunk-XYXBAU4J.mjs → chunk-GMQCQDW4.mjs} +2 -2
- package/dist/esm/{chunk-UQZTHVWC.mjs → chunk-HNBKTJPN.mjs} +2 -2
- package/dist/esm/{chunk-NF73V673.mjs → chunk-LWL57YFU.mjs} +2 -2
- package/dist/esm/{chunk-PLI53ZU6.mjs → chunk-N3O3ULF7.mjs} +2 -2
- 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-Y7ZQTLH4.mjs → chunk-RCSJFTST.mjs} +2 -2
- package/dist/esm/{chunk-EF4FA5I6.mjs → chunk-RQX6JOEN.mjs} +2 -2
- package/dist/esm/{chunk-V6C6NWFU.mjs → chunk-TGRLDWXV.mjs} +2 -2
- package/dist/esm/{chunk-2XQKGWHQ.mjs → chunk-V74WPKSY.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/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/utils/address.d.mts +1 -1
- package/dist/esm/core/account/utils/index.d.mts +1 -1
- package/dist/esm/core/accountAddress.d.mts +1 -1
- package/dist/esm/core/authenticationKey.d.mts +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 +2 -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/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/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 +2 -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-CUPEnP-W.d.mts} +1 -1
- package/dist/esm/index.d.mts +4 -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 +27 -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/types.d.mts +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/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 +26 -26
- package/src/account/AbstractedAccount.ts +16 -3
- package/src/account/DerivableAbstractedAccount.ts +3 -1
- package/src/api/account.ts +4 -16
- package/src/api/transaction.ts +59 -36
- package/src/core/crypto/utils.ts +38 -1
- package/src/internal/account.ts +36 -83
- package/src/transactions/authenticator/account.ts +71 -17
- package/src/types/abstraction.ts +9 -2
- package/src/utils/const.ts +2 -0
- package/src/version.ts +1 -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-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-BPWSOC2Y.mjs.map → chunk-DNRUDMMV.mjs.map} +0 -0
- /package/dist/esm/{chunk-3BMZKCLH.mjs.map → chunk-EM52Z7T7.mjs.map} +0 -0
- /package/dist/esm/{chunk-HZVN4JSO.mjs.map → chunk-ES2KP6BS.mjs.map} +0 -0
- /package/dist/esm/{chunk-6JYQ5P36.mjs.map → chunk-GFFKEZ56.mjs.map} +0 -0
- /package/dist/esm/{chunk-XYXBAU4J.mjs.map → chunk-GMQCQDW4.mjs.map} +0 -0
- /package/dist/esm/{chunk-UQZTHVWC.mjs.map → chunk-HNBKTJPN.mjs.map} +0 -0
- /package/dist/esm/{chunk-NF73V673.mjs.map → chunk-LWL57YFU.mjs.map} +0 -0
- /package/dist/esm/{chunk-PLI53ZU6.mjs.map → chunk-N3O3ULF7.mjs.map} +0 -0
- /package/dist/esm/{chunk-Y7ZQTLH4.mjs.map → chunk-RCSJFTST.mjs.map} +0 -0
- /package/dist/esm/{chunk-EF4FA5I6.mjs.map → chunk-RQX6JOEN.mjs.map} +0 -0
- /package/dist/esm/{chunk-V6C6NWFU.mjs.map → chunk-TGRLDWXV.mjs.map} +0 -0
- /package/dist/esm/{chunk-2XQKGWHQ.mjs.map → chunk-V74WPKSY.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.
|
|
@@ -933,23 +935,15 @@ const rotateAuthKeyAbi: EntryFunctionABI = {
|
|
|
933
935
|
* @param args - The arguments for rotating the authentication key.
|
|
934
936
|
* @param args.aptosConfig - The configuration settings for the Aptos network.
|
|
935
937
|
* @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.
|
|
938
|
+
* @param args.toAccount - (Optional) The target account to rotate to. Required if not using toNewPrivateKey.
|
|
939
|
+
* @param args.toNewPrivateKey - (Optional) The new private key to rotate to. Required if not using toAccount.
|
|
940
940
|
*
|
|
941
941
|
* @remarks
|
|
942
942
|
* This function supports three modes of rotation:
|
|
943
943
|
* 1. Using a target Account object (toAccount)
|
|
944
944
|
* 2. Using a new private key (toNewPrivateKey)
|
|
945
|
-
* 3. Using a raw authentication key (toAuthKey) - requires dangerouslySkipVerification=true
|
|
946
945
|
*
|
|
947
|
-
*
|
|
948
|
-
*
|
|
949
|
-
* If the new key is a multi key, skipping verification is dangerous because verification will publish the public key onchain and
|
|
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.
|
|
946
|
+
* @returns A simple transaction object that can be submitted to the network.
|
|
953
947
|
* @throws Error if the rotation fails or verification fails.
|
|
954
948
|
*
|
|
955
949
|
* @group Implementation
|
|
@@ -959,13 +953,9 @@ export async function rotateAuthKey(
|
|
|
959
953
|
aptosConfig: AptosConfig;
|
|
960
954
|
fromAccount: Account;
|
|
961
955
|
options?: InputGenerateTransactionOptions;
|
|
962
|
-
} & (
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
| { toAuthKey: AuthenticationKey; dangerouslySkipVerification: true }
|
|
966
|
-
),
|
|
967
|
-
): Promise<PendingTransactionResponse> {
|
|
968
|
-
const { aptosConfig, fromAccount, dangerouslySkipVerification, options } = args;
|
|
956
|
+
} & ({ toAccount: Ed25519Account | MultiEd25519Account } | { toNewPrivateKey: Ed25519PrivateKey }),
|
|
957
|
+
): Promise<SimpleTransaction> {
|
|
958
|
+
const { aptosConfig, fromAccount, options } = args;
|
|
969
959
|
if ("toNewPrivateKey" in args) {
|
|
970
960
|
return rotateAuthKeyWithChallenge({
|
|
971
961
|
aptosConfig,
|
|
@@ -973,9 +963,7 @@ export async function rotateAuthKey(
|
|
|
973
963
|
toNewPrivateKey: args.toNewPrivateKey,
|
|
974
964
|
options,
|
|
975
965
|
});
|
|
976
|
-
}
|
|
977
|
-
let authKey: AuthenticationKey;
|
|
978
|
-
if ("toAccount" in args) {
|
|
966
|
+
} else if ("toAccount" in args) {
|
|
979
967
|
if (args.toAccount instanceof Ed25519Account) {
|
|
980
968
|
return rotateAuthKeyWithChallenge({
|
|
981
969
|
aptosConfig,
|
|
@@ -983,52 +971,12 @@ export async function rotateAuthKey(
|
|
|
983
971
|
toNewPrivateKey: args.toAccount.privateKey,
|
|
984
972
|
options,
|
|
985
973
|
});
|
|
986
|
-
}
|
|
987
|
-
if (args.toAccount instanceof MultiEd25519Account) {
|
|
974
|
+
} else {
|
|
988
975
|
return rotateAuthKeyWithChallenge({ aptosConfig, fromAccount, toAccount: args.toAccount, options });
|
|
989
976
|
}
|
|
990
|
-
authKey = args.toAccount.publicKey.authKey();
|
|
991
|
-
} else if ("toAuthKey" in args) {
|
|
992
|
-
authKey = args.toAuthKey;
|
|
993
977
|
} else {
|
|
994
978
|
throw new Error("Invalid arguments");
|
|
995
979
|
}
|
|
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
980
|
}
|
|
1033
981
|
|
|
1034
982
|
async function rotateAuthKeyWithChallenge(
|
|
@@ -1037,7 +985,7 @@ async function rotateAuthKeyWithChallenge(
|
|
|
1037
985
|
fromAccount: Account;
|
|
1038
986
|
options?: InputGenerateTransactionOptions;
|
|
1039
987
|
} & ({ toNewPrivateKey: Ed25519PrivateKey } | { toAccount: MultiEd25519Account }),
|
|
1040
|
-
): Promise<
|
|
988
|
+
): Promise<SimpleTransaction> {
|
|
1041
989
|
const { aptosConfig, fromAccount, options } = args;
|
|
1042
990
|
const accountInfo = await getInfo({
|
|
1043
991
|
aptosConfig,
|
|
@@ -1064,7 +1012,7 @@ async function rotateAuthKeyWithChallenge(
|
|
|
1064
1012
|
const proofSignedByNewKey = newAccount.sign(challengeHex);
|
|
1065
1013
|
|
|
1066
1014
|
// Generate transaction
|
|
1067
|
-
|
|
1015
|
+
return generateTransaction({
|
|
1068
1016
|
aptosConfig,
|
|
1069
1017
|
sender: fromAccount.accountAddress,
|
|
1070
1018
|
data: {
|
|
@@ -1081,41 +1029,46 @@ async function rotateAuthKeyWithChallenge(
|
|
|
1081
1029
|
},
|
|
1082
1030
|
options,
|
|
1083
1031
|
});
|
|
1084
|
-
return signAndSubmitTransaction({
|
|
1085
|
-
aptosConfig,
|
|
1086
|
-
signer: fromAccount,
|
|
1087
|
-
transaction: rawTxn,
|
|
1088
|
-
});
|
|
1089
1032
|
}
|
|
1090
1033
|
|
|
1091
1034
|
const rotateAuthKeyUnverifiedAbi: EntryFunctionABI = {
|
|
1092
1035
|
typeParameters: [],
|
|
1093
|
-
parameters: [TypeTagVector.u8()],
|
|
1036
|
+
parameters: [new TypeTagU8(), TypeTagVector.u8()],
|
|
1094
1037
|
};
|
|
1095
1038
|
|
|
1096
|
-
|
|
1039
|
+
/**
|
|
1040
|
+
* Rotates the authentication key for a given account without verifying the new key.
|
|
1041
|
+
*
|
|
1042
|
+
* @param args - The arguments for rotating the authentication key.
|
|
1043
|
+
* @param args.aptosConfig - The configuration settings for the Aptos network.
|
|
1044
|
+
* @param args.fromAccount - The account from which the authentication key will be rotated.
|
|
1045
|
+
* @param args.toNewPublicKey - The new public key to rotate to.
|
|
1046
|
+
* @returns A simple transaction object that can be submitted to the network.
|
|
1047
|
+
* @throws Error if the rotation fails or verification fails.
|
|
1048
|
+
*
|
|
1049
|
+
* @group Implementation
|
|
1050
|
+
*/
|
|
1051
|
+
export async function rotateAuthKeyUnverified(args: {
|
|
1097
1052
|
aptosConfig: AptosConfig;
|
|
1098
1053
|
fromAccount: Account;
|
|
1099
|
-
|
|
1054
|
+
toNewPublicKey: AccountPublicKey;
|
|
1100
1055
|
options?: InputGenerateTransactionOptions;
|
|
1101
|
-
}): Promise<
|
|
1102
|
-
const { aptosConfig, fromAccount,
|
|
1103
|
-
|
|
1104
|
-
|
|
1056
|
+
}): Promise<SimpleTransaction> {
|
|
1057
|
+
const { aptosConfig, fromAccount, toNewPublicKey, options } = args;
|
|
1058
|
+
|
|
1059
|
+
return generateTransaction({
|
|
1105
1060
|
aptosConfig,
|
|
1106
1061
|
sender: fromAccount.accountAddress,
|
|
1107
1062
|
data: {
|
|
1108
|
-
function: "0x1::account::
|
|
1109
|
-
functionArguments: [
|
|
1063
|
+
function: "0x1::account::rotate_authentication_key_from_public_key",
|
|
1064
|
+
functionArguments: [
|
|
1065
|
+
new U8(accountPublicKeyToSigningScheme(toNewPublicKey)), // to scheme
|
|
1066
|
+
MoveVector.U8(accountPublicKeyToBaseAccountPublicKey(toNewPublicKey).toUint8Array()),
|
|
1067
|
+
],
|
|
1110
1068
|
abi: rotateAuthKeyUnverifiedAbi,
|
|
1111
1069
|
},
|
|
1112
1070
|
options,
|
|
1113
1071
|
});
|
|
1114
|
-
return signAndSubmitTransaction({
|
|
1115
|
-
aptosConfig,
|
|
1116
|
-
signer: fromAccount,
|
|
1117
|
-
transaction: rawTxn,
|
|
1118
|
-
});
|
|
1119
1072
|
}
|
|
1120
1073
|
|
|
1121
1074
|
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/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,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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/crypto/secp256k1.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { sha3_256 } from \"@noble/hashes/sha3\";\nimport { secp256k1 } from \"@noble/curves/secp256k1\";\nimport { HDKey } from \"@scure/bip32\";\nimport { Serializable, Deserializer, Serializer } from \"../../bcs\";\nimport { Hex } from \"../hex\";\nimport { HexInput, PrivateKeyVariants } from \"../../types\";\nimport { isValidBIP44Path, mnemonicToSeed } from \"./hdKey\";\nimport { PrivateKey } from \"./privateKey\";\nimport { PublicKey } from \"./publicKey\";\nimport { Signature } from \"./signature\";\nimport { convertSigningMessage } from \"./utils\";\nimport { AptosConfig } from \"../../api\";\n\n/**\n * Represents a Secp256k1 ECDSA public key.\n *\n * @extends PublicKey\n * @property LENGTH - The length of the Secp256k1 public key in bytes.\n * @group Implementation\n * @category Serialization\n */\nexport class Secp256k1PublicKey extends PublicKey {\n // Secp256k1 ecdsa public keys contain a prefix indicating compression and two 32-byte coordinates.\n static readonly LENGTH: number = 65;\n\n // If it's compressed, it is only 33 bytes\n static readonly COMPRESSED_LENGTH: number = 33;\n\n // Hex value of the public key\n private readonly key: Hex;\n\n /**\n * Create a new PublicKey instance from a HexInput, which can be a string or Uint8Array.\n * This constructor validates the length of the provided signature data.\n *\n * @param hexInput - A HexInput (string or Uint8Array) representing the signature data.\n * @throws Error if the length of the signature data is not equal to Secp256k1Signature.LENGTH.\n * @group Implementation\n * @category Serialization\n */\n constructor(hexInput: HexInput) {\n super();\n\n const hex = Hex.fromHexInput(hexInput);\n const { length } = hex.toUint8Array();\n if (length === Secp256k1PublicKey.LENGTH) {\n this.key = hex;\n } else if (length === Secp256k1PublicKey.COMPRESSED_LENGTH) {\n const point = secp256k1.ProjectivePoint.fromHex(hex.toUint8Array());\n this.key = Hex.fromHexInput(point.toRawBytes(false));\n } else {\n throw new Error(\n `PublicKey length should be ${Secp256k1PublicKey.LENGTH} or ${Secp256k1PublicKey.COMPRESSED_LENGTH}, received ${length}`,\n );\n }\n }\n\n // region PublicKey\n /**\n * Verifies a Secp256k1 signature against the public key.\n *\n * This function checks the validity of a signature for a given message, ensuring that the signature is canonical as a malleability check.\n *\n * @param args - The arguments for verifying the signature.\n * @param args.message - The message that was signed.\n * @param args.signature - The signature to verify against the public key.\n * @group Implementation\n * @category Serialization\n */\n verifySignature(args: { message: HexInput; signature: Secp256k1Signature }): boolean {\n const { message, signature } = args;\n const messageToVerify = convertSigningMessage(message);\n const messageBytes = Hex.fromHexInput(messageToVerify).toUint8Array();\n const messageSha3Bytes = sha3_256(messageBytes);\n const signatureBytes = signature.toUint8Array();\n return secp256k1.verify(signatureBytes, messageSha3Bytes, this.key.toUint8Array(), { lowS: true });\n }\n\n /**\n * Note: Secp256k1Signatures can be verified syncronously.\n *\n * Verifies the provided signature against the given message.\n * This function helps ensure the integrity and authenticity of the message by confirming that the signature is valid.\n *\n * @param args - The arguments for signature verification.\n * @param args.aptosConfig - The configuration object for connecting to the Aptos network\n * @param args.message - The message that was signed.\n * @param args.signature - The signature to verify, which must be an instance of Secp256k1Signature.\n * @returns A boolean indicating whether the signature is valid for the given message.\n * @group Implementation\n * @category Serialization\n */\n async verifySignatureAsync(args: {\n aptosConfig: AptosConfig;\n message: HexInput;\n signature: Secp256k1Signature;\n }): Promise<boolean> {\n return this.verifySignature(args);\n }\n\n /**\n * Get the data as a Uint8Array representation.\n *\n * @returns Uint8Array representation of the data.\n * @group Implementation\n * @category Serialization\n */\n toUint8Array(): Uint8Array {\n return this.key.toUint8Array();\n }\n\n // endregion\n\n // region Serializable\n\n /**\n * Serializes the data into a byte array using the provided serializer.\n * This function is essential for converting data into a format suitable for transmission or storage.\n *\n * @param serializer - The serializer instance used to convert the data.\n * @group Implementation\n * @category Serialization\n */\n serialize(serializer: Serializer): void {\n serializer.serializeBytes(this.key.toUint8Array());\n }\n\n /**\n * Deserializes a Secp256k1Signature from the provided deserializer.\n * This function allows you to reconstruct a Secp256k1Signature object from its serialized byte representation.\n *\n * @param deserializer - The deserializer instance used to read the serialized data.\n * @group Implementation\n * @category Serialization\n */\n // eslint-disable-next-line class-methods-use-this\n deserialize(deserializer: Deserializer) {\n const hex = deserializer.deserializeBytes();\n return new Secp256k1Signature(hex);\n }\n\n static deserialize(deserializer: Deserializer): Secp256k1PublicKey {\n const bytes = deserializer.deserializeBytes();\n return new Secp256k1PublicKey(bytes);\n }\n\n // endregion\n\n /**\n * Determine if the provided public key is an instance of Secp256k1PublicKey.\n *\n * @deprecated use `instanceof Secp256k1PublicKey` instead\n * @param publicKey - The public key to check.\n * @group Implementation\n * @category Serialization\n */\n static isPublicKey(publicKey: PublicKey): publicKey is Secp256k1PublicKey {\n return publicKey instanceof Secp256k1PublicKey;\n }\n\n /**\n * Determines if the provided public key is a valid instance of a Secp256k1 public key.\n * This function checks for the presence of a \"key\" property and validates the length of the key data.\n *\n * @param publicKey - The public key to validate.\n * @returns A boolean indicating whether the public key is a valid Secp256k1 public key.\n * @group Implementation\n * @category Serialization\n */\n static isInstance(publicKey: PublicKey): publicKey is Secp256k1PublicKey {\n return \"key\" in publicKey && (publicKey.key as any)?.data?.length === Secp256k1PublicKey.LENGTH;\n }\n}\n\n/**\n * Represents a Secp256k1 ECDSA private key, providing functionality to create, sign messages,\n * derive public keys, and serialize/deserialize the key.\n * @group Implementation\n * @category Serialization\n */\nexport class Secp256k1PrivateKey extends Serializable implements PrivateKey {\n /**\n * Length of Secp256k1 ecdsa private key\n * @group Implementation\n * @category Serialization\n */\n static readonly LENGTH: number = 32;\n\n /**\n * The private key bytes\n * @private\n * @group Implementation\n * @category Serialization\n */\n private readonly key: Hex;\n\n // region Constructors\n\n /**\n * Create a new PrivateKey instance from a Uint8Array or String.\n *\n * [Read about AIP-80](https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-80.md)\n *\n * @param hexInput A HexInput (string or Uint8Array)\n * @param strict If true, private key must AIP-80 compliant.\n * @group Implementation\n * @category Serialization\n */\n constructor(hexInput: HexInput, strict?: boolean) {\n super();\n\n const privateKeyHex = PrivateKey.parseHexInput(hexInput, PrivateKeyVariants.Secp256k1, strict);\n if (privateKeyHex.toUint8Array().length !== Secp256k1PrivateKey.LENGTH) {\n throw new Error(`PrivateKey length should be ${Secp256k1PrivateKey.LENGTH}`);\n }\n\n this.key = privateKeyHex;\n }\n\n /**\n * Generate a new random private key.\n *\n * @returns Secp256k1PrivateKey - A newly generated Secp256k1 private key.\n * @group Implementation\n * @category Serialization\n */\n static generate(): Secp256k1PrivateKey {\n const hexInput = secp256k1.utils.randomPrivateKey();\n return new Secp256k1PrivateKey(hexInput, false);\n }\n\n /**\n * Derives a private key from a mnemonic seed phrase using a specified BIP44 path.\n *\n * @param path - The BIP44 path to derive the key from.\n * @param mnemonics - The mnemonic seed phrase used for key generation.\n *\n * @returns The generated private key.\n *\n * @throws Error if the provided path is not a valid BIP44 path.\n * @group Implementation\n * @category Serialization\n */\n static fromDerivationPath(path: string, mnemonics: string): Secp256k1PrivateKey {\n if (!isValidBIP44Path(path)) {\n throw new Error(`Invalid derivation path ${path}`);\n }\n return Secp256k1PrivateKey.fromDerivationPathInner(path, mnemonicToSeed(mnemonics));\n }\n\n /**\n * Derives a private key from a specified BIP44 path using a given seed.\n * This function is essential for generating keys that follow the hierarchical deterministic (HD) wallet structure.\n *\n * @param path - The BIP44 path used for key derivation.\n * @param seed - The seed phrase created by the mnemonics, represented as a Uint8Array.\n * @returns The generated private key as an instance of Secp256k1PrivateKey.\n * @throws Error if the derived private key is invalid.\n * @group Implementation\n * @category Serialization\n */\n private static fromDerivationPathInner(path: string, seed: Uint8Array): Secp256k1PrivateKey {\n const { privateKey } = HDKey.fromMasterSeed(seed).derive(path);\n // library returns privateKey as Uint8Array | null\n if (privateKey === null) {\n throw new Error(\"Invalid key\");\n }\n\n return new Secp256k1PrivateKey(privateKey, false);\n }\n\n // endregion\n\n // region PrivateKey\n\n /**\n * Sign the given message with the private key.\n * This function generates a cryptographic signature for the provided message, ensuring the signature is canonical and non-malleable.\n *\n * @param message - A message in HexInput format to be signed.\n * @returns Signature - The generated signature for the provided message.\n * @group Implementation\n * @category Serialization\n */\n sign(message: HexInput): Secp256k1Signature {\n const messageToSign = convertSigningMessage(message);\n const messageBytes = Hex.fromHexInput(messageToSign);\n const messageHashBytes = sha3_256(messageBytes.toUint8Array());\n const signature = secp256k1.sign(messageHashBytes, this.key.toUint8Array(), { lowS: true });\n return new Secp256k1Signature(signature.toCompactRawBytes());\n }\n\n /**\n * Derive the Secp256k1PublicKey from this private key.\n *\n * @returns Secp256k1PublicKey The derived public key.\n * @group Implementation\n * @category Serialization\n */\n publicKey(): Secp256k1PublicKey {\n const bytes = secp256k1.getPublicKey(this.key.toUint8Array(), false);\n return new Secp256k1PublicKey(bytes);\n }\n\n /**\n * Get the private key in bytes (Uint8Array).\n *\n * @returns\n * @group Implementation\n * @category Serialization\n */\n toUint8Array(): Uint8Array {\n return this.key.toUint8Array();\n }\n\n /**\n * Get the private key as a string representation.\n *\n * @returns string representation of the private key\n * @group Implementation\n * @category Serialization\n */\n toString(): string {\n return this.toAIP80String();\n }\n\n /**\n * Get the private key as a hex string with the 0x prefix.\n *\n * @returns string representation of the private key.\n */\n toHexString(): string {\n return this.key.toString();\n }\n\n /**\n * Get the private key as a AIP-80 compliant hex string.\n *\n * [Read about AIP-80](https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-80.md)\n *\n * @returns AIP-80 compliant string representation of the private key.\n */\n toAIP80String(): string {\n return PrivateKey.formatPrivateKey(this.key.toString(), PrivateKeyVariants.Secp256k1);\n }\n\n // endregion\n\n // region Serializable\n\n serialize(serializer: Serializer): void {\n serializer.serializeBytes(this.toUint8Array());\n }\n\n static deserialize(deserializer: Deserializer): Secp256k1PrivateKey {\n const bytes = deserializer.deserializeBytes();\n return new Secp256k1PrivateKey(bytes, false);\n }\n\n // endregion\n\n /**\n * Determines if the provided private key is an instance of Secp256k1PrivateKey.\n *\n * @param privateKey - The private key to be checked.\n *\n * @deprecated use `instanceof Secp256k1PrivateKey` instead\n * @group Implementation\n * @category Serialization\n */\n static isPrivateKey(privateKey: PrivateKey): privateKey is Secp256k1PrivateKey {\n return privateKey instanceof Secp256k1PrivateKey;\n }\n}\n\n/**\n * Represents a signature of a message signed using a Secp256k1 ECDSA private key.\n *\n * @group Implementation\n * @category Serialization\n */\nexport class Secp256k1Signature extends Signature {\n /**\n * Secp256k1 ecdsa signatures are 256-bit.\n * @group Implementation\n * @category Serialization\n */\n static readonly LENGTH = 64;\n\n /**\n * The signature bytes\n * @private\n * @group Implementation\n * @category Serialization\n */\n private readonly data: Hex;\n\n // region Constructors\n\n /**\n * Create a new Signature instance from a Uint8Array or String.\n *\n * @param hexInput A HexInput (string or Uint8Array)\n * @group Implementation\n * @category Serialization\n */\n constructor(hexInput: HexInput) {\n super();\n const data = Hex.fromHexInput(hexInput);\n if (data.toUint8Array().length !== Secp256k1Signature.LENGTH) {\n throw new Error(\n `Signature length should be ${Secp256k1Signature.LENGTH}, received ${data.toUint8Array().length}`,\n );\n }\n this.data = data;\n }\n\n // endregion\n\n // region Signature\n\n toUint8Array(): Uint8Array {\n return this.data.toUint8Array();\n }\n\n // endregion\n\n // region Serializable\n\n serialize(serializer: Serializer): void {\n serializer.serializeBytes(this.data.toUint8Array());\n }\n\n static deserialize(deserializer: Deserializer): Secp256k1Signature {\n const hex = deserializer.deserializeBytes();\n return new Secp256k1Signature(hex);\n }\n\n // endregion\n}\n"],"mappings":"sSAGA,OAAS,YAAAA,MAAgB,qBACzB,OAAS,aAAAC,MAAiB,0BAC1B,OAAS,SAAAC,MAAa,eAmBf,IAAMC,EAAN,MAAMA,UAA2BC,CAAU,CAmBhD,YAAYC,EAAoB,CAC9B,MAAM,EAEN,IAAMC,EAAMC,EAAI,aAAaF,CAAQ,EAC/B,CAAE,OAAAG,CAAO,EAAIF,EAAI,aAAa,EACpC,GAAIE,IAAWL,EAAmB,OAChC,KAAK,IAAMG,UACFE,IAAWL,EAAmB,kBAAmB,CAC1D,IAAMM,EAAQC,EAAU,gBAAgB,QAAQJ,EAAI,aAAa,CAAC,EAClE,KAAK,IAAMC,EAAI,aAAaE,EAAM,WAAW,EAAK,CAAC,CACrD,KACE,OAAM,IAAI,MACR,8BAA8BN,EAAmB,MAAM,OAAOA,EAAmB,iBAAiB,cAAcK,CAAM,EACxH,CAEJ,CAcA,gBAAgBG,EAAqE,CACnF,GAAM,CAAE,QAAAC,EAAS,UAAAC,CAAU,EAAIF,EACzBG,EAAkBC,EAAsBH,CAAO,EAC/CI,EAAeT,EAAI,aAAaO,CAAe,EAAE,aAAa,EAC9DG,EAAmBC,EAASF,CAAY,EACxCG,EAAiBN,EAAU,aAAa,EAC9C,OAAOH,EAAU,OAAOS,EAAgBF,EAAkB,KAAK,IAAI,aAAa,EAAG,CAAE,KAAM,EAAK,CAAC,CACnG,CAgBA,MAAM,qBAAqBN,EAIN,CACnB,OAAO,KAAK,gBAAgBA,CAAI,CAClC,CASA,cAA2B,CACzB,OAAO,KAAK,IAAI,aAAa,CAC/B,CAcA,UAAUS,EAA8B,CACtCA,EAAW,eAAe,KAAK,IAAI,aAAa,CAAC,CACnD,CAWA,YAAYC,EAA4B,CACtC,IAAMf,EAAMe,EAAa,iBAAiB,EAC1C,OAAO,IAAIC,EAAmBhB,CAAG,CACnC,CAEA,OAAO,YAAYe,EAAgD,CACjE,IAAME,EAAQF,EAAa,iBAAiB,EAC5C,OAAO,IAAIlB,EAAmBoB,CAAK,CACrC,CAYA,OAAO,YAAYC,EAAuD,CACxE,OAAOA,aAAqBrB,CAC9B,CAWA,OAAO,WAAWqB,EAAuD,CACvE,MAAO,QAASA,GAAcA,EAAU,KAAa,MAAM,SAAWrB,EAAmB,MAC3F,CACF,EAvJaA,EAEK,OAAiB,GAFtBA,EAKK,kBAA4B,GALvC,IAAMsB,EAANtB,EA+JMuB,EAAN,MAAMA,UAA4BC,CAAmC,CA4B1E,YAAYtB,EAAoBuB,EAAkB,CAChD,MAAM,EAEN,IAAMC,EAAgBC,EAAW,cAAczB,cAAwCuB,CAAM,EAC7F,GAAIC,EAAc,aAAa,EAAE,SAAWH,EAAoB,OAC9D,MAAM,IAAI,MAAM,+BAA+BA,EAAoB,MAAM,EAAE,EAG7E,KAAK,IAAMG,CACb,CASA,OAAO,UAAgC,CACrC,IAAMxB,EAAWK,EAAU,MAAM,iBAAiB,EAClD,OAAO,IAAIgB,EAAoBrB,EAAU,EAAK,CAChD,CAcA,OAAO,mBAAmB0B,EAAcC,EAAwC,CAC9E,GAAI,CAACC,EAAiBF,CAAI,EACxB,MAAM,IAAI,MAAM,2BAA2BA,CAAI,EAAE,EAEnD,OAAOL,EAAoB,wBAAwBK,EAAMG,EAAeF,CAAS,CAAC,CACpF,CAaA,OAAe,wBAAwBD,EAAcI,EAAuC,CAC1F,GAAM,CAAE,WAAAC,CAAW,EAAIC,EAAM,eAAeF,CAAI,EAAE,OAAOJ,CAAI,EAE7D,GAAIK,IAAe,KACjB,MAAM,IAAI,MAAM,aAAa,EAG/B,OAAO,IAAIV,EAAoBU,EAAY,EAAK,CAClD,CAeA,KAAKxB,EAAuC,CAC1C,IAAM0B,EAAgBvB,EAAsBH,CAAO,EAC7CI,EAAeT,EAAI,aAAa+B,CAAa,EAC7CC,EAAmBrB,EAASF,EAAa,aAAa,CAAC,EACvDH,EAAYH,EAAU,KAAK6B,EAAkB,KAAK,IAAI,aAAa,EAAG,CAAE,KAAM,EAAK,CAAC,EAC1F,OAAO,IAAIjB,EAAmBT,EAAU,kBAAkB,CAAC,CAC7D,CASA,WAAgC,CAC9B,IAAMU,EAAQb,EAAU,aAAa,KAAK,IAAI,aAAa,EAAG,EAAK,EACnE,OAAO,IAAIe,EAAmBF,CAAK,CACrC,CASA,cAA2B,CACzB,OAAO,KAAK,IAAI,aAAa,CAC/B,CASA,UAAmB,CACjB,OAAO,KAAK,cAAc,CAC5B,CAOA,aAAsB,CACpB,OAAO,KAAK,IAAI,SAAS,CAC3B,CASA,eAAwB,CACtB,OAAOO,EAAW,iBAAiB,KAAK,IAAI,SAAS,aAA+B,CACtF,CAMA,UAAUV,EAA8B,CACtCA,EAAW,eAAe,KAAK,aAAa,CAAC,CAC/C,CAEA,OAAO,YAAYC,EAAiD,CAClE,IAAME,EAAQF,EAAa,iBAAiB,EAC5C,OAAO,IAAIK,EAAoBH,EAAO,EAAK,CAC7C,CAaA,OAAO,aAAaa,EAA2D,CAC7E,OAAOA,aAAsBV,CAC/B,CACF,EAjMaA,EAMK,OAAiB,GAN5B,IAAMc,EAANd,EAyMMe,EAAN,MAAMA,UAA2BC,CAAU,CAyBhD,YAAYrC,EAAoB,CAC9B,MAAM,EACN,IAAMsC,EAAOpC,EAAI,aAAaF,CAAQ,EACtC,GAAIsC,EAAK,aAAa,EAAE,SAAWF,EAAmB,OACpD,MAAM,IAAI,MACR,8BAA8BA,EAAmB,MAAM,cAAcE,EAAK,aAAa,EAAE,MAAM,EACjG,EAEF,KAAK,KAAOA,CACd,CAMA,cAA2B,CACzB,OAAO,KAAK,KAAK,aAAa,CAChC,CAMA,UAAUvB,EAA8B,CACtCA,EAAW,eAAe,KAAK,KAAK,aAAa,CAAC,CACpD,CAEA,OAAO,YAAYC,EAAgD,CACjE,IAAMf,EAAMe,EAAa,iBAAiB,EAC1C,OAAO,IAAIoB,EAAmBnC,CAAG,CACnC,CAGF,EA1DamC,EAMK,OAAS,GANpB,IAAMnB,EAANmB","names":["sha3_256","secp256k1","HDKey","_Secp256k1PublicKey","PublicKey","hexInput","hex","Hex","length","point","secp256k1","args","message","signature","messageToVerify","convertSigningMessage","messageBytes","messageSha3Bytes","sha3_256","signatureBytes","serializer","deserializer","Secp256k1Signature","bytes","publicKey","Secp256k1PublicKey","_Secp256k1PrivateKey","Serializable","strict","privateKeyHex","PrivateKey","path","mnemonics","isValidBIP44Path","mnemonicToSeed","seed","privateKey","HDKey","messageToSign","messageHashBytes","Secp256k1PrivateKey","_Secp256k1Signature","Signature","data"]}
|