@haneullabs/haneul 2.5.1 → 2.13.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/CHANGELOG.md +129 -0
- package/README.md +36 -36
- package/dist/bcs/bcs.d.mts +6 -7
- package/dist/bcs/bcs.d.mts.map +1 -1
- package/dist/bcs/bcs.mjs.map +1 -1
- package/dist/bcs/effects.mjs.map +1 -1
- package/dist/bcs/index.d.mts +2 -2
- package/dist/bcs/index.d.mts.map +1 -1
- package/dist/bcs/index.mjs +2 -2
- package/dist/bcs/index.mjs.map +1 -1
- package/dist/bcs/pure.d.mts.map +1 -1
- package/dist/bcs/type-tag-serializer.d.mts.map +1 -1
- package/dist/bcs/types.d.mts +0 -1
- package/dist/bcs/types.d.mts.map +1 -1
- package/dist/client/cache.d.mts.map +1 -1
- package/dist/client/client.d.mts.map +1 -1
- package/dist/client/core-resolver.d.mts.map +1 -1
- package/dist/client/core-resolver.mjs +87 -68
- package/dist/client/core-resolver.mjs.map +1 -1
- package/dist/client/core.d.mts +9 -8
- package/dist/client/core.d.mts.map +1 -1
- package/dist/client/core.mjs +29 -10
- package/dist/client/core.mjs.map +1 -1
- package/dist/client/errors.d.mts.map +1 -1
- package/dist/client/mvr.d.mts +0 -1
- package/dist/client/mvr.d.mts.map +1 -1
- package/dist/client/types.d.mts +110 -24
- package/dist/client/types.d.mts.map +1 -1
- package/dist/client/utils.d.mts.map +1 -1
- package/dist/client/utils.mjs +7 -7
- package/dist/client/utils.mjs.map +1 -1
- package/dist/cryptography/index.d.mts +2 -2
- package/dist/cryptography/index.mjs +2 -2
- package/dist/cryptography/intent.d.mts +2 -2
- package/dist/cryptography/intent.d.mts.map +1 -1
- package/dist/cryptography/intent.mjs +2 -2
- package/dist/cryptography/intent.mjs.map +1 -1
- package/dist/cryptography/keypair.d.mts +3 -3
- package/dist/cryptography/keypair.d.mts.map +1 -1
- package/dist/cryptography/keypair.mjs +3 -3
- package/dist/cryptography/keypair.mjs.map +1 -1
- package/dist/cryptography/mnemonics.d.mts +5 -5
- package/dist/cryptography/mnemonics.d.mts.map +1 -1
- package/dist/cryptography/mnemonics.mjs +7 -7
- package/dist/cryptography/mnemonics.mjs.map +1 -1
- package/dist/cryptography/publickey.d.mts +2 -3
- package/dist/cryptography/publickey.d.mts.map +1 -1
- package/dist/cryptography/publickey.mjs +10 -10
- package/dist/cryptography/publickey.mjs.map +1 -1
- package/dist/cryptography/signature-scheme.d.mts.map +1 -1
- package/dist/cryptography/signature.d.mts +10 -13
- package/dist/cryptography/signature.d.mts.map +1 -1
- package/dist/cryptography/signature.mjs +2 -2
- package/dist/cryptography/signature.mjs.map +1 -1
- package/dist/faucet/faucet.d.mts +2 -2
- package/dist/faucet/faucet.d.mts.map +1 -1
- package/dist/faucet/faucet.mjs +2 -2
- package/dist/faucet/faucet.mjs.map +1 -1
- package/dist/faucet/index.d.mts +2 -2
- package/dist/faucet/index.mjs +2 -2
- package/dist/graphql/client.d.mts +20 -5
- package/dist/graphql/client.d.mts.map +1 -1
- package/dist/graphql/client.mjs +55 -7
- package/dist/graphql/client.mjs.map +1 -1
- package/dist/graphql/core.d.mts +6 -5
- package/dist/graphql/core.d.mts.map +1 -1
- package/dist/graphql/core.mjs +43 -47
- package/dist/graphql/core.mjs.map +1 -1
- package/dist/graphql/generated/queries.d.mts +0 -1
- package/dist/graphql/generated/queries.d.mts.map +1 -1
- package/dist/graphql/generated/queries.mjs +46 -10
- package/dist/graphql/generated/queries.mjs.map +1 -1
- package/dist/graphql/generated/tada-env.d.mts +706 -98
- package/dist/graphql/generated/tada-env.d.mts.map +1 -1
- package/dist/graphql/index.d.mts +2 -2
- package/dist/graphql/index.mjs +2 -2
- package/dist/graphql/schema/index.d.mts +0 -1
- package/dist/graphql/schema/index.d.mts.map +1 -1
- package/dist/graphql/types.d.mts.map +1 -1
- package/dist/grpc/client.d.mts +20 -5
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs +47 -7
- package/dist/grpc/client.mjs.map +1 -1
- package/dist/grpc/core.d.mts +6 -5
- package/dist/grpc/core.d.mts.map +1 -1
- package/dist/grpc/core.mjs +35 -34
- package/dist/grpc/core.mjs.map +1 -1
- package/dist/grpc/index.d.mts +2 -2
- package/dist/grpc/index.mjs +2 -2
- package/dist/grpc/proto/google/protobuf/any.d.mts +0 -1
- package/dist/grpc/proto/google/protobuf/any.d.mts.map +1 -1
- package/dist/grpc/proto/google/protobuf/duration.d.mts +0 -1
- package/dist/grpc/proto/google/protobuf/duration.d.mts.map +1 -1
- package/dist/grpc/proto/google/protobuf/field_mask.d.mts +0 -1
- package/dist/grpc/proto/google/protobuf/field_mask.d.mts.map +1 -1
- package/dist/grpc/proto/google/protobuf/struct.d.mts +1 -2
- package/dist/grpc/proto/google/protobuf/struct.d.mts.map +1 -1
- package/dist/grpc/proto/google/protobuf/timestamp.d.mts +0 -1
- package/dist/grpc/proto/google/protobuf/timestamp.d.mts.map +1 -1
- package/dist/grpc/proto/google/rpc/status.d.mts +0 -1
- package/dist/grpc/proto/google/rpc/status.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/argument.d.mts +1 -2
- package/dist/grpc/proto/haneul/rpc/v2/argument.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/balance_change.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/balance_change.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/bcs.d.mts +1 -2
- package/dist/grpc/proto/haneul/rpc/v2/bcs.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/bcs.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/checkpoint.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/checkpoint.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/checkpoint_contents.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/checkpoint_contents.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/checkpoint_summary.d.mts +1 -2
- package/dist/grpc/proto/haneul/rpc/v2/checkpoint_summary.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/effects.d.mts +5 -6
- package/dist/grpc/proto/haneul/rpc/v2/effects.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/epoch.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/epoch.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/error_reason.d.mts +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/error_reason.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/event.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/event.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/executed_transaction.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/executed_transaction.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/execution_status.d.mts +8 -9
- package/dist/grpc/proto/haneul/rpc/v2/execution_status.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/execution_status.mjs +4 -4
- package/dist/grpc/proto/haneul/rpc/v2/execution_status.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/gas_cost_summary.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/gas_cost_summary.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/input.d.mts +3 -4
- package/dist/grpc/proto/haneul/rpc/v2/input.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/jwk.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/jwk.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/ledger_service.client.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/ledger_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/ledger_service.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/ledger_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/move_package.d.mts +5 -6
- package/dist/grpc/proto/haneul/rpc/v2/move_package.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/move_package_service.client.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/move_package_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/move_package_service.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/move_package_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/name_service.client.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/name_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/name_service.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/name_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/object.d.mts +38 -2
- package/dist/grpc/proto/haneul/rpc/v2/object.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/object.mjs +26 -1
- package/dist/grpc/proto/haneul/rpc/v2/object.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/object_reference.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/object_reference.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/owner.d.mts +1 -2
- package/dist/grpc/proto/haneul/rpc/v2/owner.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/protocol_config.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/protocol_config.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature.d.mts +1 -2
- package/dist/grpc/proto/haneul/rpc/v2/signature.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_scheme.d.mts +2 -2
- package/dist/grpc/proto/haneul/rpc/v2/signature_scheme.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_scheme.mjs +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_scheme.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_verification_service.client.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/signature_verification_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_verification_service.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_verification_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/state_service.client.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/state_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/state_service.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/state_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/subscription_service.client.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/subscription_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/subscription_service.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/subscription_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/system_state.d.mts +3 -4
- package/dist/grpc/proto/haneul/rpc/v2/system_state.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/system_state.mjs +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/system_state.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/transaction.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/transaction.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.client.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.d.mts +9 -2
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.mjs +23 -12
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.mjs.map +1 -1
- package/dist/grpc/proto/types.d.mts +2 -2
- package/dist/grpc/proto/types.d.mts.map +1 -1
- package/dist/grpc/proto/types.mjs +2 -1
- package/dist/jsonRpc/client.d.mts +4 -7
- package/dist/jsonRpc/client.d.mts.map +1 -1
- package/dist/jsonRpc/client.mjs +4 -33
- package/dist/jsonRpc/client.mjs.map +1 -1
- package/dist/jsonRpc/core.d.mts +8 -15
- package/dist/jsonRpc/core.d.mts.map +1 -1
- package/dist/jsonRpc/core.mjs +81 -34
- package/dist/jsonRpc/core.mjs.map +1 -1
- package/dist/jsonRpc/errors.d.mts.map +1 -1
- package/dist/jsonRpc/http-transport.d.mts +1 -17
- package/dist/jsonRpc/http-transport.d.mts.map +1 -1
- package/dist/jsonRpc/http-transport.mjs +0 -23
- package/dist/jsonRpc/http-transport.mjs.map +1 -1
- package/dist/jsonRpc/index.d.mts +3 -3
- package/dist/jsonRpc/network.d.mts.map +1 -1
- package/dist/jsonRpc/types/chain.d.mts.map +1 -1
- package/dist/jsonRpc/types/changes.d.mts.map +1 -1
- package/dist/jsonRpc/types/coins.d.mts.map +1 -1
- package/dist/jsonRpc/types/common.d.mts +1 -2
- package/dist/jsonRpc/types/common.d.mts.map +1 -1
- package/dist/jsonRpc/types/generated.d.mts +101 -129
- package/dist/jsonRpc/types/generated.d.mts.map +1 -1
- package/dist/jsonRpc/types/index.d.mts +1 -1
- package/dist/jsonRpc/types/params.d.mts +9 -14
- package/dist/jsonRpc/types/params.d.mts.map +1 -1
- package/dist/keypairs/ed25519/keypair.d.mts +8 -6
- package/dist/keypairs/ed25519/keypair.d.mts.map +1 -1
- package/dist/keypairs/ed25519/keypair.mjs +13 -9
- package/dist/keypairs/ed25519/keypair.mjs.map +1 -1
- package/dist/keypairs/ed25519/publickey.d.mts +0 -1
- package/dist/keypairs/ed25519/publickey.d.mts.map +1 -1
- package/dist/keypairs/passkey/keypair.d.mts +12 -5
- package/dist/keypairs/passkey/keypair.d.mts.map +1 -1
- package/dist/keypairs/passkey/keypair.mjs +20 -7
- package/dist/keypairs/passkey/keypair.mjs.map +1 -1
- package/dist/keypairs/passkey/publickey.d.mts +0 -1
- package/dist/keypairs/passkey/publickey.d.mts.map +1 -1
- package/dist/keypairs/passkey/types.d.mts.map +1 -1
- package/dist/keypairs/secp256k1/keypair.d.mts +3 -3
- package/dist/keypairs/secp256k1/keypair.d.mts.map +1 -1
- package/dist/keypairs/secp256k1/keypair.mjs +6 -6
- package/dist/keypairs/secp256k1/keypair.mjs.map +1 -1
- package/dist/keypairs/secp256k1/publickey.d.mts +0 -1
- package/dist/keypairs/secp256k1/publickey.d.mts.map +1 -1
- package/dist/keypairs/secp256r1/keypair.d.mts +3 -3
- package/dist/keypairs/secp256r1/keypair.d.mts.map +1 -1
- package/dist/keypairs/secp256r1/keypair.mjs +6 -6
- package/dist/keypairs/secp256r1/keypair.mjs.map +1 -1
- package/dist/keypairs/secp256r1/publickey.d.mts +0 -1
- package/dist/keypairs/secp256r1/publickey.d.mts.map +1 -1
- package/dist/multisig/publickey.d.mts +1 -0
- package/dist/multisig/publickey.d.mts.map +1 -1
- package/dist/multisig/publickey.mjs +8 -8
- package/dist/multisig/publickey.mjs.map +1 -1
- package/dist/multisig/signer.d.mts.map +1 -1
- package/dist/transactions/Arguments.d.mts.map +1 -1
- package/dist/transactions/Commands.d.mts +1 -1
- package/dist/transactions/Commands.d.mts.map +1 -1
- package/dist/transactions/Commands.mjs.map +1 -1
- package/dist/transactions/Inputs.d.mts.map +1 -1
- package/dist/transactions/ObjectCache.d.mts +3 -3
- package/dist/transactions/ObjectCache.d.mts.map +1 -1
- package/dist/transactions/Transaction.d.mts +32 -6
- package/dist/transactions/Transaction.d.mts.map +1 -1
- package/dist/transactions/Transaction.mjs +23 -1
- package/dist/transactions/Transaction.mjs.map +1 -1
- package/dist/transactions/TransactionData.d.mts.map +1 -1
- package/dist/transactions/TransactionData.mjs +8 -8
- package/dist/transactions/TransactionData.mjs.map +1 -1
- package/dist/transactions/data/internal.d.mts +109 -109
- package/dist/transactions/data/internal.d.mts.map +1 -1
- package/dist/transactions/data/internal.mjs.map +1 -1
- package/dist/transactions/data/v1.d.mts +220 -221
- package/dist/transactions/data/v1.d.mts.map +1 -1
- package/dist/transactions/data/v2.d.mts +16 -16
- package/dist/transactions/data/v2.d.mts.map +1 -1
- package/dist/transactions/data/v2.mjs.map +1 -1
- package/dist/transactions/executor/caching.mjs +2 -2
- package/dist/transactions/executor/caching.mjs.map +1 -1
- package/dist/transactions/executor/parallel.d.mts +1 -1
- package/dist/transactions/executor/parallel.d.mts.map +1 -1
- package/dist/transactions/executor/parallel.mjs +1 -1
- package/dist/transactions/executor/parallel.mjs.map +1 -1
- package/dist/transactions/executor/serial.d.mts +3 -3
- package/dist/transactions/executor/serial.d.mts.map +1 -1
- package/dist/transactions/executor/serial.mjs.map +1 -1
- package/dist/transactions/intents/CoinWithBalance.d.mts.map +1 -1
- package/dist/transactions/intents/CoinWithBalance.mjs +174 -97
- package/dist/transactions/intents/CoinWithBalance.mjs.map +1 -1
- package/dist/transactions/object.d.mts.map +1 -1
- package/dist/transactions/pure.d.mts.map +1 -1
- package/dist/transactions/pure.mjs +12 -12
- package/dist/transactions/pure.mjs.map +1 -1
- package/dist/transactions/resolve.d.mts.map +1 -1
- package/dist/transactions/resolve.mjs +3 -3
- package/dist/transactions/resolve.mjs.map +1 -1
- package/dist/transactions/serializer.d.mts.map +1 -1
- package/dist/transactions/serializer.mjs +15 -15
- package/dist/transactions/serializer.mjs.map +1 -1
- package/dist/transactions/utils.d.mts +0 -1
- package/dist/transactions/utils.d.mts.map +1 -1
- package/dist/utils/coin-reservation.mjs +67 -0
- package/dist/utils/coin-reservation.mjs.map +1 -0
- package/dist/utils/constants.d.mts +2 -1
- package/dist/utils/constants.d.mts.map +1 -1
- package/dist/utils/constants.mjs +2 -1
- package/dist/utils/constants.mjs.map +1 -1
- package/dist/utils/derived-objects.d.mts +0 -1
- package/dist/utils/derived-objects.d.mts.map +1 -1
- package/dist/utils/dynamic-fields.d.mts.map +1 -1
- package/dist/utils/dynamic-fields.mjs +4 -4
- package/dist/utils/dynamic-fields.mjs.map +1 -1
- package/dist/utils/format.d.mts.map +1 -1
- package/dist/utils/haneul-types.d.mts.map +1 -1
- package/dist/utils/haneul-types.mjs +8 -0
- package/dist/utils/haneul-types.mjs.map +1 -1
- package/dist/utils/haneulns.d.mts.map +1 -1
- package/dist/utils/index.d.mts +2 -2
- package/dist/utils/index.mjs +2 -2
- package/dist/utils/move-registry.d.mts.map +1 -1
- package/dist/verify/index.d.mts +2 -2
- package/dist/verify/index.mjs +2 -2
- package/dist/verify/verify.d.mts +2 -2
- package/dist/verify/verify.d.mts.map +1 -1
- package/dist/verify/verify.mjs +2 -2
- package/dist/verify/verify.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/address.d.mts.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/dist/zklogin/bcs.d.mts.map +1 -1
- package/dist/zklogin/jwt-decode.d.mts +0 -1
- package/dist/zklogin/jwt-decode.d.mts.map +1 -1
- package/dist/zklogin/jwt-utils.d.mts +0 -1
- package/dist/zklogin/jwt-utils.d.mts.map +1 -1
- package/dist/zklogin/nonce.d.mts.map +1 -1
- package/dist/zklogin/nonce.mjs +1 -1
- package/dist/zklogin/nonce.mjs.map +1 -1
- package/dist/zklogin/poseidon.d.mts.map +1 -1
- package/dist/zklogin/publickey.d.mts +0 -1
- package/dist/zklogin/publickey.d.mts.map +1 -1
- package/dist/zklogin/signature.d.mts.map +1 -1
- package/dist/zklogin/utils.d.mts.map +1 -1
- package/dist/zklogin/utils.mjs +1 -1
- package/dist/zklogin/utils.mjs.map +1 -1
- package/docs/bcs.md +132 -0
- package/docs/clients/core.md +616 -0
- package/docs/clients/graphql.md +99 -0
- package/docs/clients/grpc.md +152 -0
- package/docs/clients/index.md +93 -0
- package/docs/clients/json-rpc.md +235 -0
- package/docs/cryptography/keypairs.md +259 -0
- package/docs/cryptography/multisig.md +192 -0
- package/docs/cryptography/passkey.md +111 -0
- package/docs/cryptography/webcrypto-signer.md +81 -0
- package/docs/executors.md +148 -0
- package/docs/faucet.md +26 -0
- package/docs/hello-haneul.md +115 -0
- package/docs/index.md +56 -0
- package/docs/install.md +61 -0
- package/docs/llm-docs.md +32 -0
- package/docs/llms-index.md +66 -0
- package/docs/migrations/0.38.md +57 -0
- package/docs/migrations/haneul-1.0.md +454 -0
- package/docs/migrations/haneul-2.0/agent-prompt.md +42 -0
- package/docs/migrations/haneul-2.0/dapp-kit.md +350 -0
- package/docs/migrations/haneul-2.0/deepbook-v3.md +33 -0
- package/docs/migrations/haneul-2.0/haneul.md +341 -0
- package/docs/migrations/haneul-2.0/haneulns.md +42 -0
- package/docs/migrations/haneul-2.0/index.md +161 -0
- package/docs/migrations/haneul-2.0/json-rpc-migration.md +399 -0
- package/docs/migrations/haneul-2.0/kiosk.md +120 -0
- package/docs/migrations/haneul-2.0/sdk-maintainers.md +91 -0
- package/docs/migrations/haneul-2.0/seal.md +14 -0
- package/docs/migrations/haneul-2.0/wallet-builders.md +66 -0
- package/docs/migrations/haneul-2.0/walrus.md +41 -0
- package/docs/migrations/haneul-2.0/zksend.md +94 -0
- package/docs/plugins.md +255 -0
- package/docs/sdk-building.md +341 -0
- package/docs/transaction-building/basics.md +297 -0
- package/docs/transaction-building/gas.md +62 -0
- package/docs/transaction-building/intents.md +61 -0
- package/docs/transaction-building/offline.md +71 -0
- package/docs/transaction-building/sponsored-transactions.md +22 -0
- package/docs/utils/derived_objects.md +80 -0
- package/docs/utils/index.md +53 -0
- package/docs/zklogin.md +78 -0
- package/package.json +199 -199
- package/src/bcs/bcs.ts +13 -13
- package/src/bcs/effects.ts +20 -20
- package/src/bcs/index.ts +2 -2
- package/src/client/core-resolver.ts +150 -100
- package/src/client/core.ts +62 -22
- package/src/client/types.ts +109 -24
- package/src/cryptography/index.ts +2 -2
- package/src/cryptography/keypair.ts +2 -2
- package/src/cryptography/mnemonics.ts +7 -7
- package/src/cryptography/publickey.ts +8 -8
- package/src/faucet/faucet.ts +1 -1
- package/src/faucet/index.ts +1 -1
- package/src/graphql/client.ts +100 -8
- package/src/graphql/core.ts +73 -80
- package/src/graphql/generated/queries.ts +301 -51
- package/src/graphql/generated/schema.graphql +407 -104
- package/src/graphql/generated/tada-env.ts +779 -58
- package/src/graphql/index.ts +1 -1
- package/src/graphql/queries/getAllBalances.graphql +1 -1
- package/src/graphql/queries/getBalance.graphql +1 -1
- package/src/graphql/queries/getCoins.graphql +2 -2
- package/src/graphql/queries/getDynamicFields.graphql +9 -1
- package/src/graphql/queries/getMoveFunction.graphql +1 -1
- package/src/graphql/queries/getProtocolConfig.graphql +18 -0
- package/src/graphql/queries/nameService.graphql +1 -1
- package/src/graphql/queries/objects.graphql +11 -1
- package/src/graphql/queries/transactions.graphql +1 -3
- package/src/graphql/queries/verifyZkLoginSignature.graphql +1 -2
- package/src/grpc/client.ts +66 -8
- package/src/grpc/core.ts +74 -35
- package/src/grpc/index.ts +1 -1
- package/src/grpc/proto/haneul/rpc/v2/bcs.ts +1 -1
- package/src/grpc/proto/haneul/rpc/v2/execution_status.ts +4 -4
- package/src/grpc/proto/haneul/rpc/v2/object.ts +44 -0
- package/src/grpc/proto/haneul/rpc/v2/signature.ts +1 -1
- package/src/grpc/proto/haneul/rpc/v2/signature_scheme.ts +1 -1
- package/src/grpc/proto/haneul/rpc/v2/system_state.ts +4 -4
- package/src/grpc/proto/haneul/rpc/v2/transaction_execution_service.ts +16 -0
- package/src/jsonRpc/client.ts +5 -23
- package/src/jsonRpc/core.ts +114 -41
- package/src/jsonRpc/http-transport.ts +0 -52
- package/src/jsonRpc/index.ts +0 -1
- package/src/jsonRpc/types/common.ts +0 -1
- package/src/jsonRpc/types/generated.ts +2 -2
- package/src/jsonRpc/types/params.ts +6 -6
- package/src/keypairs/ed25519/keypair.ts +14 -10
- package/src/keypairs/passkey/keypair.ts +22 -8
- package/src/keypairs/secp256k1/keypair.ts +6 -6
- package/src/keypairs/secp256r1/keypair.ts +6 -6
- package/src/multisig/publickey.ts +1 -1
- package/src/transactions/Commands.ts +1 -1
- package/src/transactions/Transaction.ts +38 -1
- package/src/transactions/TransactionData.ts +3 -3
- package/src/transactions/__tests__/bcs.test.ts +3 -3
- package/src/transactions/data/internal.ts +12 -12
- package/src/transactions/data/v2.ts +6 -6
- package/src/transactions/executor/caching.ts +2 -2
- package/src/transactions/executor/parallel.ts +1 -2
- package/src/transactions/executor/serial.ts +1 -1
- package/src/transactions/intents/CoinWithBalance.ts +247 -121
- package/src/utils/coin-reservation.ts +84 -0
- package/src/utils/constants.ts +2 -0
- package/src/utils/haneul-types.ts +16 -1
- package/src/utils/index.ts +1 -0
- package/src/verify/index.ts +1 -1
- package/src/verify/verify.ts +1 -1
- package/src/version.ts +1 -1
- package/src/zklogin/nonce.ts +1 -1
- package/src/zklogin/utils.ts +1 -1
- package/dist/jsonRpc/rpc-websocket-client.d.mts +0 -26
- package/dist/jsonRpc/rpc-websocket-client.d.mts.map +0 -1
- package/dist/jsonRpc/rpc-websocket-client.mjs +0 -135
- package/dist/jsonRpc/rpc-websocket-client.mjs.map +0 -1
- package/src/jsonRpc/rpc-websocket-client.ts +0 -241
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isValidHardenedPath, mnemonicToSeedHex } from "../../cryptography/mnemonics.mjs";
|
|
2
|
-
import { Keypair, PRIVATE_KEY_SIZE,
|
|
2
|
+
import { Keypair, PRIVATE_KEY_SIZE, decodeHaneulPrivateKey, encodeHaneulPrivateKey } from "../../cryptography/keypair.mjs";
|
|
3
3
|
import { derivePath } from "./ed25519-hd-key.mjs";
|
|
4
4
|
import { Ed25519PublicKey } from "./publickey.mjs";
|
|
5
|
+
import { toHex } from "@haneullabs/bcs";
|
|
5
6
|
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
6
7
|
|
|
7
8
|
//#region src/keypairs/ed25519/keypair.ts
|
|
8
|
-
const DEFAULT_ED25519_DERIVATION_PATH = "m/44'/
|
|
9
|
+
const DEFAULT_ED25519_DERIVATION_PATH = "m/44'/8282'/0'/0'/0'";
|
|
9
10
|
/**
|
|
10
11
|
* An Ed25519 Keypair used for signing transactions.
|
|
11
12
|
*/
|
|
@@ -58,7 +59,7 @@ var Ed25519Keypair = class Ed25519Keypair extends Keypair {
|
|
|
58
59
|
*/
|
|
59
60
|
static fromSecretKey(secretKey, options) {
|
|
60
61
|
if (typeof secretKey === "string") {
|
|
61
|
-
const decoded =
|
|
62
|
+
const decoded = decodeHaneulPrivateKey(secretKey);
|
|
62
63
|
if (decoded.scheme !== "ED25519") throw new Error(`Expected a ED25519 keypair, got ${decoded.scheme}`);
|
|
63
64
|
return this.fromSecretKey(decoded.secretKey, options);
|
|
64
65
|
}
|
|
@@ -85,7 +86,7 @@ var Ed25519Keypair = class Ed25519Keypair extends Keypair {
|
|
|
85
86
|
* The Bech32 secret key string for this Ed25519 keypair
|
|
86
87
|
*/
|
|
87
88
|
getSecretKey() {
|
|
88
|
-
return
|
|
89
|
+
return encodeHaneulPrivateKey(this.keypair.secretKey.slice(0, PRIVATE_KEY_SIZE), this.getKeyScheme());
|
|
89
90
|
}
|
|
90
91
|
/**
|
|
91
92
|
* Return the signature for the provided data using Ed25519.
|
|
@@ -97,8 +98,8 @@ var Ed25519Keypair = class Ed25519Keypair extends Keypair {
|
|
|
97
98
|
* Derive Ed25519 keypair from mnemonics and path. The mnemonics must be normalized
|
|
98
99
|
* and validated against the english wordlist.
|
|
99
100
|
*
|
|
100
|
-
* If path is none, it will default to m/44'/
|
|
101
|
-
* be compliant to SLIP-0010 in form m/44'/
|
|
101
|
+
* If path is none, it will default to m/44'/8282'/0'/0'/0', otherwise the path must
|
|
102
|
+
* be compliant to SLIP-0010 in form m/44'/8282'/{account_index}'/{change_index}'/{address_index}'.
|
|
102
103
|
*/
|
|
103
104
|
static deriveKeypair(mnemonics, path) {
|
|
104
105
|
if (path == null) path = DEFAULT_ED25519_DERIVATION_PATH;
|
|
@@ -109,12 +110,15 @@ var Ed25519Keypair = class Ed25519Keypair extends Keypair {
|
|
|
109
110
|
/**
|
|
110
111
|
* Derive Ed25519 keypair from mnemonicSeed and path.
|
|
111
112
|
*
|
|
112
|
-
* If path is none, it will default to m/44'/
|
|
113
|
-
* be compliant to SLIP-0010 in form m/44'/
|
|
113
|
+
* If path is none, it will default to m/44'/8282'/0'/0'/0', otherwise the path must
|
|
114
|
+
* be compliant to SLIP-0010 in form m/44'/8282'/{account_index}'/{change_index}'/{address_index}'.
|
|
115
|
+
*
|
|
116
|
+
* @param seed - The seed as a hex string or Uint8Array.
|
|
114
117
|
*/
|
|
115
|
-
static deriveKeypairFromSeed(
|
|
118
|
+
static deriveKeypairFromSeed(seed, path) {
|
|
116
119
|
if (path == null) path = DEFAULT_ED25519_DERIVATION_PATH;
|
|
117
120
|
if (!isValidHardenedPath(path)) throw new Error("Invalid derivation path");
|
|
121
|
+
const seedHex = typeof seed === "string" ? seed : toHex(seed);
|
|
118
122
|
const { key } = derivePath(path, seedHex);
|
|
119
123
|
return Ed25519Keypair.fromSecretKey(key);
|
|
120
124
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keypair.mjs","names":[],"sources":["../../../src/keypairs/ed25519/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ed25519 } from '@noble/curves/ed25519.js';\n\nimport {\n\
|
|
1
|
+
{"version":3,"file":"keypair.mjs","names":[],"sources":["../../../src/keypairs/ed25519/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toHex } from '@haneullabs/bcs';\nimport { ed25519 } from '@noble/curves/ed25519.js';\n\nimport {\n\tdecodeHaneulPrivateKey,\n\tencodeHaneulPrivateKey,\n\tKeypair,\n\tPRIVATE_KEY_SIZE,\n} from '../../cryptography/keypair.js';\nimport { isValidHardenedPath, mnemonicToSeedHex } from '../../cryptography/mnemonics.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { derivePath } from './ed25519-hd-key.js';\nimport { Ed25519PublicKey } from './publickey.js';\n\nexport const DEFAULT_ED25519_DERIVATION_PATH = \"m/44'/8282'/0'/0'/0'\";\n\n/**\n * Ed25519 Keypair data. The publickey is the 32-byte public key and\n * the secretkey is 64-byte, where the first 32 bytes is the secret\n * key and the last 32 bytes is the public key.\n */\nexport interface Ed25519KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Ed25519 Keypair used for signing transactions.\n */\nexport class Ed25519Keypair extends Keypair {\n\tprivate keypair: Ed25519KeypairData;\n\n\t/**\n\t * Create a new Ed25519 keypair instance.\n\t * Generate random keypair if no {@link Ed25519Keypair} is provided.\n\t *\n\t * @param keypair Ed25519 keypair\n\t */\n\tconstructor(keypair?: Ed25519KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = {\n\t\t\t\tpublicKey: keypair.publicKey,\n\t\t\t\tsecretKey: keypair.secretKey.slice(0, 32),\n\t\t\t};\n\t\t} else {\n\t\t\tconst privateKey = ed25519.utils.randomSecretKey();\n\t\t\tthis.keypair = {\n\t\t\t\tpublicKey: ed25519.getPublicKey(privateKey),\n\t\t\t\tsecretKey: privateKey,\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair ED25519\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'ED25519';\n\t}\n\n\t/**\n\t * Generate a new random Ed25519 keypair\n\t */\n\tstatic generate(): Ed25519Keypair {\n\t\tconst secretKey = ed25519.utils.randomSecretKey();\n\t\treturn new Ed25519Keypair({\n\t\t\tpublicKey: ed25519.getPublicKey(secretKey),\n\t\t\tsecretKey,\n\t\t});\n\t}\n\n\t/**\n\t * Create a Ed25519 keypair from a raw secret key byte array, also known as seed.\n\t * This is NOT the private scalar which is result of hashing and bit clamping of\n\t * the raw secret key.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key as a byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Ed25519Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeHaneulPrivateKey(secretKey);\n\n\t\t\tif (decoded.scheme !== 'ED25519') {\n\t\t\t\tthrow new Error(`Expected a ED25519 keypair, got ${decoded.scheme}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst secretKeyLength = secretKey.length;\n\t\tif (secretKeyLength !== PRIVATE_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Wrong secretKey size. Expected ${PRIVATE_KEY_SIZE} bytes, got ${secretKeyLength}.`,\n\t\t\t);\n\t\t}\n\t\tconst keypair = {\n\t\t\tpublicKey: ed25519.getPublicKey(secretKey),\n\t\t\tsecretKey,\n\t\t};\n\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('haneul validation');\n\t\t\tconst signature = ed25519.sign(signData, secretKey);\n\t\t\tif (!ed25519.verify(signature, signData, keypair.publicKey)) {\n\t\t\t\tthrow new Error('provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Ed25519Keypair(keypair);\n\t}\n\n\t/**\n\t * The public key for this Ed25519 keypair\n\t */\n\tgetPublicKey(): Ed25519PublicKey {\n\t\treturn new Ed25519PublicKey(this.keypair.publicKey);\n\t}\n\n\t/**\n\t * The Bech32 secret key string for this Ed25519 keypair\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeHaneulPrivateKey(\n\t\t\tthis.keypair.secretKey.slice(0, PRIVATE_KEY_SIZE),\n\t\t\tthis.getKeyScheme(),\n\t\t);\n\t}\n\n\t/**\n\t * Return the signature for the provided data using Ed25519.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\treturn ed25519.sign(data, this.keypair.secretKey) as Uint8Array<ArrayBuffer>;\n\t}\n\n\t/**\n\t * Derive Ed25519 keypair from mnemonics and path. The mnemonics must be normalized\n\t * and validated against the english wordlist.\n\t *\n\t * If path is none, it will default to m/44'/8282'/0'/0'/0', otherwise the path must\n\t * be compliant to SLIP-0010 in form m/44'/8282'/{account_index}'/{change_index}'/{address_index}'.\n\t */\n\tstatic deriveKeypair(mnemonics: string, path?: string): Ed25519Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_ED25519_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidHardenedPath(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\tconst { key } = derivePath(path, mnemonicToSeedHex(mnemonics));\n\n\t\treturn Ed25519Keypair.fromSecretKey(key);\n\t}\n\n\t/**\n\t * Derive Ed25519 keypair from mnemonicSeed and path.\n\t *\n\t * If path is none, it will default to m/44'/8282'/0'/0'/0', otherwise the path must\n\t * be compliant to SLIP-0010 in form m/44'/8282'/{account_index}'/{change_index}'/{address_index}'.\n\t *\n\t * @param seed - The seed as a hex string or Uint8Array.\n\t */\n\tstatic deriveKeypairFromSeed(seed: string | Uint8Array, path?: string): Ed25519Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_ED25519_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidHardenedPath(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\tconst seedHex = typeof seed === 'string' ? seed : toHex(seed);\n\t\tconst { key } = derivePath(path, seedHex);\n\n\t\treturn Ed25519Keypair.fromSecretKey(key);\n\t}\n}\n"],"mappings":";;;;;;;;AAiBA,MAAa,kCAAkC;;;;AAe/C,IAAa,iBAAb,MAAa,uBAAuB,QAAQ;;;;;;;CAS3C,YAAY,SAA8B;AACzC,SAAO;AACP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QAAQ,KAAK,MAAM,KAAK,QAAQ,UAAU;;;;;;;;;CAUlD,OAAO,cAAc,WAAmB,MAA+B;AACtE,MAAI,QAAQ,KACX,QAAO;AAER,MAAI,CAAC,oBAAoB,KAAK,CAC7B,OAAM,IAAI,MAAM,0BAA0B;EAE3C,MAAM,EAAE,QAAQ,WAAW,MAAM,kBAAkB,UAAU,CAAC;AAE9D,SAAO,eAAe,cAAc,IAAI;;;;;;;;;;CAWzC,OAAO,sBAAsB,MAA2B,MAA+B;AACtF,MAAI,QAAQ,KACX,QAAO;AAER,MAAI,CAAC,oBAAoB,KAAK,CAC7B,OAAM,IAAI,MAAM,0BAA0B;EAE3C,MAAM,UAAU,OAAO,SAAS,WAAW,OAAO,MAAM,KAAK;EAC7D,MAAM,EAAE,QAAQ,WAAW,MAAM,QAAQ;AAEzC,SAAO,eAAe,cAAc,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../../src/keypairs/ed25519/publickey.ts"],"
|
|
1
|
+
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../../src/keypairs/ed25519/publickey.ts"],"mappings":";;;;AAmBA;;cAAa,gBAAA,SAAyB,SAAA;EAAA,OAC9B,IAAA;EAAA,QACC,IAAA;EAkCiB;;;;cA5Bb,KAAA,EAAO,iBAAA;EARkB;;;EA6B5B,MAAA,CAAO,SAAA,EAAW,gBAAA;EA5BpB;;;EAmCP,UAAA,CAAA,GAAc,UAAA,CAAW,WAAA;EA5Bb;;;EAmCZ,IAAA,CAAA;EAPA;;;EAcM,MAAA,CAAO,OAAA,EAAS,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;AAAA"}
|
|
@@ -11,21 +11,22 @@ type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> }
|
|
|
11
11
|
type BrowserPasswordProviderOptions = Pick<DeepPartial<PublicKeyCredentialCreationOptions>, DeepPartialConfigKeys> & Omit<Partial<PublicKeyCredentialCreationOptions>, DeepPartialConfigKeys | 'pubKeyCredParams' | 'challenge'>;
|
|
12
12
|
interface PasskeyProvider {
|
|
13
13
|
create(): Promise<RegistrationCredential>;
|
|
14
|
-
get(challenge: Uint8Array): Promise<AuthenticationCredential>;
|
|
14
|
+
get(challenge: Uint8Array, credentialId?: Uint8Array): Promise<AuthenticationCredential>;
|
|
15
15
|
}
|
|
16
16
|
declare class BrowserPasskeyProvider implements PasskeyProvider {
|
|
17
17
|
#private;
|
|
18
18
|
constructor(name: string, options: BrowserPasswordProviderOptions);
|
|
19
19
|
create(): Promise<RegistrationCredential>;
|
|
20
|
-
get(challenge: Uint8Array): Promise<AuthenticationCredential>;
|
|
20
|
+
get(challenge: Uint8Array, credentialId?: Uint8Array): Promise<AuthenticationCredential>;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* @experimental
|
|
24
|
-
* A passkey signer used for signing transactions. This is a client side implementation for [SIP-9](https://github.
|
|
24
|
+
* A passkey signer used for signing transactions. This is a client side implementation for [SIP-9](https://github.com/haneul-foundation/sips/blob/main/sips/sip-9.md).
|
|
25
25
|
*/
|
|
26
26
|
declare class PasskeyKeypair extends Signer {
|
|
27
27
|
private publicKey;
|
|
28
28
|
private provider;
|
|
29
|
+
private credentialId?;
|
|
29
30
|
/**
|
|
30
31
|
* Get the key scheme of passkey,
|
|
31
32
|
*/
|
|
@@ -44,7 +45,13 @@ declare class PasskeyKeypair extends Signer {
|
|
|
44
45
|
* If there are existing passkey wallet, use `signAndRecover` to identify the correct
|
|
45
46
|
* public key and then initialize the instance. See usage in `signAndRecover`.
|
|
46
47
|
*/
|
|
47
|
-
constructor(publicKey: Uint8Array, provider: PasskeyProvider);
|
|
48
|
+
constructor(publicKey: Uint8Array, provider: PasskeyProvider, credentialId?: Uint8Array);
|
|
49
|
+
/**
|
|
50
|
+
* Return the credential ID for this passkey, if available.
|
|
51
|
+
* The credential ID is captured when creating a new passkey via `getPasskeyInstance`
|
|
52
|
+
* and can be used to constrain which credential the browser selects during signing.
|
|
53
|
+
*/
|
|
54
|
+
getCredentialId(): Uint8Array | undefined;
|
|
48
55
|
/**
|
|
49
56
|
* Creates an instance of Passkey signer invoking the passkey from navigator.
|
|
50
57
|
* Note that this will invoke the passkey device to create a fresh credential.
|
|
@@ -93,7 +100,7 @@ declare class PasskeyKeypair extends Signer {
|
|
|
93
100
|
* const testMessage2 = new TextEncoder().encode('Hello world 2!');
|
|
94
101
|
* const possiblePks2 = await PasskeyKeypair.signAndRecover(provider, testMessage2);
|
|
95
102
|
* const commonPk = findCommonPublicKey(possiblePks, possiblePks2);
|
|
96
|
-
* const signer = new PasskeyKeypair(
|
|
103
|
+
* const signer = new PasskeyKeypair(commonPk.toRawBytes(), provider);
|
|
97
104
|
* ```
|
|
98
105
|
*
|
|
99
106
|
* @param provider - the passkey provider.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keypair.d.mts","names":[],"sources":["../../../src/keypairs/passkey/keypair.ts"],"
|
|
1
|
+
{"version":3,"file":"keypair.d.mts","names":[],"sources":["../../../src/keypairs/passkey/keypair.ts"],"mappings":";;;;;;;;KAsBK,qBAAA;AAAA,KAEA,WAAA,MAAiB,CAAA,gCAEP,CAAA,IAAK,WAAA,CAAY,CAAA,CAAE,CAAA,OAE/B,CAAA;AAAA,KAES,8BAAA,GAAiC,IAAA,CAC5C,WAAA,CAAY,kCAAA,GACZ,qBAAA,IAEA,IAAA,CACC,OAAA,CAAQ,kCAAA,GACR,qBAAA;AAAA,UAGe,eAAA;EAChB,MAAA,IAAU,OAAA,CAAQ,sBAAA;EAClB,GAAA,CAAI,SAAA,EAAW,UAAA,EAAY,YAAA,GAAe,UAAA,GAAa,OAAA,CAAQ,wBAAA;AAAA;AAAA,cAInD,sBAAA,YAAkC,eAAA;EAAA;cAIlC,IAAA,UAAc,OAAA,EAAS,8BAAA;EAK7B,MAAA,CAAA,GAAU,OAAA,CAAQ,sBAAA;EA4BlB,GAAA,CAAI,SAAA,EAAW,UAAA,EAAY,YAAA,GAAe,UAAA,GAAa,OAAA,CAAQ,wBAAA;AAAA;;;;;cAkBzD,cAAA,SAAuB,MAAA;EAAA,QAC3B,SAAA;EAAA,QACA,QAAA;EAAA,QACA,YAAA;EA7EW;;;EAkFnB,YAAA,CAAA,GAAgB,eAAA;EAhFb;;AAEJ;;;;;;;;;;;;cAgGa,SAAA,EAAW,UAAA,EAAY,QAAA,EAAU,eAAA,EAAiB,YAAA,GAAe,UAAA;EAhGjC;;;;;EA4G5C,eAAA,CAAA,GAAmB,UAAA;EAvGV;;;;AAIV;;;;EAJU,OAmHI,kBAAA,CAAmB,QAAA,EAAU,eAAA,GAAkB,OAAA,CAAQ,cAAA;EA7GrD;;;EA+Hf,YAAA,CAAA,GAAgB,SAAA;EA/H8C;;;;EAuIxD,IAAA,CAAK,IAAA,EAAM,UAAA,GAAU,OAAA,CAAA,UAAA,CAAA,WAAA;EAvI3B;;;;EAiLM,cAAA,CAAe,KAAA,EAAO,UAAA,EAAY,MAAA,EAAQ,WAAA,GAAc,OAAA,CAAQ,kBAAA;EAjLf;;;;AAIxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAJwD,OAmO1C,cAAA,CACZ,QAAA,EAAU,eAAA,EACV,OAAA,EAAS,UAAA,GACP,OAAA,CAAQ,SAAA;AAAA;;AA3KZ;;;;;;;iBAwMgB,mBAAA,CAAoB,IAAA,EAAM,SAAA,IAAa,IAAA,EAAM,SAAA,KAAc,SAAA"}
|
|
@@ -45,17 +45,21 @@ var BrowserPasskeyProvider = class {
|
|
|
45
45
|
}
|
|
46
46
|
} });
|
|
47
47
|
}
|
|
48
|
-
async get(challenge) {
|
|
48
|
+
async get(challenge, credentialId) {
|
|
49
49
|
return await navigator.credentials.get({ publicKey: {
|
|
50
50
|
challenge,
|
|
51
51
|
userVerification: this.#options.authenticatorSelection?.userVerification || "required",
|
|
52
|
-
timeout: this.#options.timeout ?? 6e4
|
|
52
|
+
timeout: this.#options.timeout ?? 6e4,
|
|
53
|
+
...credentialId && { allowCredentials: [{
|
|
54
|
+
type: "public-key",
|
|
55
|
+
id: credentialId
|
|
56
|
+
}] }
|
|
53
57
|
} });
|
|
54
58
|
}
|
|
55
59
|
};
|
|
56
60
|
/**
|
|
57
61
|
* @experimental
|
|
58
|
-
* A passkey signer used for signing transactions. This is a client side implementation for [SIP-9](https://github.
|
|
62
|
+
* A passkey signer used for signing transactions. This is a client side implementation for [SIP-9](https://github.com/haneul-foundation/sips/blob/main/sips/sip-9.md).
|
|
59
63
|
*/
|
|
60
64
|
var PasskeyKeypair = class PasskeyKeypair extends Signer {
|
|
61
65
|
/**
|
|
@@ -78,10 +82,19 @@ var PasskeyKeypair = class PasskeyKeypair extends Signer {
|
|
|
78
82
|
* If there are existing passkey wallet, use `signAndRecover` to identify the correct
|
|
79
83
|
* public key and then initialize the instance. See usage in `signAndRecover`.
|
|
80
84
|
*/
|
|
81
|
-
constructor(publicKey, provider) {
|
|
85
|
+
constructor(publicKey, provider, credentialId) {
|
|
82
86
|
super();
|
|
83
87
|
this.publicKey = publicKey;
|
|
84
88
|
this.provider = provider;
|
|
89
|
+
this.credentialId = credentialId;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Return the credential ID for this passkey, if available.
|
|
93
|
+
* The credential ID is captured when creating a new passkey via `getPasskeyInstance`
|
|
94
|
+
* and can be used to constrain which credential the browser selects during signing.
|
|
95
|
+
*/
|
|
96
|
+
getCredentialId() {
|
|
97
|
+
return this.credentialId;
|
|
85
98
|
}
|
|
86
99
|
/**
|
|
87
100
|
* Creates an instance of Passkey signer invoking the passkey from navigator.
|
|
@@ -97,7 +110,7 @@ var PasskeyKeypair = class PasskeyKeypair extends Signer {
|
|
|
97
110
|
else {
|
|
98
111
|
const derSPKI = credential.response.getPublicKey();
|
|
99
112
|
const pubkeyUncompressed = parseDerSPKI(new Uint8Array(derSPKI));
|
|
100
|
-
return new PasskeyKeypair(p256.Point.fromBytes(pubkeyUncompressed).toBytes(true), provider);
|
|
113
|
+
return new PasskeyKeypair(p256.Point.fromBytes(pubkeyUncompressed).toBytes(true), provider, new Uint8Array(credential.rawId));
|
|
101
114
|
}
|
|
102
115
|
}
|
|
103
116
|
/**
|
|
@@ -111,7 +124,7 @@ var PasskeyKeypair = class PasskeyKeypair extends Signer {
|
|
|
111
124
|
* This is sent to passkey as the challenge field.
|
|
112
125
|
*/
|
|
113
126
|
async sign(data) {
|
|
114
|
-
const credential = await this.provider.get(data);
|
|
127
|
+
const credential = await this.provider.get(data, this.credentialId);
|
|
115
128
|
const authenticatorData = new Uint8Array(credential.response.authenticatorData);
|
|
116
129
|
const clientDataJSON = new Uint8Array(credential.response.clientDataJSON);
|
|
117
130
|
const clientDataJSONString = new TextDecoder().decode(clientDataJSON);
|
|
@@ -168,7 +181,7 @@ var PasskeyKeypair = class PasskeyKeypair extends Signer {
|
|
|
168
181
|
* const testMessage2 = new TextEncoder().encode('Hello world 2!');
|
|
169
182
|
* const possiblePks2 = await PasskeyKeypair.signAndRecover(provider, testMessage2);
|
|
170
183
|
* const commonPk = findCommonPublicKey(possiblePks, possiblePks2);
|
|
171
|
-
* const signer = new PasskeyKeypair(
|
|
184
|
+
* const signer = new PasskeyKeypair(commonPk.toRawBytes(), provider);
|
|
172
185
|
* ```
|
|
173
186
|
*
|
|
174
187
|
* @param provider - the passkey provider.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keypair.mjs","names":["#name","#options","secp256r1"],"sources":["../../../src/keypairs/passkey/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toBase64 } from '@haneullabs/bcs';\nimport { p256 as secp256r1 } from '@noble/curves/nist.js';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { sha256 } from '@noble/hashes/sha2.js';\nimport { randomBytes } from '@noble/hashes/utils.js';\n\nimport { PasskeyAuthenticator } from '../../bcs/bcs.js';\nimport type { IntentScope, SignatureWithBytes } from '../../cryptography/index.js';\nimport { messageWithIntent, SIGNATURE_SCHEME_TO_FLAG, Signer } from '../../cryptography/index.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport {\n\tparseDerSPKI,\n\tPASSKEY_PUBLIC_KEY_SIZE,\n\tPASSKEY_SIGNATURE_SIZE,\n\tPasskeyPublicKey,\n} from './publickey.js';\nimport type { AuthenticationCredential, RegistrationCredential } from './types.js';\n\ntype DeepPartialConfigKeys = 'rp' | 'user' | 'authenticatorSelection';\n\ntype DeepPartial<T> = T extends object\n\t? {\n\t\t\t[P in keyof T]?: DeepPartial<T[P]>;\n\t\t}\n\t: T;\n\nexport type BrowserPasswordProviderOptions = Pick<\n\tDeepPartial<PublicKeyCredentialCreationOptions>,\n\tDeepPartialConfigKeys\n> &\n\tOmit<\n\t\tPartial<PublicKeyCredentialCreationOptions>,\n\t\tDeepPartialConfigKeys | 'pubKeyCredParams' | 'challenge'\n\t>;\n\nexport interface PasskeyProvider {\n\tcreate(): Promise<RegistrationCredential>;\n\tget(challenge: Uint8Array): Promise<AuthenticationCredential>;\n}\n\n// Default browser implementation\nexport class BrowserPasskeyProvider implements PasskeyProvider {\n\t#name: string;\n\t#options: BrowserPasswordProviderOptions;\n\n\tconstructor(name: string, options: BrowserPasswordProviderOptions) {\n\t\tthis.#name = name;\n\t\tthis.#options = options;\n\t}\n\n\tasync create(): Promise<RegistrationCredential> {\n\t\treturn (await navigator.credentials.create({\n\t\t\tpublicKey: {\n\t\t\t\ttimeout: this.#options.timeout ?? 60000,\n\t\t\t\t...this.#options,\n\t\t\t\trp: {\n\t\t\t\t\tname: this.#name,\n\t\t\t\t\t...this.#options.rp,\n\t\t\t\t},\n\t\t\t\tuser: {\n\t\t\t\t\tname: this.#name,\n\t\t\t\t\tdisplayName: this.#name,\n\t\t\t\t\t...this.#options.user,\n\t\t\t\t\tid: randomBytes(10) as BufferSource,\n\t\t\t\t},\n\t\t\t\tchallenge: new TextEncoder().encode('Create passkey wallet on Haneul'),\n\t\t\t\tpubKeyCredParams: [{ alg: -7, type: 'public-key' }],\n\t\t\t\tauthenticatorSelection: {\n\t\t\t\t\tauthenticatorAttachment: 'cross-platform',\n\t\t\t\t\tresidentKey: 'required',\n\t\t\t\t\trequireResidentKey: true,\n\t\t\t\t\tuserVerification: 'required',\n\t\t\t\t\t...this.#options.authenticatorSelection,\n\t\t\t\t},\n\t\t\t},\n\t\t})) as RegistrationCredential;\n\t}\n\n\tasync get(challenge: Uint8Array): Promise<AuthenticationCredential> {\n\t\treturn (await navigator.credentials.get({\n\t\t\tpublicKey: {\n\t\t\t\tchallenge: challenge as BufferSource,\n\t\t\t\tuserVerification: this.#options.authenticatorSelection?.userVerification || 'required',\n\t\t\t\ttimeout: this.#options.timeout ?? 60000,\n\t\t\t},\n\t\t})) as AuthenticationCredential;\n\t}\n}\n\n/**\n * @experimental\n * A passkey signer used for signing transactions. This is a client side implementation for [SIP-9](https://github.co./haneul-foundation/sips/blob/main/sips/sip-9.md).\n */\nexport class PasskeyKeypair extends Signer {\n\tprivate publicKey: Uint8Array;\n\tprivate provider: PasskeyProvider;\n\n\t/**\n\t * Get the key scheme of passkey,\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Passkey';\n\t}\n\n\t/**\n\t * Creates an instance of Passkey signer. If no passkey wallet had created before,\n\t * use `getPasskeyInstance`. For example:\n\t * ```\n\t * let provider = new BrowserPasskeyProvider('Haneul Passkey Example',{\n\t * \t rpName: 'Haneul Passkey Example',\n\t * \t rpId: window.location.hostname,\n\t * } as BrowserPasswordProviderOptions);\n\t * const signer = await PasskeyKeypair.getPasskeyInstance(provider);\n\t * ```\n\t *\n\t * If there are existing passkey wallet, use `signAndRecover` to identify the correct\n\t * public key and then initialize the instance. See usage in `signAndRecover`.\n\t */\n\tconstructor(publicKey: Uint8Array, provider: PasskeyProvider) {\n\t\tsuper();\n\t\tthis.publicKey = publicKey;\n\t\tthis.provider = provider;\n\t}\n\n\t/**\n\t * Creates an instance of Passkey signer invoking the passkey from navigator.\n\t * Note that this will invoke the passkey device to create a fresh credential.\n\t * Should only be called if passkey wallet is created for the first time.\n\t *\n\t * @param provider - the passkey provider.\n\t * @returns the passkey instance.\n\t */\n\tstatic async getPasskeyInstance(provider: PasskeyProvider): Promise<PasskeyKeypair> {\n\t\t// create a passkey secp256r1 with the provider.\n\t\tconst credential = await provider.create();\n\n\t\tif (!credential.response.getPublicKey()) {\n\t\t\tthrow new Error('Invalid credential create response');\n\t\t} else {\n\t\t\tconst derSPKI = credential.response.getPublicKey()!;\n\t\t\tconst pubkeyUncompressed = parseDerSPKI(new Uint8Array(derSPKI));\n\t\t\tconst pubkey = secp256r1.Point.fromBytes(pubkeyUncompressed);\n\t\t\tconst pubkeyCompressed = pubkey.toBytes(true);\n\t\t\treturn new PasskeyKeypair(pubkeyCompressed, provider);\n\t\t}\n\t}\n\n\t/**\n\t * Return the public key for this passkey.\n\t */\n\tgetPublicKey(): PublicKey {\n\t\treturn new PasskeyPublicKey(this.publicKey);\n\t}\n\n\t/**\n\t * Return the signature for the provided data (i.e. blake2b(intent_message)).\n\t * This is sent to passkey as the challenge field.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\t// asks the passkey to sign over challenge as the data.\n\t\tconst credential = await this.provider.get(data);\n\n\t\t// parse authenticatorData (as bytes), clientDataJSON (decoded as string).\n\t\tconst authenticatorData = new Uint8Array(credential.response.authenticatorData);\n\t\tconst clientDataJSON = new Uint8Array(credential.response.clientDataJSON); // response.clientDataJSON is already UTF-8 encoded JSON\n\t\tconst decoder = new TextDecoder();\n\t\tconst clientDataJSONString: string = decoder.decode(clientDataJSON);\n\n\t\tconst sig = secp256r1.Signature.fromBytes(new Uint8Array(credential.response.signature), 'der');\n\t\tconst normalizedSig = sig.hasHighS()\n\t\t\t? new secp256r1.Signature(sig.r, secp256r1.Point.Fn.neg(sig.s))\n\t\t\t: sig;\n\n\t\tconst normalized = normalizedSig.toBytes('compact');\n\n\t\tif (\n\t\t\tnormalized.length !== PASSKEY_SIGNATURE_SIZE ||\n\t\t\tthis.publicKey.length !== PASSKEY_PUBLIC_KEY_SIZE\n\t\t) {\n\t\t\tthrow new Error('Invalid signature or public key length');\n\t\t}\n\n\t\t// construct userSignature as flag || sig || pubkey for the secp256r1 signature.\n\t\tconst arr = new Uint8Array(1 + normalized.length + this.publicKey.length);\n\t\tarr.set([SIGNATURE_SCHEME_TO_FLAG['Secp256r1']]);\n\t\tarr.set(normalized, 1);\n\t\tarr.set(this.publicKey, 1 + normalized.length);\n\n\t\t// serialize all fields into a passkey signature according to https://github.co./haneul-foundation/sips/blob/main/sips/sip-9.md#signature-encoding\n\t\treturn PasskeyAuthenticator.serialize({\n\t\t\tauthenticatorData: authenticatorData,\n\t\t\tclientDataJson: clientDataJSONString,\n\t\t\tuserSignature: arr,\n\t\t}).toBytes();\n\t}\n\n\t/**\n\t * This overrides the base class implementation that accepts the raw bytes and signs its\n\t * digest of the intent message, then serialize it with the passkey flag.\n\t */\n\tasync signWithIntent(bytes: Uint8Array, intent: IntentScope): Promise<SignatureWithBytes> {\n\t\t// prepend it into an intent message and computes the digest.\n\t\tconst intentMessage = messageWithIntent(intent, bytes);\n\t\tconst digest = blake2b(intentMessage, { dkLen: 32 });\n\n\t\t// sign the digest.\n\t\tconst signature = await this.sign(digest);\n\n\t\t// prepend with the passkey flag.\n\t\tconst serializedSignature = new Uint8Array(1 + signature.length);\n\t\tserializedSignature.set([SIGNATURE_SCHEME_TO_FLAG[this.getKeyScheme()]]);\n\t\tserializedSignature.set(signature, 1);\n\t\treturn {\n\t\t\tsignature: toBase64(serializedSignature),\n\t\t\tbytes: toBase64(bytes),\n\t\t};\n\t}\n\n\t/**\n\t * Given a message, asks the passkey device to sign it and return all (up to 4) possible public keys.\n\t * See: https://bitcoin.stackexchange.com/questions/81232/how-is-public-key-extracted-from-message-digital-signature-address\n\t *\n\t * This is useful if the user previously created passkey wallet with the origin, but the wallet session\n\t * does not have the public key / address. By calling this method twice with two different messages, the\n\t * wallet can compare the returned public keys and uniquely identify the previously created passkey wallet\n\t * using `findCommonPublicKey`.\n\t *\n\t * Alternatively, one call can be made and all possible public keys should be checked onchain to see if\n\t * there is any assets.\n\t *\n\t * Once the correct public key is identified, a passkey instance can then be initialized with this public key.\n\t *\n\t * Example usage to recover wallet with two signing calls:\n\t * ```\n\t * let provider = new BrowserPasskeyProvider('Haneul Passkey Example',{\n\t * rpName: 'Haneul Passkey Example',\n\t * \t rpId: window.location.hostname,\n\t * } as BrowserPasswordProviderOptions);\n\t * const testMessage = new TextEncoder().encode('Hello world!');\n\t * const possiblePks = await PasskeyKeypair.signAndRecover(provider, testMessage);\n\t * const testMessage2 = new TextEncoder().encode('Hello world 2!');\n\t * const possiblePks2 = await PasskeyKeypair.signAndRecover(provider, testMessage2);\n\t * const commonPk = findCommonPublicKey(possiblePks, possiblePks2);\n\t * const signer = new PasskeyKeypair(provider, commonPk.toRawBytes());\n\t * ```\n\t *\n\t * @param provider - the passkey provider.\n\t * @param message - the message to sign.\n\t * @returns all possible public keys.\n\t */\n\tstatic async signAndRecover(\n\t\tprovider: PasskeyProvider,\n\t\tmessage: Uint8Array,\n\t): Promise<PublicKey[]> {\n\t\tconst credential = await provider.get(message);\n\t\tconst fullMessage = messageFromAssertionResponse(credential.response);\n\t\tconst sig = secp256r1.Signature.fromBytes(new Uint8Array(credential.response.signature), 'der');\n\n\t\tconst res = [];\n\t\tconst msgHash = sha256(fullMessage);\n\t\tfor (let i = 0; i < 4; i++) {\n\t\t\tconst s = sig.addRecoveryBit(i);\n\t\t\ttry {\n\t\t\t\tconst pubkey = s.recoverPublicKey(msgHash);\n\t\t\t\tconst pk = new PasskeyPublicKey(pubkey.toBytes(true));\n\t\t\t\tres.push(pk);\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n}\n\n/**\n * Finds the unique public key that exists in both arrays, throws error if the common\n * pubkey does not equal to one.\n *\n * @param arr1 - The first pubkeys array.\n * @param arr2 - The second pubkeys array.\n * @returns The only common pubkey in both arrays.\n */\nexport function findCommonPublicKey(arr1: PublicKey[], arr2: PublicKey[]): PublicKey {\n\tconst matchingPubkeys: PublicKey[] = [];\n\tfor (const pubkey1 of arr1) {\n\t\tfor (const pubkey2 of arr2) {\n\t\t\tif (pubkey1.equals(pubkey2)) {\n\t\t\t\tmatchingPubkeys.push(pubkey1);\n\t\t\t}\n\t\t}\n\t}\n\tif (matchingPubkeys.length !== 1) {\n\t\tthrow new Error('No unique public key found');\n\t}\n\treturn matchingPubkeys[0];\n}\n\n/**\n * Constructs the message that the passkey signature is produced over as authenticatorData || sha256(clientDataJSON).\n */\nfunction messageFromAssertionResponse(response: AuthenticatorAssertionResponse): Uint8Array {\n\tconst authenticatorData = new Uint8Array(response.authenticatorData);\n\tconst clientDataJSON = new Uint8Array(response.clientDataJSON);\n\tconst clientDataJSONDigest = sha256(clientDataJSON);\n\treturn new Uint8Array([...authenticatorData, ...clientDataJSONDigest]);\n}\n"],"mappings":";;;;;;;;;;;;AA6CA,IAAa,yBAAb,MAA+D;CAC9D;CACA;CAEA,YAAY,MAAc,SAAyC;AAClE,QAAKA,OAAQ;AACb,QAAKC,UAAW;;CAGjB,MAAM,SAA0C;AAC/C,SAAQ,MAAM,UAAU,YAAY,OAAO,EAC1C,WAAW;GACV,SAAS,MAAKA,QAAS,WAAW;GAClC,GAAG,MAAKA;GACR,IAAI;IACH,MAAM,MAAKD;IACX,GAAG,MAAKC,QAAS;IACjB;GACD,MAAM;IACL,MAAM,MAAKD;IACX,aAAa,MAAKA;IAClB,GAAG,MAAKC,QAAS;IACjB,IAAI,YAAY,GAAG;IACnB;GACD,WAAW,IAAI,aAAa,CAAC,OAAO,kCAAkC;GACtE,kBAAkB,CAAC;IAAE,KAAK;IAAI,MAAM;IAAc,CAAC;GACnD,wBAAwB;IACvB,yBAAyB;IACzB,aAAa;IACb,oBAAoB;IAC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ACP;;;AAGF,SAAO;;;;;;;;;;;AAYT,SAAgB,oBAAoB,MAAmB,MAA8B;CACpF,MAAM,kBAA+B,EAAE;AACvC,MAAK,MAAM,WAAW,KACrB,MAAK,MAAM,WAAW,KACrB,KAAI,QAAQ,OAAO,QAAQ,CAC1B,iBAAgB,KAAK,QAAQ;AAIhC,KAAI,gBAAgB,WAAW,EAC9B,OAAM,IAAI,MAAM,6BAA6B;AAE9C,QAAO,gBAAgB;;;;;AAMxB,SAAS,6BAA6B,UAAsD;CAC3F,MAAM,oBAAoB,IAAI,WAAW,SAAS,kBAAkB;CAEpE,MAAM,uBAAuB,OADN,IAAI,WAAW,SAAS,eAAe,CACX;AACnD,QAAO,IAAI,WAAW,CAAC,GAAG,mBAAmB,GAAG,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"keypair.mjs","names":["#name","#options","secp256r1"],"sources":["../../../src/keypairs/passkey/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toBase64 } from '@haneullabs/bcs';\nimport { p256 as secp256r1 } from '@noble/curves/nist.js';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { sha256 } from '@noble/hashes/sha2.js';\nimport { randomBytes } from '@noble/hashes/utils.js';\n\nimport { PasskeyAuthenticator } from '../../bcs/bcs.js';\nimport type { IntentScope, SignatureWithBytes } from '../../cryptography/index.js';\nimport { messageWithIntent, SIGNATURE_SCHEME_TO_FLAG, Signer } from '../../cryptography/index.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport {\n\tparseDerSPKI,\n\tPASSKEY_PUBLIC_KEY_SIZE,\n\tPASSKEY_SIGNATURE_SIZE,\n\tPasskeyPublicKey,\n} from './publickey.js';\nimport type { AuthenticationCredential, RegistrationCredential } from './types.js';\n\ntype DeepPartialConfigKeys = 'rp' | 'user' | 'authenticatorSelection';\n\ntype DeepPartial<T> = T extends object\n\t? {\n\t\t\t[P in keyof T]?: DeepPartial<T[P]>;\n\t\t}\n\t: T;\n\nexport type BrowserPasswordProviderOptions = Pick<\n\tDeepPartial<PublicKeyCredentialCreationOptions>,\n\tDeepPartialConfigKeys\n> &\n\tOmit<\n\t\tPartial<PublicKeyCredentialCreationOptions>,\n\t\tDeepPartialConfigKeys | 'pubKeyCredParams' | 'challenge'\n\t>;\n\nexport interface PasskeyProvider {\n\tcreate(): Promise<RegistrationCredential>;\n\tget(challenge: Uint8Array, credentialId?: Uint8Array): Promise<AuthenticationCredential>;\n}\n\n// Default browser implementation\nexport class BrowserPasskeyProvider implements PasskeyProvider {\n\t#name: string;\n\t#options: BrowserPasswordProviderOptions;\n\n\tconstructor(name: string, options: BrowserPasswordProviderOptions) {\n\t\tthis.#name = name;\n\t\tthis.#options = options;\n\t}\n\n\tasync create(): Promise<RegistrationCredential> {\n\t\treturn (await navigator.credentials.create({\n\t\t\tpublicKey: {\n\t\t\t\ttimeout: this.#options.timeout ?? 60000,\n\t\t\t\t...this.#options,\n\t\t\t\trp: {\n\t\t\t\t\tname: this.#name,\n\t\t\t\t\t...this.#options.rp,\n\t\t\t\t},\n\t\t\t\tuser: {\n\t\t\t\t\tname: this.#name,\n\t\t\t\t\tdisplayName: this.#name,\n\t\t\t\t\t...this.#options.user,\n\t\t\t\t\tid: randomBytes(10) as BufferSource,\n\t\t\t\t},\n\t\t\t\tchallenge: new TextEncoder().encode('Create passkey wallet on Haneul'),\n\t\t\t\tpubKeyCredParams: [{ alg: -7, type: 'public-key' }],\n\t\t\t\tauthenticatorSelection: {\n\t\t\t\t\tauthenticatorAttachment: 'cross-platform',\n\t\t\t\t\tresidentKey: 'required',\n\t\t\t\t\trequireResidentKey: true,\n\t\t\t\t\tuserVerification: 'required',\n\t\t\t\t\t...this.#options.authenticatorSelection,\n\t\t\t\t},\n\t\t\t},\n\t\t})) as RegistrationCredential;\n\t}\n\n\tasync get(challenge: Uint8Array, credentialId?: Uint8Array): Promise<AuthenticationCredential> {\n\t\treturn (await navigator.credentials.get({\n\t\t\tpublicKey: {\n\t\t\t\tchallenge: challenge as BufferSource,\n\t\t\t\tuserVerification: this.#options.authenticatorSelection?.userVerification || 'required',\n\t\t\t\ttimeout: this.#options.timeout ?? 60000,\n\t\t\t\t...(credentialId && {\n\t\t\t\t\tallowCredentials: [{ type: 'public-key' as const, id: credentialId as BufferSource }],\n\t\t\t\t}),\n\t\t\t},\n\t\t})) as AuthenticationCredential;\n\t}\n}\n\n/**\n * @experimental\n * A passkey signer used for signing transactions. This is a client side implementation for [SIP-9](https://github.com/haneul-foundation/sips/blob/main/sips/sip-9.md).\n */\nexport class PasskeyKeypair extends Signer {\n\tprivate publicKey: Uint8Array;\n\tprivate provider: PasskeyProvider;\n\tprivate credentialId?: Uint8Array;\n\n\t/**\n\t * Get the key scheme of passkey,\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Passkey';\n\t}\n\n\t/**\n\t * Creates an instance of Passkey signer. If no passkey wallet had created before,\n\t * use `getPasskeyInstance`. For example:\n\t * ```\n\t * let provider = new BrowserPasskeyProvider('Haneul Passkey Example',{\n\t * \t rpName: 'Haneul Passkey Example',\n\t * \t rpId: window.location.hostname,\n\t * } as BrowserPasswordProviderOptions);\n\t * const signer = await PasskeyKeypair.getPasskeyInstance(provider);\n\t * ```\n\t *\n\t * If there are existing passkey wallet, use `signAndRecover` to identify the correct\n\t * public key and then initialize the instance. See usage in `signAndRecover`.\n\t */\n\tconstructor(publicKey: Uint8Array, provider: PasskeyProvider, credentialId?: Uint8Array) {\n\t\tsuper();\n\t\tthis.publicKey = publicKey;\n\t\tthis.provider = provider;\n\t\tthis.credentialId = credentialId;\n\t}\n\n\t/**\n\t * Return the credential ID for this passkey, if available.\n\t * The credential ID is captured when creating a new passkey via `getPasskeyInstance`\n\t * and can be used to constrain which credential the browser selects during signing.\n\t */\n\tgetCredentialId(): Uint8Array | undefined {\n\t\treturn this.credentialId;\n\t}\n\n\t/**\n\t * Creates an instance of Passkey signer invoking the passkey from navigator.\n\t * Note that this will invoke the passkey device to create a fresh credential.\n\t * Should only be called if passkey wallet is created for the first time.\n\t *\n\t * @param provider - the passkey provider.\n\t * @returns the passkey instance.\n\t */\n\tstatic async getPasskeyInstance(provider: PasskeyProvider): Promise<PasskeyKeypair> {\n\t\t// create a passkey secp256r1 with the provider.\n\t\tconst credential = await provider.create();\n\n\t\tif (!credential.response.getPublicKey()) {\n\t\t\tthrow new Error('Invalid credential create response');\n\t\t} else {\n\t\t\tconst derSPKI = credential.response.getPublicKey()!;\n\t\t\tconst pubkeyUncompressed = parseDerSPKI(new Uint8Array(derSPKI));\n\t\t\tconst pubkey = secp256r1.Point.fromBytes(pubkeyUncompressed);\n\t\t\tconst pubkeyCompressed = pubkey.toBytes(true);\n\t\t\treturn new PasskeyKeypair(pubkeyCompressed, provider, new Uint8Array(credential.rawId));\n\t\t}\n\t}\n\n\t/**\n\t * Return the public key for this passkey.\n\t */\n\tgetPublicKey(): PublicKey {\n\t\treturn new PasskeyPublicKey(this.publicKey);\n\t}\n\n\t/**\n\t * Return the signature for the provided data (i.e. blake2b(intent_message)).\n\t * This is sent to passkey as the challenge field.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\t// asks the passkey to sign over challenge as the data.\n\t\tconst credential = await this.provider.get(data, this.credentialId);\n\n\t\t// parse authenticatorData (as bytes), clientDataJSON (decoded as string).\n\t\tconst authenticatorData = new Uint8Array(credential.response.authenticatorData);\n\t\tconst clientDataJSON = new Uint8Array(credential.response.clientDataJSON); // response.clientDataJSON is already UTF-8 encoded JSON\n\t\tconst decoder = new TextDecoder();\n\t\tconst clientDataJSONString: string = decoder.decode(clientDataJSON);\n\n\t\tconst sig = secp256r1.Signature.fromBytes(new Uint8Array(credential.response.signature), 'der');\n\t\tconst normalizedSig = sig.hasHighS()\n\t\t\t? new secp256r1.Signature(sig.r, secp256r1.Point.Fn.neg(sig.s))\n\t\t\t: sig;\n\n\t\tconst normalized = normalizedSig.toBytes('compact');\n\n\t\tif (\n\t\t\tnormalized.length !== PASSKEY_SIGNATURE_SIZE ||\n\t\t\tthis.publicKey.length !== PASSKEY_PUBLIC_KEY_SIZE\n\t\t) {\n\t\t\tthrow new Error('Invalid signature or public key length');\n\t\t}\n\n\t\t// construct userSignature as flag || sig || pubkey for the secp256r1 signature.\n\t\tconst arr = new Uint8Array(1 + normalized.length + this.publicKey.length);\n\t\tarr.set([SIGNATURE_SCHEME_TO_FLAG['Secp256r1']]);\n\t\tarr.set(normalized, 1);\n\t\tarr.set(this.publicKey, 1 + normalized.length);\n\n\t\t// serialize all fields into a passkey signature according to https://github.com/haneul-foundation/sips/blob/main/sips/sip-9.md#signature-encoding\n\t\treturn PasskeyAuthenticator.serialize({\n\t\t\tauthenticatorData: authenticatorData,\n\t\t\tclientDataJson: clientDataJSONString,\n\t\t\tuserSignature: arr,\n\t\t}).toBytes();\n\t}\n\n\t/**\n\t * This overrides the base class implementation that accepts the raw bytes and signs its\n\t * digest of the intent message, then serialize it with the passkey flag.\n\t */\n\tasync signWithIntent(bytes: Uint8Array, intent: IntentScope): Promise<SignatureWithBytes> {\n\t\t// prepend it into an intent message and computes the digest.\n\t\tconst intentMessage = messageWithIntent(intent, bytes);\n\t\tconst digest = blake2b(intentMessage, { dkLen: 32 });\n\n\t\t// sign the digest.\n\t\tconst signature = await this.sign(digest);\n\n\t\t// prepend with the passkey flag.\n\t\tconst serializedSignature = new Uint8Array(1 + signature.length);\n\t\tserializedSignature.set([SIGNATURE_SCHEME_TO_FLAG[this.getKeyScheme()]]);\n\t\tserializedSignature.set(signature, 1);\n\t\treturn {\n\t\t\tsignature: toBase64(serializedSignature),\n\t\t\tbytes: toBase64(bytes),\n\t\t};\n\t}\n\n\t/**\n\t * Given a message, asks the passkey device to sign it and return all (up to 4) possible public keys.\n\t * See: https://bitcoin.stackexchange.com/questions/81232/how-is-public-key-extracted-from-message-digital-signature-address\n\t *\n\t * This is useful if the user previously created passkey wallet with the origin, but the wallet session\n\t * does not have the public key / address. By calling this method twice with two different messages, the\n\t * wallet can compare the returned public keys and uniquely identify the previously created passkey wallet\n\t * using `findCommonPublicKey`.\n\t *\n\t * Alternatively, one call can be made and all possible public keys should be checked onchain to see if\n\t * there is any assets.\n\t *\n\t * Once the correct public key is identified, a passkey instance can then be initialized with this public key.\n\t *\n\t * Example usage to recover wallet with two signing calls:\n\t * ```\n\t * let provider = new BrowserPasskeyProvider('Haneul Passkey Example',{\n\t * rpName: 'Haneul Passkey Example',\n\t * \t rpId: window.location.hostname,\n\t * } as BrowserPasswordProviderOptions);\n\t * const testMessage = new TextEncoder().encode('Hello world!');\n\t * const possiblePks = await PasskeyKeypair.signAndRecover(provider, testMessage);\n\t * const testMessage2 = new TextEncoder().encode('Hello world 2!');\n\t * const possiblePks2 = await PasskeyKeypair.signAndRecover(provider, testMessage2);\n\t * const commonPk = findCommonPublicKey(possiblePks, possiblePks2);\n\t * const signer = new PasskeyKeypair(commonPk.toRawBytes(), provider);\n\t * ```\n\t *\n\t * @param provider - the passkey provider.\n\t * @param message - the message to sign.\n\t * @returns all possible public keys.\n\t */\n\tstatic async signAndRecover(\n\t\tprovider: PasskeyProvider,\n\t\tmessage: Uint8Array,\n\t): Promise<PublicKey[]> {\n\t\tconst credential = await provider.get(message);\n\t\tconst fullMessage = messageFromAssertionResponse(credential.response);\n\t\tconst sig = secp256r1.Signature.fromBytes(new Uint8Array(credential.response.signature), 'der');\n\n\t\tconst res = [];\n\t\tconst msgHash = sha256(fullMessage);\n\t\tfor (let i = 0; i < 4; i++) {\n\t\t\tconst s = sig.addRecoveryBit(i);\n\t\t\ttry {\n\t\t\t\tconst pubkey = s.recoverPublicKey(msgHash);\n\t\t\t\tconst pk = new PasskeyPublicKey(pubkey.toBytes(true));\n\t\t\t\tres.push(pk);\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n}\n\n/**\n * Finds the unique public key that exists in both arrays, throws error if the common\n * pubkey does not equal to one.\n *\n * @param arr1 - The first pubkeys array.\n * @param arr2 - The second pubkeys array.\n * @returns The only common pubkey in both arrays.\n */\nexport function findCommonPublicKey(arr1: PublicKey[], arr2: PublicKey[]): PublicKey {\n\tconst matchingPubkeys: PublicKey[] = [];\n\tfor (const pubkey1 of arr1) {\n\t\tfor (const pubkey2 of arr2) {\n\t\t\tif (pubkey1.equals(pubkey2)) {\n\t\t\t\tmatchingPubkeys.push(pubkey1);\n\t\t\t}\n\t\t}\n\t}\n\tif (matchingPubkeys.length !== 1) {\n\t\tthrow new Error('No unique public key found');\n\t}\n\treturn matchingPubkeys[0];\n}\n\n/**\n * Constructs the message that the passkey signature is produced over as authenticatorData || sha256(clientDataJSON).\n */\nfunction messageFromAssertionResponse(response: AuthenticatorAssertionResponse): Uint8Array {\n\tconst authenticatorData = new Uint8Array(response.authenticatorData);\n\tconst clientDataJSON = new Uint8Array(response.clientDataJSON);\n\tconst clientDataJSONDigest = sha256(clientDataJSON);\n\treturn new Uint8Array([...authenticatorData, ...clientDataJSONDigest]);\n}\n"],"mappings":";;;;;;;;;;;;AA6CA,IAAa,yBAAb,MAA+D;CAC9D;CACA;CAEA,YAAY,MAAc,SAAyC;AAClE,QAAKA,OAAQ;AACb,QAAKC,UAAW;;CAGjB,MAAM,SAA0C;AAC/C,SAAQ,MAAM,UAAU,YAAY,OAAO,EAC1C,WAAW;GACV,SAAS,MAAKA,QAAS,WAAW;GAClC,GAAG,MAAKA;GACR,IAAI;IACH,MAAM,MAAKD;IACX,GAAG,MAAKC,QAAS;IACjB;GACD,MAAM;IACL,MAAM,MAAKD;IACX,aAAa,MAAKA;IAClB,GAAG,MAAKC,QAAS;IACjB,IAAI,YAAY,GAAG;IACnB;GACD,WAAW,IAAI,aAAa,CAAC,OAAO,kCAAkC;GACtE,kBAAkB,CAAC;IAAE,KAAK;IAAI,MAAM;IAAc,CAAC;GACnD,wBAAwB;IACvB,yBAAyB;IACzB,aAAa;IACb,oBAAoB;IACp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OAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;GAC3B,MAAM,IAAI,IAAI,eAAe,EAAE;AAC/B,OAAI;IAEH,MAAM,KAAK,IAAI,iBADA,EAAE,iBAAiB,QAAQ,CACH,QAAQ,KAAK,CAAC;AACrD,QAAI,KAAK,GAAG;WACL;AACP;;;AAGF,SAAO;;;;;;;;;;;AAYT,SAAgB,oBAAoB,MAAmB,MAA8B;CACpF,MAAM,kBAA+B,EAAE;AACvC,MAAK,MAAM,WAAW,KACrB,MAAK,MAAM,WAAW,KACrB,KAAI,QAAQ,OAAO,QAAQ,CAC1B,iBAAgB,KAAK,QAAQ;AAIhC,KAAI,gBAAgB,WAAW,EAC9B,OAAM,IAAI,MAAM,6BAA6B;AAE9C,QAAO,gBAAgB;;;;;AAMxB,SAAS,6BAA6B,UAAsD;CAC3F,MAAM,oBAAoB,IAAI,WAAW,SAAS,kBAAkB;CAEpE,MAAM,uBAAuB,OADN,IAAI,WAAW,SAAS,eAAe,CACX;AACnD,QAAO,IAAI,WAAW,CAAC,GAAG,mBAAmB,GAAG,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../../src/keypairs/passkey/publickey.ts"],"
|
|
1
|
+
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../../src/keypairs/passkey/publickey.ts"],"mappings":";;;;;;cAiEa,gBAAA,SAAyB,SAAA;EAAA,OAC9B,IAAA;EAAA,QACC,IAAA;EAgDc;;;;cA1CV,KAAA,EAAO,iBAAA;EA0CuD;;;EArBjE,MAAA,CAAO,SAAA,EAAW,gBAAA;;;;EAO3B,UAAA,CAAA,GAAc,UAAA,CAAW,WAAA;;;;EAOzB,IAAA,CAAA;;;;EAOM,MAAA,CAAO,OAAA,EAAS,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../../src/keypairs/passkey/types.ts"],"
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../../src/keypairs/passkey/types.ts"],"mappings":";;AAMA;;UAAiB,wBAAA,SAAiC,mBAAA;EACjD,QAAA,EAAU,8BAAA;AAAA;;;;UAMM,sBAAA,SAA+B,mBAAA;EAC/C,QAAA,EAAU,gCAAA;AAAA"}
|
|
@@ -3,7 +3,7 @@ import { SignatureScheme } from "../../cryptography/signature-scheme.mjs";
|
|
|
3
3
|
import { Keypair } from "../../cryptography/keypair.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/keypairs/secp256k1/keypair.d.ts
|
|
6
|
-
declare const DEFAULT_SECP256K1_DERIVATION_PATH = "m/54'/
|
|
6
|
+
declare const DEFAULT_SECP256K1_DERIVATION_PATH = "m/54'/8282'/0'/0/0";
|
|
7
7
|
/**
|
|
8
8
|
* Secp256k1 Keypair data
|
|
9
9
|
*/
|
|
@@ -68,8 +68,8 @@ declare class Secp256k1Keypair extends Keypair {
|
|
|
68
68
|
* Derive Secp256k1 keypair from mnemonics and path. The mnemonics must be normalized
|
|
69
69
|
* and validated against the english wordlist.
|
|
70
70
|
*
|
|
71
|
-
* If path is none, it will default to m/54'/
|
|
72
|
-
* be compliant to BIP-32 in form m/54'/
|
|
71
|
+
* If path is none, it will default to m/54'/8282'/0'/0/0, otherwise the path must
|
|
72
|
+
* be compliant to BIP-32 in form m/54'/8282'/{account_index}'/{change_index}/{address_index}.
|
|
73
73
|
*/
|
|
74
74
|
static deriveKeypair(mnemonics: string, path?: string): Secp256k1Keypair;
|
|
75
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keypair.d.mts","names":[],"sources":["../../../src/keypairs/secp256k1/keypair.ts"],"
|
|
1
|
+
{"version":3,"file":"keypair.d.mts","names":[],"sources":["../../../src/keypairs/secp256k1/keypair.ts"],"mappings":";;;;;cAaa,iCAAA;;AAAb;;UAKiB,oBAAA;EAChB,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,UAAA;AAAA;;;;cAMC,gBAAA,SAAyB,OAAA;EAAA,QAC7B,OAAA;EAPR;;;;AAMD;;cASa,OAAA,GAAU,oBAAA;EAAA;;;EAetB,YAAA,CAAA,GAAgB,eAAA;EA2Bb;;;EAAA,OApBI,QAAA,CAAA,GAAY,gBAAA;EAuEF;;;;;;;;;;;;EAAA,OAtDV,aAAA,CACN,SAAA,EAAW,UAAA,WACX,OAAA;IAAY,cAAA;EAAA,IACV,gBAAA;EApBI;;;;;EAAA,OAkDA,QAAA,CAAS,IAAA,EAAM,UAAA,GAAa,gBAAA;EA/BlC;;;EAuCD,YAAA,CAAA,GAAgB,SAAA;EARA;;;EAchB,YAAA,CAAA;EAAA;;;EAOM,IAAA,CAAK,IAAA,EAAM,UAAA,GAAU,OAAA,CAAA,UAAA,CAAA,WAAA;EAAA;;;;;;;EAAA,OAapB,aAAA,CAAc,SAAA,UAAmB,IAAA,YAAgB,gBAAA;AAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { isValidBIP32Path, mnemonicToSeed } from "../../cryptography/mnemonics.mjs";
|
|
2
|
-
import { Keypair,
|
|
2
|
+
import { Keypair, decodeHaneulPrivateKey, encodeHaneulPrivateKey } from "../../cryptography/keypair.mjs";
|
|
3
3
|
import { Secp256k1PublicKey } from "./publickey.mjs";
|
|
4
4
|
import { blake2b } from "@noble/hashes/blake2.js";
|
|
5
5
|
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
6
6
|
import { HDKey } from "@scure/bip32";
|
|
7
7
|
|
|
8
8
|
//#region src/keypairs/secp256k1/keypair.ts
|
|
9
|
-
const DEFAULT_SECP256K1_DERIVATION_PATH = "m/54'/
|
|
9
|
+
const DEFAULT_SECP256K1_DERIVATION_PATH = "m/54'/8282'/0'/0/0";
|
|
10
10
|
/**
|
|
11
11
|
* An Secp256k1 Keypair used for signing transactions.
|
|
12
12
|
*/
|
|
@@ -54,7 +54,7 @@ var Secp256k1Keypair = class Secp256k1Keypair extends Keypair {
|
|
|
54
54
|
*/
|
|
55
55
|
static fromSecretKey(secretKey, options) {
|
|
56
56
|
if (typeof secretKey === "string") {
|
|
57
|
-
const decoded =
|
|
57
|
+
const decoded = decodeHaneulPrivateKey(secretKey);
|
|
58
58
|
if (decoded.scheme !== "Secp256k1") throw new Error(`Expected a Secp256k1 keypair, got ${decoded.scheme}`);
|
|
59
59
|
return this.fromSecretKey(decoded.secretKey, options);
|
|
60
60
|
}
|
|
@@ -93,7 +93,7 @@ var Secp256k1Keypair = class Secp256k1Keypair extends Keypair {
|
|
|
93
93
|
* The Bech32 secret key string for this Secp256k1 keypair
|
|
94
94
|
*/
|
|
95
95
|
getSecretKey() {
|
|
96
|
-
return
|
|
96
|
+
return encodeHaneulPrivateKey(this.keypair.secretKey, this.getKeyScheme());
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* Return the signature for the provided data.
|
|
@@ -105,8 +105,8 @@ var Secp256k1Keypair = class Secp256k1Keypair extends Keypair {
|
|
|
105
105
|
* Derive Secp256k1 keypair from mnemonics and path. The mnemonics must be normalized
|
|
106
106
|
* and validated against the english wordlist.
|
|
107
107
|
*
|
|
108
|
-
* If path is none, it will default to m/54'/
|
|
109
|
-
* be compliant to BIP-32 in form m/54'/
|
|
108
|
+
* If path is none, it will default to m/54'/8282'/0'/0/0, otherwise the path must
|
|
109
|
+
* be compliant to BIP-32 in form m/54'/8282'/{account_index}'/{change_index}/{address_index}.
|
|
110
110
|
*/
|
|
111
111
|
static deriveKeypair(mnemonics, path) {
|
|
112
112
|
if (path == null) path = DEFAULT_SECP256K1_DERIVATION_PATH;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keypair.mjs","names":[],"sources":["../../../src/keypairs/secp256k1/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { secp256k1 } from '@noble/curves/secp256k1.js';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { HDKey } from '@scure/bip32';\n\nimport {
|
|
1
|
+
{"version":3,"file":"keypair.mjs","names":[],"sources":["../../../src/keypairs/secp256k1/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { secp256k1 } from '@noble/curves/secp256k1.js';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { HDKey } from '@scure/bip32';\n\nimport { decodeHaneulPrivateKey, encodeHaneulPrivateKey, Keypair } from '../../cryptography/keypair.js';\nimport { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { Secp256k1PublicKey } from './publickey.js';\n\nexport const DEFAULT_SECP256K1_DERIVATION_PATH = \"m/54'/8282'/0'/0/0\";\n\n/**\n * Secp256k1 Keypair data\n */\nexport interface Secp256k1KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Secp256k1 Keypair used for signing transactions.\n */\nexport class Secp256k1Keypair extends Keypair {\n\tprivate keypair: Secp256k1KeypairData;\n\n\t/**\n\t * Create a new keypair instance.\n\t * Generate random keypair if no {@link Secp256k1Keypair} is provided.\n\t *\n\t * @param keypair secp256k1 keypair\n\t */\n\tconstructor(keypair?: Secp256k1KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tconst secretKey: Uint8Array = secp256k1.utils.randomSecretKey();\n\t\t\tconst publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);\n\n\t\t\tthis.keypair = { publicKey, secretKey };\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair Secp256k1\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256k1';\n\t}\n\n\t/**\n\t * Generate a new random keypair\n\t */\n\tstatic generate(): Secp256k1Keypair {\n\t\treturn new Secp256k1Keypair();\n\t}\n\n\t/**\n\t * Create a keypair from a raw secret key byte array.\n\t *\n\t * This method should only be used to recreate a keypair from a previously\n\t * generated secret key. Generating keypairs from a random seed should be done\n\t * with the {@link Keypair.fromSeed} method.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Secp256k1Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeHaneulPrivateKey(secretKey);\n\n\t\t\tif (decoded.scheme !== 'Secp256k1') {\n\t\t\t\tthrow new Error(`Expected a Secp256k1 keypair, got ${decoded.scheme}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst publicKey: Uint8Array = secp256k1.getPublicKey(secretKey, true);\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('haneul validation');\n\t\t\tconst msgHash = blake2b(signData, { dkLen: 32 });\n\t\t\tconst signature = secp256k1.sign(msgHash, secretKey, { prehash: false });\n\n\t\t\tif (!secp256k1.verify(signature, msgHash, publicKey, { lowS: true, prehash: false })) {\n\t\t\t\tthrow new Error('Provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Secp256k1Keypair({ publicKey, secretKey });\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed.\n\t *\n\t * @param seed seed byte array\n\t */\n\tstatic fromSeed(seed: Uint8Array): Secp256k1Keypair {\n\t\tconst publicKey = secp256k1.getPublicKey(seed, true);\n\t\treturn new Secp256k1Keypair({ publicKey, secretKey: seed });\n\t}\n\n\t/**\n\t * The public key for this keypair\n\t */\n\tgetPublicKey(): PublicKey {\n\t\treturn new Secp256k1PublicKey(this.keypair.publicKey);\n\t}\n\t/**\n\t * The Bech32 secret key string for this Secp256k1 keypair\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeHaneulPrivateKey(this.keypair.secretKey, this.getKeyScheme());\n\t}\n\n\t/**\n\t * Return the signature for the provided data.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\treturn secp256k1.sign(data, this.keypair.secretKey, {\n\t\t\tlowS: true,\n\t\t}) as Uint8Array<ArrayBuffer>;\n\t}\n\n\t/**\n\t * Derive Secp256k1 keypair from mnemonics and path. The mnemonics must be normalized\n\t * and validated against the english wordlist.\n\t *\n\t * If path is none, it will default to m/54'/8282'/0'/0/0, otherwise the path must\n\t * be compliant to BIP-32 in form m/54'/8282'/{account_index}'/{change_index}/{address_index}.\n\t */\n\tstatic deriveKeypair(mnemonics: string, path?: string): Secp256k1Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_SECP256K1_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidBIP32Path(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\tconst key = HDKey.fromMasterSeed(mnemonicToSeed(mnemonics)).derive(path);\n\t\tif (key.publicKey == null || key.privateKey == null) {\n\t\t\tthrow new Error('Invalid key');\n\t\t}\n\t\treturn new Secp256k1Keypair({\n\t\t\tpublicKey: key.publicKey,\n\t\t\tsecretKey: key.privateKey,\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;AAaA,MAAa,oCAAoC;;;;AAajD,IAAa,mBAAb,MAAa,yBAAyB,QAAQ;;;;;;;CAS7C,YAAY,SAAgC;AAC3C,SAAO;AACP,MAAI,QACH,MAAK,UAAU;OACT;GACN,MAAM,YAAwB,UAAU,MAAM,iBAAiB;AAG/D,QAAK,UAAU;IAAE,WAFa,UAAU,aAAa,WAAW,KAAK;IAEzC;IAAW;;;;;;CAOzC,eAAgC;AAC/B,SAAO;;;;;CAMR,OAAO,WAA6B;AACnC,SAAO,IAAI,kBAAkB;;;;;;;;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,IAAI,cAAc,KAC9C,OAAM,IAAI,MAAM,cAAc;AAE/B,SAAO,IAAI,iBAAiB;GAC3B,WAAW,IAAI;GACf,WAAW,IAAI;GACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../../src/keypairs/secp256k1/publickey.ts"],"
|
|
1
|
+
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../../src/keypairs/secp256k1/publickey.ts"],"mappings":";;;;AAmBA;;cAAa,kBAAA,SAA2B,SAAA;EAAA,OAChC,IAAA;EAAA,QACC,IAAA;EAkCiB;;;;cA5Bb,KAAA,EAAO,iBAAA;EARoB;;;EA6B9B,MAAA,CAAO,SAAA,EAAW,kBAAA;EA5BpB;;;EAmCP,UAAA,CAAA,GAAc,UAAA,CAAW,WAAA;EA5Bb;;;EAmCZ,IAAA,CAAA;EAPA;;;EAcM,MAAA,CAAO,OAAA,EAAS,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;AAAA"}
|
|
@@ -3,7 +3,7 @@ import { SignatureScheme } from "../../cryptography/signature-scheme.mjs";
|
|
|
3
3
|
import { Keypair } from "../../cryptography/keypair.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/keypairs/secp256r1/keypair.d.ts
|
|
6
|
-
declare const DEFAULT_SECP256R1_DERIVATION_PATH = "m/74'/
|
|
6
|
+
declare const DEFAULT_SECP256R1_DERIVATION_PATH = "m/74'/8282'/0'/0/0";
|
|
7
7
|
/**
|
|
8
8
|
* Secp256r1 Keypair data
|
|
9
9
|
*/
|
|
@@ -68,8 +68,8 @@ declare class Secp256r1Keypair extends Keypair {
|
|
|
68
68
|
* Derive Secp256r1 keypair from mnemonics and path. The mnemonics must be normalized
|
|
69
69
|
* and validated against the english wordlist.
|
|
70
70
|
*
|
|
71
|
-
* If path is none, it will default to m/74'/
|
|
72
|
-
* be compliant to BIP-32 in form m/74'/
|
|
71
|
+
* If path is none, it will default to m/74'/8282'/0'/0/0, otherwise the path must
|
|
72
|
+
* be compliant to BIP-32 in form m/74'/8282'/{account_index}'/{change_index}/{address_index}.
|
|
73
73
|
*/
|
|
74
74
|
static deriveKeypair(mnemonics: string, path?: string): Secp256r1Keypair;
|
|
75
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keypair.d.mts","names":[],"sources":["../../../src/keypairs/secp256r1/keypair.ts"],"
|
|
1
|
+
{"version":3,"file":"keypair.d.mts","names":[],"sources":["../../../src/keypairs/secp256r1/keypair.ts"],"mappings":";;;;;cAaa,iCAAA;;AAAb;;UAKiB,oBAAA;EAChB,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,UAAA;AAAA;;;;cAMC,gBAAA,SAAyB,OAAA;EAAA,QAC7B,OAAA;EAPR;;;;AAMD;;cASa,OAAA,GAAU,oBAAA;EAAA;;;EAetB,YAAA,CAAA,GAAgB,eAAA;EA2Bb;;;EAAA,OApBI,QAAA,CAAA,GAAY,gBAAA;EAwEF;;;;;;;;;;;;EAAA,OAvDV,aAAA,CACN,SAAA,EAAW,UAAA,WACX,OAAA;IAAY,cAAA;EAAA,IACV,gBAAA;EApBI;;;;;EAAA,OAkDA,QAAA,CAAS,IAAA,EAAM,UAAA,GAAa,gBAAA;EA/BlC;;;EAuCD,YAAA,CAAA,GAAgB,SAAA;EARA;;;EAehB,YAAA,CAAA;EAAA;;;EAOM,IAAA,CAAK,IAAA,EAAM,UAAA,GAAU,OAAA,CAAA,UAAA,CAAA,WAAA;EAAA;;;;;;;EAAA,OAapB,aAAA,CAAc,SAAA,UAAmB,IAAA,YAAgB,gBAAA;AAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { isValidBIP32Path, mnemonicToSeed } from "../../cryptography/mnemonics.mjs";
|
|
2
|
-
import { Keypair,
|
|
2
|
+
import { Keypair, decodeHaneulPrivateKey, encodeHaneulPrivateKey } from "../../cryptography/keypair.mjs";
|
|
3
3
|
import { Secp256r1PublicKey } from "./publickey.mjs";
|
|
4
4
|
import { blake2b } from "@noble/hashes/blake2.js";
|
|
5
5
|
import { p256 } from "@noble/curves/nist.js";
|
|
6
6
|
import { HDKey } from "@scure/bip32";
|
|
7
7
|
|
|
8
8
|
//#region src/keypairs/secp256r1/keypair.ts
|
|
9
|
-
const DEFAULT_SECP256R1_DERIVATION_PATH = "m/74'/
|
|
9
|
+
const DEFAULT_SECP256R1_DERIVATION_PATH = "m/74'/8282'/0'/0/0";
|
|
10
10
|
/**
|
|
11
11
|
* An Secp256r1 Keypair used for signing transactions.
|
|
12
12
|
*/
|
|
@@ -54,7 +54,7 @@ var Secp256r1Keypair = class Secp256r1Keypair extends Keypair {
|
|
|
54
54
|
*/
|
|
55
55
|
static fromSecretKey(secretKey, options) {
|
|
56
56
|
if (typeof secretKey === "string") {
|
|
57
|
-
const decoded =
|
|
57
|
+
const decoded = decodeHaneulPrivateKey(secretKey);
|
|
58
58
|
if (decoded.scheme !== "Secp256r1") throw new Error(`Expected a Secp256r1 keypair, got ${decoded.scheme}`);
|
|
59
59
|
return this.fromSecretKey(decoded.secretKey, options);
|
|
60
60
|
}
|
|
@@ -96,7 +96,7 @@ var Secp256r1Keypair = class Secp256r1Keypair extends Keypair {
|
|
|
96
96
|
* The Bech32 secret key string for this Secp256r1 keypair
|
|
97
97
|
*/
|
|
98
98
|
getSecretKey() {
|
|
99
|
-
return
|
|
99
|
+
return encodeHaneulPrivateKey(this.keypair.secretKey, this.getKeyScheme());
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Return the signature for the provided data.
|
|
@@ -108,8 +108,8 @@ var Secp256r1Keypair = class Secp256r1Keypair extends Keypair {
|
|
|
108
108
|
* Derive Secp256r1 keypair from mnemonics and path. The mnemonics must be normalized
|
|
109
109
|
* and validated against the english wordlist.
|
|
110
110
|
*
|
|
111
|
-
* If path is none, it will default to m/74'/
|
|
112
|
-
* be compliant to BIP-32 in form m/74'/
|
|
111
|
+
* If path is none, it will default to m/74'/8282'/0'/0/0, otherwise the path must
|
|
112
|
+
* be compliant to BIP-32 in form m/74'/8282'/{account_index}'/{change_index}/{address_index}.
|
|
113
113
|
*/
|
|
114
114
|
static deriveKeypair(mnemonics, path) {
|
|
115
115
|
if (path == null) path = DEFAULT_SECP256R1_DERIVATION_PATH;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keypair.mjs","names":["secp256r1"],"sources":["../../../src/keypairs/secp256r1/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { p256 as secp256r1 } from '@noble/curves/nist.js';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { HDKey } from '@scure/bip32';\n\nimport {
|
|
1
|
+
{"version":3,"file":"keypair.mjs","names":["secp256r1"],"sources":["../../../src/keypairs/secp256r1/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { p256 as secp256r1 } from '@noble/curves/nist.js';\nimport { blake2b } from '@noble/hashes/blake2.js';\nimport { HDKey } from '@scure/bip32';\n\nimport { decodeHaneulPrivateKey, encodeHaneulPrivateKey, Keypair } from '../../cryptography/keypair.js';\nimport { isValidBIP32Path, mnemonicToSeed } from '../../cryptography/mnemonics.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { Secp256r1PublicKey } from './publickey.js';\n\nexport const DEFAULT_SECP256R1_DERIVATION_PATH = \"m/74'/8282'/0'/0/0\";\n\n/**\n * Secp256r1 Keypair data\n */\nexport interface Secp256r1KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Secp256r1 Keypair used for signing transactions.\n */\nexport class Secp256r1Keypair extends Keypair {\n\tprivate keypair: Secp256r1KeypairData;\n\n\t/**\n\t * Create a new keypair instance.\n\t * Generate random keypair if no {@link Secp256r1Keypair} is provided.\n\t *\n\t * @param keypair Secp256r1 keypair\n\t */\n\tconstructor(keypair?: Secp256r1KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tconst secretKey: Uint8Array = secp256r1.utils.randomSecretKey();\n\t\t\tconst publicKey: Uint8Array = secp256r1.getPublicKey(secretKey, true);\n\n\t\t\tthis.keypair = { publicKey, secretKey };\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair Secp256r1\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256r1';\n\t}\n\n\t/**\n\t * Generate a new random keypair\n\t */\n\tstatic generate(): Secp256r1Keypair {\n\t\treturn new Secp256r1Keypair();\n\t}\n\n\t/**\n\t * Create a keypair from a raw secret key byte array.\n\t *\n\t * This method should only be used to recreate a keypair from a previously\n\t * generated secret key. Generating keypairs from a random seed should be done\n\t * with the {@link Keypair.fromSeed} method.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Secp256r1Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeHaneulPrivateKey(secretKey);\n\n\t\t\tif (decoded.scheme !== 'Secp256r1') {\n\t\t\t\tthrow new Error(`Expected a Secp256r1 keypair, got ${decoded.scheme}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst publicKey: Uint8Array = secp256r1.getPublicKey(secretKey, true);\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('haneul validation');\n\t\t\tconst msgHash = blake2b(signData, { dkLen: 32 });\n\t\t\tconst signature = secp256r1.sign(msgHash, secretKey, { lowS: true, prehash: false });\n\n\t\t\tif (!secp256r1.verify(signature, msgHash, publicKey, { lowS: true, prehash: false })) {\n\t\t\t\tthrow new Error('Provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Secp256r1Keypair({ publicKey, secretKey });\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed.\n\t *\n\t * @param seed seed byte array\n\t */\n\tstatic fromSeed(seed: Uint8Array): Secp256r1Keypair {\n\t\tconst publicKey = secp256r1.getPublicKey(seed, true);\n\t\treturn new Secp256r1Keypair({ publicKey, secretKey: seed });\n\t}\n\n\t/**\n\t * The public key for this keypair\n\t */\n\tgetPublicKey(): PublicKey {\n\t\treturn new Secp256r1PublicKey(this.keypair.publicKey);\n\t}\n\n\t/**\n\t * The Bech32 secret key string for this Secp256r1 keypair\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeHaneulPrivateKey(this.keypair.secretKey, this.getKeyScheme());\n\t}\n\n\t/**\n\t * Return the signature for the provided data.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\treturn secp256r1.sign(data, this.keypair.secretKey, {\n\t\t\tlowS: true,\n\t\t}) as Uint8Array<ArrayBuffer>;\n\t}\n\n\t/**\n\t * Derive Secp256r1 keypair from mnemonics and path. The mnemonics must be normalized\n\t * and validated against the english wordlist.\n\t *\n\t * If path is none, it will default to m/74'/8282'/0'/0/0, otherwise the path must\n\t * be compliant to BIP-32 in form m/74'/8282'/{account_index}'/{change_index}/{address_index}.\n\t */\n\tstatic deriveKeypair(mnemonics: string, path?: string): Secp256r1Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_SECP256R1_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidBIP32Path(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\t// We use HDKey which is hardcoded to use Secp256k1 but since we only need the 32 bytes for the private key it's okay to use here as well.\n\t\tconst privateKey = HDKey.fromMasterSeed(mnemonicToSeed(mnemonics)).derive(path).privateKey;\n\t\treturn Secp256r1Keypair.from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AuB;AACtB,SAAO,uBAAuB,KAAK,QAAQ,WAAW,KAAK,cAAc,CAAC;;;;;CAM3E,MAAM,KAAK,MAAkB;AAC5B,SAAOA,KAAU,KAAK,MAAM,KAAK,QAAQ,WAAW,EACnD,MAAM,MACN,CAAC;;;;;;;;;CAUH,OAAO,cAAc,WAAmB,MAAiC;AACxE,MAAI,QAAQ,KACX,QAAO;AAER,MAAI,CAAC,iBAAiB,KAAK,CAC1B,OAAM,IAAI,MAAM,0BAA0B;EAG3C,MAAM,aAAa,MAAM,eAAe,eAAe,UAAU,CAAC,CAAC,OAAO,KAAK,CAAC;AAChF,SAAO,iBAAiB,cAAc,WAAY"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../../src/keypairs/secp256r1/publickey.ts"],"
|
|
1
|
+
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../../src/keypairs/secp256r1/publickey.ts"],"mappings":";;;;AAgBA;;cAAa,kBAAA,SAA2B,SAAA;EAAA,OAChC,IAAA;EAAA,QACC,IAAA;EAkCiB;;;;cA5Bb,KAAA,EAAO,iBAAA;EARoB;;;EA6B9B,MAAA,CAAO,SAAA,EAAW,kBAAA;EA5BpB;;;EAmCP,UAAA,CAAA,GAAc,UAAA,CAAW,WAAA;EA5Bb;;;EAmCZ,IAAA,CAAA;EAPA;;;EAcM,MAAA,CAAO,OAAA,EAAS,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;AAAA"}
|