@haneullabs/haneul 2.5.2 → 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 +1 -2
- package/dist/cryptography/publickey.d.mts.map +1 -1
- package/dist/cryptography/publickey.mjs +7 -7
- 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 +0 -1
- 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 +7 -7
- 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 +26 -0
- 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.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/verify.d.mts.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/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 +5 -5
- 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/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/version.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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinWithBalance.mjs","names":["bcs","balance"],"sources":["../../../src/transactions/intents/CoinWithBalance.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { InferInput } from 'valibot';\nimport { bigint, object, parse, string } from 'valibot';\n\nimport { bcs } from '../../bcs/index.js';\nimport { normalizeStructTag } from '../../utils/haneul-types.js';\nimport { TransactionCommands } from '../Commands.js';\nimport type { Argument } from '../data/internal.js';\nimport { Inputs } from '../Inputs.js';\nimport type { BuildTransactionOptions } from '../resolve.js';\nimport type { Transaction, TransactionResult } from '../Transaction.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\nimport type { ClientWithCoreApi, HaneulClientTypes } from '../../client/index.js';\n\nexport const COIN_WITH_BALANCE = 'CoinWithBalance';\nconst SUI_TYPE = normalizeStructTag('0x2::haneul::HANEUL');\n\nexport function coinWithBalance({\n\ttype = SUI_TYPE,\n\tbalance,\n\tuseGasCoin = true,\n}: {\n\tbalance: bigint | number;\n\ttype?: string;\n\tuseGasCoin?: boolean;\n}): (tx: Transaction) => TransactionResult {\n\tlet coinResult: TransactionResult | null = null;\n\n\treturn (tx: Transaction) => {\n\t\tif (coinResult) {\n\t\t\treturn coinResult;\n\t\t}\n\n\t\ttx.addIntentResolver(COIN_WITH_BALANCE, resolveCoinBalance);\n\t\tconst coinType = type === 'gas' ? type : normalizeStructTag(type);\n\n\t\tcoinResult = tx.add(\n\t\t\tTransactionCommands.Intent({\n\t\t\t\tname: COIN_WITH_BALANCE,\n\t\t\t\tinputs: {},\n\t\t\t\tdata: {\n\t\t\t\t\ttype: coinType === SUI_TYPE && useGasCoin ? 'gas' : coinType,\n\t\t\t\t\tbalance: BigInt(balance),\n\t\t\t\t} satisfies InferInput<typeof CoinWithBalanceData>,\n\t\t\t}),\n\t\t);\n\n\t\treturn coinResult;\n\t};\n}\n\nconst CoinWithBalanceData = object({\n\ttype: string(),\n\tbalance: bigint(),\n});\n\nexport async function resolveCoinBalance(\n\ttransactionData: TransactionDataBuilder,\n\tbuildOptions: BuildTransactionOptions,\n\tnext: () => Promise<void>,\n) {\n\tconst coinTypes = new Set<string>();\n\tconst totalByType = new Map<string, bigint>();\n\n\tif (!transactionData.sender) {\n\t\tthrow new Error('Sender must be set to resolve CoinWithBalance');\n\t}\n\n\tfor (const command of transactionData.commands) {\n\t\tif (command.$kind === '$Intent' && command.$Intent.name === COIN_WITH_BALANCE) {\n\t\t\tconst { type, balance } = parse(CoinWithBalanceData, command.$Intent.data);\n\n\t\t\tif (type !== 'gas' && balance > 0n) {\n\t\t\t\tcoinTypes.add(type);\n\t\t\t}\n\n\t\t\ttotalByType.set(type, (totalByType.get(type) ?? 0n) + balance);\n\t\t}\n\t}\n\tconst usedIds = new Set<string>();\n\n\tfor (const input of transactionData.inputs) {\n\t\tif (input.Object?.ImmOrOwnedObject) {\n\t\t\tusedIds.add(input.Object.ImmOrOwnedObject.objectId);\n\t\t}\n\t\tif (input.UnresolvedObject?.objectId) {\n\t\t\tusedIds.add(input.UnresolvedObject.objectId);\n\t\t}\n\t}\n\n\tconst coinsByType = new Map<string, HaneulClientTypes.Coin[]>();\n\tconst addressBalanceByType = new Map<string, bigint>();\n\tconst client = buildOptions.client;\n\n\tif (!client) {\n\t\tthrow new Error(\n\t\t\t'Client must be provided to build or serialize transactions with CoinWithBalance intents',\n\t\t);\n\t}\n\n\tawait Promise.all([\n\t\t...[...coinTypes].map(async (coinType) => {\n\t\t\tconst { coins, addressBalance } = await getCoinsAndBalanceOfType({\n\t\t\t\tcoinType,\n\t\t\t\tbalance: totalByType.get(coinType)!,\n\t\t\t\tclient,\n\t\t\t\towner: transactionData.sender!,\n\t\t\t\tusedIds,\n\t\t\t});\n\n\t\t\tcoinsByType.set(coinType, coins);\n\t\t\taddressBalanceByType.set(coinType, addressBalance);\n\t\t}),\n\t\ttotalByType.has('gas')\n\t\t\t? await client.core\n\t\t\t\t\t.getBalance({\n\t\t\t\t\t\towner: transactionData.sender!,\n\t\t\t\t\t\tcoinType: SUI_TYPE,\n\t\t\t\t\t})\n\t\t\t\t\t.then(({ balance }) => {\n\t\t\t\t\t\taddressBalanceByType.set('gas', BigInt(balance.addressBalance));\n\t\t\t\t\t})\n\t\t\t: null,\n\t]);\n\n\tconst mergedCoins = new Map<string, Argument>();\n\n\tfor (const [index, transaction] of transactionData.commands.entries()) {\n\t\tif (transaction.$kind !== '$Intent' || transaction.$Intent.name !== COIN_WITH_BALANCE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst { type, balance } = transaction.$Intent.data as {\n\t\t\ttype: string;\n\t\t\tbalance: bigint;\n\t\t};\n\n\t\tif (balance === 0n) {\n\t\t\ttransactionData.replaceCommand(\n\t\t\t\tindex,\n\t\t\t\tTransactionCommands.MoveCall({\n\t\t\t\t\ttarget: '0x2::coin::zero',\n\t\t\t\t\ttypeArguments: [type === 'gas' ? SUI_TYPE : type],\n\t\t\t\t}),\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst commands = [];\n\n\t\tif (addressBalanceByType.get(type)! >= totalByType.get(type)!) {\n\t\t\tcommands.push(\n\t\t\t\tTransactionCommands.MoveCall({\n\t\t\t\t\ttarget: '0x2::coin::redeem_funds',\n\t\t\t\t\ttypeArguments: [type === 'gas' ? SUI_TYPE : type],\n\t\t\t\t\targuments: [\n\t\t\t\t\t\ttransactionData.addInput(\n\t\t\t\t\t\t\t'withdrawal',\n\t\t\t\t\t\t\tInputs.FundsWithdrawal({\n\t\t\t\t\t\t\t\treservation: {\n\t\t\t\t\t\t\t\t\t$kind: 'MaxAmountU64',\n\t\t\t\t\t\t\t\t\tMaxAmountU64: String(balance),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\ttypeArg: {\n\t\t\t\t\t\t\t\t\t$kind: 'Balance',\n\t\t\t\t\t\t\t\t\tBalance: type === 'gas' ? SUI_TYPE : type,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\twithdrawFrom: {\n\t\t\t\t\t\t\t\t\t$kind: 'Sender',\n\t\t\t\t\t\t\t\t\tSender: true,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t);\n\t\t} else {\n\t\t\tif (!mergedCoins.has(type)) {\n\t\t\t\tconst addressBalance = addressBalanceByType.get(type) ?? 0n;\n\t\t\t\tconst coinType = type === 'gas' ? SUI_TYPE : type;\n\n\t\t\t\tlet baseCoin: Argument;\n\t\t\t\tlet restCoins: Argument[];\n\n\t\t\t\tif (type === 'gas') {\n\t\t\t\t\tbaseCoin = { $kind: 'GasCoin', GasCoin: true };\n\t\t\t\t\trestCoins = [];\n\t\t\t\t} else {\n\t\t\t\t\t[baseCoin, ...restCoins] = coinsByType.get(type)!.map((coin) =>\n\t\t\t\t\t\ttransactionData.addInput(\n\t\t\t\t\t\t\t'object',\n\t\t\t\t\t\t\tInputs.ObjectRef({\n\t\t\t\t\t\t\t\tobjectId: coin.objectId,\n\t\t\t\t\t\t\t\tdigest: coin.digest,\n\t\t\t\t\t\t\t\tversion: coin.version,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (addressBalance > 0n) {\n\t\t\t\t\tcommands.push(\n\t\t\t\t\t\tTransactionCommands.MoveCall({\n\t\t\t\t\t\t\ttarget: '0x2::coin::redeem_funds',\n\t\t\t\t\t\t\ttypeArguments: [coinType],\n\t\t\t\t\t\t\targuments: [\n\t\t\t\t\t\t\t\ttransactionData.addInput(\n\t\t\t\t\t\t\t\t\t'withdrawal',\n\t\t\t\t\t\t\t\t\tInputs.FundsWithdrawal({\n\t\t\t\t\t\t\t\t\t\treservation: {\n\t\t\t\t\t\t\t\t\t\t\t$kind: 'MaxAmountU64',\n\t\t\t\t\t\t\t\t\t\t\tMaxAmountU64: String(addressBalance),\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\ttypeArg: {\n\t\t\t\t\t\t\t\t\t\t\t$kind: 'Balance',\n\t\t\t\t\t\t\t\t\t\t\tBalance: coinType,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\twithdrawFrom: {\n\t\t\t\t\t\t\t\t\t\t\t$kind: 'Sender',\n\t\t\t\t\t\t\t\t\t\t\tSender: true,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\n\t\t\t\t\tcommands.push(\n\t\t\t\t\t\tTransactionCommands.MergeCoins(baseCoin, [\n\t\t\t\t\t\t\t{ $kind: 'Result', Result: index + commands.length - 1 },\n\t\t\t\t\t\t\t...restCoins,\n\t\t\t\t\t\t]),\n\t\t\t\t\t);\n\t\t\t\t} else if (restCoins.length > 0) {\n\t\t\t\t\tcommands.push(TransactionCommands.MergeCoins(baseCoin, restCoins));\n\t\t\t\t}\n\n\t\t\t\tmergedCoins.set(type, baseCoin);\n\t\t\t}\n\n\t\t\tcommands.push(\n\t\t\t\tTransactionCommands.SplitCoins(mergedCoins.get(type)!, [\n\t\t\t\t\ttransactionData.addInput('pure', Inputs.Pure(bcs.u64().serialize(balance))),\n\t\t\t\t]),\n\t\t\t);\n\t\t}\n\n\t\ttransactionData.replaceCommand(index, commands);\n\n\t\ttransactionData.mapArguments((arg, _command, commandIndex) => {\n\t\t\tif (commandIndex >= index && commandIndex < index + commands.length) {\n\t\t\t\treturn arg;\n\t\t\t}\n\n\t\t\tif (arg.$kind === 'Result' && arg.Result === index) {\n\t\t\t\treturn {\n\t\t\t\t\t$kind: 'NestedResult',\n\t\t\t\t\tNestedResult: [index + commands.length - 1, 0],\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn arg;\n\t\t});\n\t}\n\n\treturn next();\n}\n\nasync function getCoinsAndBalanceOfType({\n\tcoinType,\n\tbalance,\n\tclient,\n\towner,\n\tusedIds,\n}: {\n\tcoinType: string;\n\tbalance: bigint;\n\tclient: ClientWithCoreApi;\n\towner: string;\n\tusedIds: Set<string>;\n}): Promise<{\n\tcoins: HaneulClientTypes.Coin[];\n\tbalance: bigint;\n\taddressBalance: bigint;\n\tcoinBalance: bigint;\n}> {\n\tlet remainingBalance = balance;\n\tconst coins: HaneulClientTypes.Coin[] = [];\n\tconst balanceRequest = client.core.getBalance({ owner, coinType }).then(({ balance }) => {\n\t\tremainingBalance -= BigInt(balance.addressBalance);\n\n\t\treturn balance;\n\t});\n\n\tconst [allCoins, balanceResponse] = await Promise.all([loadMoreCoins(), balanceRequest]);\n\n\tif (BigInt(balanceResponse.balance) < balance) {\n\t\tthrow new Error(\n\t\t\t`Insufficient balance of ${coinType} for owner ${owner}. Required: ${balance}, Available: ${\n\t\t\t\tbalance - remainingBalance\n\t\t\t}`,\n\t\t);\n\t}\n\n\treturn {\n\t\tcoins: allCoins,\n\t\tbalance: BigInt(balanceResponse.coinBalance),\n\t\taddressBalance: BigInt(balanceResponse.addressBalance),\n\t\tcoinBalance: BigInt(balanceResponse.coinBalance),\n\t};\n\n\tasync function loadMoreCoins(cursor: string | null = null): Promise<HaneulClientTypes.Coin[]> {\n\t\tconst {\n\t\t\tobjects,\n\t\t\thasNextPage,\n\t\t\tcursor: nextCursor,\n\t\t} = await client.core.listCoins({\n\t\t\towner,\n\t\t\tcoinType,\n\t\t\tcursor,\n\t\t});\n\n\t\tawait balanceRequest;\n\n\t\tif (remainingBalance > 0n) {\n\t\t\tfor (const coin of objects) {\n\t\t\t\tif (usedIds.has(coin.objectId)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst coinBalance = BigInt(coin.balance);\n\n\t\t\t\tcoins.push(coin);\n\t\t\t\tremainingBalance -= coinBalance;\n\n\t\t\t\tif (remainingBalance <= 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (hasNextPage) {\n\t\t\t\treturn loadMoreCoins(nextCursor);\n\t\t\t}\n\t\t}\n\n\t\treturn coins;\n\t}\n}\n"],"mappings":";;;;;;;AAgBA,MAAa,oBAAoB;AACjC,MAAM,WAAW,mBAAmB,sBAAsB;AAE1D,SAAgB,gBAAgB,EAC/B,OAAO,UACP,SACA,aAAa,QAK6B;CAC1C,IAAI,aAAuC;AAE3C,SAAQ,OAAoB;AAC3B,MAAI,WACH,QAAO;AAGR,KAAG,kBAAkB,mBAAmB,mBAAmB;EAC3D,MAAM,WAAW,SAAS,QAAQ,OAAO,mBAAmB,KAAK;AAEjE,eAAa,GAAG,IACf,oBAAoB,OAAO;GAC1B,MAAM;GACN,QAAQ,EAAE;GACV,MAAM;IACL,MAAM,aAAa,YAAY,aAAa,QAAQ;IACpD,SAAS,OAAO,QAAQ;IACxB;GACD,CAAC,CACF;AAED,SAAO;;;AAIT,MAAM,sBAAsB,OAAO;CAClC,MAAM,QAAQ;CACd,SAAS,QAAQ;CACjB,CAAC;AAEF,eAAsB,mBACrB,iBACA,cACA,MACC;CACD,MAAM,4BAAY,IAAI,KAAa;CACnC,MAAM,8BA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AAI,MACT,2BAA2B,SAAS,aAAa,MAAM,cAAc,QAAQ,eAC5E,UAAU,mBAEX;AAGF,QAAO;EACN,OAAO;EACP,SAAS,OAAO,gBAAgB,YAAY;EAC5C,gBAAgB,OAAO,gBAAgB,eAAe;EACtD,aAAa,OAAO,gBAAgB,YAAY;EAChD;CAED,eAAe,cAAc,SAAwB,MAAyC;EAC7F,MAAM,EACL,SACA,aACA,QAAQ,eACL,MAAM,OAAO,KAAK,UAAU;GAC/B;GACA;GACA;GACA,CAAC;AAEF,QAAM;AAEN,MAAI,mBAAmB,IAAI;AAC1B,QAAK,MAAM,QAAQ,SAAS;AAC3B,QAAI,QAAQ,IAAI,KAAK,SAAS,CAC7B;IAGD,MAAM,cAAc,OAAO,KAAK,QAAQ;AAExC,UAAM,KAAK,KAAK;AAChB,wBAAoB;AAEpB,QAAI,oBAAoB,EACvB;;AAIF,OAAI,YACH,QAAO,cAAc,WAAW;;AAIlC,SAAO"}
|
|
1
|
+
{"version":3,"file":"CoinWithBalance.mjs","names":["bcs","balance"],"sources":["../../../src/transactions/intents/CoinWithBalance.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { InferInput } from 'valibot';\nimport { bigint, object, optional, parse, picklist, string } from 'valibot';\n\nimport { bcs } from '../../bcs/index.js';\nimport { normalizeStructTag } from '../../utils/haneul-types.js';\nimport { TransactionCommands } from '../Commands.js';\nimport type { Argument } from '../data/internal.js';\nimport { Inputs } from '../Inputs.js';\nimport type { BuildTransactionOptions } from '../resolve.js';\nimport type { Transaction, TransactionResult } from '../Transaction.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\nimport type { ClientWithCoreApi, HaneulClientTypes } from '../../client/index.js';\n\nexport const COIN_WITH_BALANCE = 'CoinWithBalance';\nconst HANEUL_TYPE = normalizeStructTag('0x2::haneul::HANEUL');\n\nexport function coinWithBalance({\n\ttype = HANEUL_TYPE,\n\tbalance,\n\tuseGasCoin = true,\n}: {\n\tbalance: bigint | number;\n\ttype?: string;\n\tuseGasCoin?: boolean;\n}): (tx: Transaction) => TransactionResult {\n\tlet coinResult: TransactionResult | null = null;\n\n\treturn (tx: Transaction) => {\n\t\tif (coinResult) {\n\t\t\treturn coinResult;\n\t\t}\n\n\t\ttx.addIntentResolver(COIN_WITH_BALANCE, resolveCoinBalance);\n\t\tconst coinType = type === 'gas' ? type : normalizeStructTag(type);\n\n\t\tcoinResult = tx.add(\n\t\t\tTransactionCommands.Intent({\n\t\t\t\tname: COIN_WITH_BALANCE,\n\t\t\t\tinputs: {},\n\t\t\t\tdata: {\n\t\t\t\t\ttype: coinType === HANEUL_TYPE && useGasCoin ? 'gas' : coinType,\n\t\t\t\t\tbalance: BigInt(balance),\n\t\t\t\t\toutputKind: 'coin',\n\t\t\t\t} satisfies InferInput<typeof CoinWithBalanceData>,\n\t\t\t}),\n\t\t);\n\n\t\treturn coinResult;\n\t};\n}\n\nexport function createBalance({\n\ttype = HANEUL_TYPE,\n\tbalance,\n\tuseGasCoin = true,\n}: {\n\tbalance: bigint | number;\n\ttype?: string;\n\tuseGasCoin?: boolean;\n}): (tx: Transaction) => TransactionResult {\n\tlet balanceResult: TransactionResult | null = null;\n\n\treturn (tx: Transaction) => {\n\t\tif (balanceResult) {\n\t\t\treturn balanceResult;\n\t\t}\n\n\t\ttx.addIntentResolver(COIN_WITH_BALANCE, resolveCoinBalance);\n\t\tconst coinType = type === 'gas' ? type : normalizeStructTag(type);\n\n\t\tbalanceResult = tx.add(\n\t\t\tTransactionCommands.Intent({\n\t\t\t\tname: COIN_WITH_BALANCE,\n\t\t\t\tinputs: {},\n\t\t\t\tdata: {\n\t\t\t\t\ttype: coinType === HANEUL_TYPE && useGasCoin ? 'gas' : coinType,\n\t\t\t\t\tbalance: BigInt(balance),\n\t\t\t\t\toutputKind: 'balance',\n\t\t\t\t} satisfies InferInput<typeof CoinWithBalanceData>,\n\t\t\t}),\n\t\t);\n\n\t\treturn balanceResult;\n\t};\n}\n\nconst CoinWithBalanceData = object({\n\ttype: string(),\n\tbalance: bigint(),\n\toutputKind: optional(picklist(['coin', 'balance'])),\n});\n\nexport async function resolveCoinBalance(\n\ttransactionData: TransactionDataBuilder,\n\tbuildOptions: BuildTransactionOptions,\n\tnext: () => Promise<void>,\n) {\n\ttype IntentInfo = { balance: bigint; outputKind: 'coin' | 'balance' };\n\n\tconst coinTypes = new Set<string>();\n\tconst totalByType = new Map<string, bigint>();\n\tconst intentsByType = new Map<string, IntentInfo[]>();\n\n\tif (!transactionData.sender) {\n\t\tthrow new Error('Sender must be set to resolve CoinWithBalance');\n\t}\n\n\t// First pass: scan intents, collect per-type data, and resolve zero-balance intents in place.\n\tfor (const [i, command] of transactionData.commands.entries()) {\n\t\tif (command.$kind !== '$Intent' || command.$Intent.name !== COIN_WITH_BALANCE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst { type, balance, outputKind } = parse(CoinWithBalanceData, command.$Intent.data);\n\n\t\t// Zero-balance intents are resolved immediately — no coins or AB needed.\n\t\t// This is a 1:1 replacement so indices don't shift.\n\t\tif (balance === 0n) {\n\t\t\tconst coinType = type === 'gas' ? HANEUL_TYPE : type;\n\t\t\ttransactionData.replaceCommand(\n\t\t\t\ti,\n\t\t\t\tTransactionCommands.MoveCall({\n\t\t\t\t\ttarget: (outputKind ?? 'coin') === 'balance' ? '0x2::balance::zero' : '0x2::coin::zero',\n\t\t\t\t\ttypeArguments: [coinType],\n\t\t\t\t}),\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (type !== 'gas') {\n\t\t\tcoinTypes.add(type);\n\t\t}\n\n\t\ttotalByType.set(type, (totalByType.get(type) ?? 0n) + balance);\n\n\t\tif (!intentsByType.has(type)) intentsByType.set(type, []);\n\t\tintentsByType.get(type)!.push({ balance, outputKind: outputKind ?? 'coin' });\n\t}\n\n\tconst usedIds = new Set<string>();\n\n\tfor (const input of transactionData.inputs) {\n\t\tif (input.Object?.ImmOrOwnedObject) {\n\t\t\tusedIds.add(input.Object.ImmOrOwnedObject.objectId);\n\t\t}\n\t\tif (input.UnresolvedObject?.objectId) {\n\t\t\tusedIds.add(input.UnresolvedObject.objectId);\n\t\t}\n\t}\n\n\tconst coinsByType = new Map<string, HaneulClientTypes.Coin[]>();\n\tconst addressBalanceByType = new Map<string, bigint>();\n\tconst client = buildOptions.client;\n\n\tif (!client) {\n\t\tthrow new Error(\n\t\t\t'Client must be provided to build or serialize transactions with CoinWithBalance intents',\n\t\t);\n\t}\n\n\tawait Promise.all([\n\t\t...[...coinTypes].map(async (coinType) => {\n\t\t\tconst { coins, addressBalance } = await getCoinsAndBalanceOfType({\n\t\t\t\tcoinType,\n\t\t\t\tbalance: totalByType.get(coinType)!,\n\t\t\t\tclient,\n\t\t\t\towner: transactionData.sender!,\n\t\t\t\tusedIds,\n\t\t\t});\n\n\t\t\tcoinsByType.set(coinType, coins);\n\t\t\taddressBalanceByType.set(coinType, addressBalance);\n\t\t}),\n\t\ttotalByType.has('gas')\n\t\t\t? await client.core\n\t\t\t\t\t.getBalance({\n\t\t\t\t\t\towner: transactionData.sender!,\n\t\t\t\t\t\tcoinType: HANEUL_TYPE,\n\t\t\t\t\t})\n\t\t\t\t\t.then(({ balance }) => {\n\t\t\t\t\t\taddressBalanceByType.set('gas', BigInt(balance.addressBalance));\n\t\t\t\t\t})\n\t\t\t: null,\n\t]);\n\n\tconst mergedCoins = new Map<string, Argument>();\n\tconst exactBalanceByType = new Map<string, boolean>();\n\n\t// Per-type state for Path 2 combined splits\n\ttype TypeState = { results: Argument[]; nextIntent: number };\n\tconst typeState = new Map<string, TypeState>();\n\n\tlet index = 0;\n\twhile (index < transactionData.commands.length) {\n\t\tconst transaction = transactionData.commands[index];\n\t\tif (transaction.$kind !== '$Intent' || transaction.$Intent.name !== COIN_WITH_BALANCE) {\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst { type, balance } = transaction.$Intent.data as {\n\t\t\ttype: string;\n\t\t\tbalance: bigint;\n\t\t};\n\t\tconst coinType = type === 'gas' ? HANEUL_TYPE : type;\n\t\tconst totalRequired = totalByType.get(type)!;\n\t\tconst addressBalance = addressBalanceByType.get(type) ?? 0n;\n\n\t\tconst commands = [];\n\t\tlet intentResult: Argument;\n\n\t\tconst intentsForType = intentsByType.get(type) ?? [];\n\t\tconst allBalance = intentsForType.every((i) => i.outputKind === 'balance');\n\n\t\tif (allBalance && addressBalance >= totalRequired) {\n\t\t\t// Path 1: All balance intents and AB sufficient — direct per-intent withdrawal.\n\t\t\t// No coins touched, enables parallel execution.\n\t\t\tcommands.push(\n\t\t\t\tTransactionCommands.MoveCall({\n\t\t\t\t\ttarget: '0x2::balance::redeem_funds',\n\t\t\t\t\ttypeArguments: [coinType],\n\t\t\t\t\targuments: [\n\t\t\t\t\t\ttransactionData.addInput(\n\t\t\t\t\t\t\t'withdrawal',\n\t\t\t\t\t\t\tInputs.FundsWithdrawal({\n\t\t\t\t\t\t\t\treservation: {\n\t\t\t\t\t\t\t\t\t$kind: 'MaxAmountU64',\n\t\t\t\t\t\t\t\t\tMaxAmountU64: String(balance),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\ttypeArg: { $kind: 'Balance', Balance: coinType },\n\t\t\t\t\t\t\t\twithdrawFrom: { $kind: 'Sender', Sender: true },\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t);\n\n\t\t\tintentResult = {\n\t\t\t\t$kind: 'NestedResult',\n\t\t\t\tNestedResult: [index + commands.length - 1, 0],\n\t\t\t};\n\t\t} else {\n\t\t\t// Path 2: Merge and Split — build a merged coin, split all intents at once.\n\n\t\t\tif (!typeState.has(type)) {\n\t\t\t\tconst intents = intentsForType;\n\n\t\t\t\t// Step 1: Build sources and merge\n\t\t\t\tconst sources: Argument[] = [];\n\n\t\t\t\tif (type === 'gas') {\n\t\t\t\t\tsources.push({ $kind: 'GasCoin', GasCoin: true });\n\t\t\t\t} else {\n\t\t\t\t\tconst coins = coinsByType.get(type)!;\n\t\t\t\t\tconst loadedCoinBalance = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);\n\t\t\t\t\tconst abNeeded =\n\t\t\t\t\t\ttotalRequired > loadedCoinBalance ? totalRequired - loadedCoinBalance : 0n;\n\n\t\t\t\t\texactBalanceByType.set(type, loadedCoinBalance + abNeeded === totalRequired);\n\n\t\t\t\t\tfor (const coin of coins) {\n\t\t\t\t\t\tsources.push(\n\t\t\t\t\t\t\ttransactionData.addInput(\n\t\t\t\t\t\t\t\t'object',\n\t\t\t\t\t\t\t\tInputs.ObjectRef({\n\t\t\t\t\t\t\t\t\tobjectId: coin.objectId,\n\t\t\t\t\t\t\t\t\tdigest: coin.digest,\n\t\t\t\t\t\t\t\t\tversion: coin.version,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (abNeeded > 0n) {\n\t\t\t\t\t\tcommands.push(\n\t\t\t\t\t\t\tTransactionCommands.MoveCall({\n\t\t\t\t\t\t\t\ttarget: '0x2::coin::redeem_funds',\n\t\t\t\t\t\t\t\ttypeArguments: [coinType],\n\t\t\t\t\t\t\t\targuments: [\n\t\t\t\t\t\t\t\t\ttransactionData.addInput(\n\t\t\t\t\t\t\t\t\t\t'withdrawal',\n\t\t\t\t\t\t\t\t\t\tInputs.FundsWithdrawal({\n\t\t\t\t\t\t\t\t\t\t\treservation: {\n\t\t\t\t\t\t\t\t\t\t\t\t$kind: 'MaxAmountU64',\n\t\t\t\t\t\t\t\t\t\t\t\tMaxAmountU64: String(abNeeded),\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\ttypeArg: { $kind: 'Balance', Balance: coinType },\n\t\t\t\t\t\t\t\t\t\t\twithdrawFrom: { $kind: 'Sender', Sender: true },\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tsources.push({ $kind: 'Result', Result: index + commands.length - 1 });\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst baseCoin = sources[0];\n\t\t\t\tconst rest = sources.slice(1);\n\t\t\t\tfor (let i = 0; i < rest.length; i += 500) {\n\t\t\t\t\tcommands.push(TransactionCommands.MergeCoins(baseCoin, rest.slice(i, i + 500)));\n\t\t\t\t}\n\n\t\t\t\tmergedCoins.set(type, baseCoin);\n\n\t\t\t\t// Step 2: Combined SplitCoins for all intents of this type\n\t\t\t\tconst splitCmdIndex = index + commands.length;\n\t\t\t\tcommands.push(\n\t\t\t\t\tTransactionCommands.SplitCoins(\n\t\t\t\t\t\tbaseCoin,\n\t\t\t\t\t\tintents.map((i) =>\n\t\t\t\t\t\t\ttransactionData.addInput('pure', Inputs.Pure(bcs.u64().serialize(i.balance))),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t);\n\n\t\t\t\t// Build per-intent results, adding into_balance conversions for balance intents\n\t\t\t\tconst results: Argument[] = [];\n\t\t\t\tfor (let i = 0; i < intents.length; i++) {\n\t\t\t\t\tconst splitResult: Argument = {\n\t\t\t\t\t\t$kind: 'NestedResult',\n\t\t\t\t\t\tNestedResult: [splitCmdIndex, i],\n\t\t\t\t\t};\n\n\t\t\t\t\tif (intents[i].outputKind === 'balance') {\n\t\t\t\t\t\tcommands.push(\n\t\t\t\t\t\t\tTransactionCommands.MoveCall({\n\t\t\t\t\t\t\t\ttarget: '0x2::coin::into_balance',\n\t\t\t\t\t\t\t\ttypeArguments: [coinType],\n\t\t\t\t\t\t\t\targuments: [splitResult],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tresults.push({\n\t\t\t\t\t\t\t$kind: 'NestedResult',\n\t\t\t\t\t\t\tNestedResult: [index + commands.length - 1, 0],\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresults.push(splitResult);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\ttypeState.set(type, { results, nextIntent: 0 });\n\t\t\t}\n\n\t\t\tconst state = typeState.get(type)!;\n\t\t\tintentResult = state.results[state.nextIntent++];\n\t\t}\n\n\t\ttransactionData.replaceCommand(\n\t\t\tindex,\n\t\t\tcommands,\n\t\t\tintentResult as { NestedResult: [number, number] },\n\t\t);\n\n\t\t// Advance past the replacement. When commands is empty (subsequent intents\n\t\t// of a combined split), the command was removed and the next command shifted\n\t\t// into this position — so we stay at the same index.\n\t\tindex += commands.length;\n\t}\n\n\t// Step 3: Remainder handling\n\tfor (const [type, mergedCoin] of mergedCoins) {\n\t\tif (type === 'gas') continue;\n\n\t\tconst hasBalanceIntent = intentsByType.get(type)?.some((i) => i.outputKind === 'balance');\n\n\t\tif (hasBalanceIntent) {\n\t\t\t// Balance intents exist: send remainder coin back to sender's address balance.\n\t\t\t// coin::send_funds is gasless-eligible and handles zero amounts.\n\t\t\ttransactionData.commands.push(\n\t\t\t\tTransactionCommands.MoveCall({\n\t\t\t\t\ttarget: '0x2::coin::send_funds',\n\t\t\t\t\ttypeArguments: [type],\n\t\t\t\t\targuments: [\n\t\t\t\t\t\tmergedCoin,\n\t\t\t\t\t\ttransactionData.addInput(\n\t\t\t\t\t\t\t'pure',\n\t\t\t\t\t\t\tInputs.Pure(bcs.Address.serialize(transactionData.sender!)),\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t);\n\t\t} else if (exactBalanceByType.get(type)) {\n\t\t\t// Coin-only with exact match: destroy the zero-value dust coin.\n\t\t\ttransactionData.commands.push(\n\t\t\t\tTransactionCommands.MoveCall({\n\t\t\t\t\ttarget: '0x2::coin::destroy_zero',\n\t\t\t\t\ttypeArguments: [type],\n\t\t\t\t\targuments: [mergedCoin],\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\t// Coin-only with surplus: merged coin stays with sender as an owned object\n\t}\n\n\treturn next();\n}\n\nasync function getCoinsAndBalanceOfType({\n\tcoinType,\n\tbalance,\n\tclient,\n\towner,\n\tusedIds,\n}: {\n\tcoinType: string;\n\tbalance: bigint;\n\tclient: ClientWithCoreApi;\n\towner: string;\n\tusedIds: Set<string>;\n}): Promise<{\n\tcoins: HaneulClientTypes.Coin[];\n\tbalance: bigint;\n\taddressBalance: bigint;\n\tcoinBalance: bigint;\n}> {\n\tlet remainingBalance = balance;\n\tconst coins: HaneulClientTypes.Coin[] = [];\n\tconst balanceRequest = client.core.getBalance({ owner, coinType }).then(({ balance }) => {\n\t\tremainingBalance -= BigInt(balance.addressBalance);\n\n\t\treturn balance;\n\t});\n\n\tconst [allCoins, balanceResponse] = await Promise.all([loadMoreCoins(), balanceRequest]);\n\n\tif (BigInt(balanceResponse.balance) < balance) {\n\t\tthrow new Error(\n\t\t\t`Insufficient balance of ${coinType} for owner ${owner}. Required: ${balance}, Available: ${\n\t\t\t\tbalance - remainingBalance\n\t\t\t}`,\n\t\t);\n\t}\n\n\treturn {\n\t\tcoins: allCoins,\n\t\tbalance: BigInt(balanceResponse.coinBalance),\n\t\taddressBalance: BigInt(balanceResponse.addressBalance),\n\t\tcoinBalance: BigInt(balanceResponse.coinBalance),\n\t};\n\n\tasync function loadMoreCoins(cursor: string | null = null): Promise<HaneulClientTypes.Coin[]> {\n\t\tconst {\n\t\t\tobjects,\n\t\t\thasNextPage,\n\t\t\tcursor: nextCursor,\n\t\t} = await client.core.listCoins({\n\t\t\towner,\n\t\t\tcoinType,\n\t\t\tcursor,\n\t\t});\n\n\t\tawait balanceRequest;\n\n\t\t// Always load all coins from the page (except already-used ones).\n\t\t// This merges all available coins rather than leaving dust.\n\t\tfor (const coin of objects) {\n\t\t\tif (usedIds.has(coin.objectId)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcoins.push(coin);\n\t\t\tremainingBalance -= BigInt(coin.balance);\n\t\t}\n\n\t\t// Only paginate if loaded coins + AB are still insufficient\n\t\tif (remainingBalance > 0n && hasNextPage) {\n\t\t\treturn loadMoreCoins(nextCursor);\n\t\t}\n\n\t\treturn coins;\n\t}\n}\n"],"mappings":";;;;;;;AAgBA,MAAa,oBAAoB;AACjC,MAAM,cAAc,mBAAmB,sBAAsB;AAE7D,SAAgB,gBAAgB,EAC/B,OAAO,aACP,SACA,aAAa,QAK6B;CAC1C,IAAI,aAAuC;AAE3C,SAAQ,OAAoB;AAC3B,MAAI,WACH,QAAO;AAGR,KAAG,kBAAkB,mBAAmB,mBAAmB;EAC3D,MAAM,WAAW,SAAS,QAAQ,OAAO,mBAAmB,KAAK;AAEjE,eAAa,GAAG,IACf,oBAAoB,OAAO;GAC1B,MAAM;GACN,QAAQ,EAAE;GACV,MAAM;IACL,MAAM,aAAa,eAAe,aAAa,QAAQ;IACvD,SAAS,OAAO,QAAQ;IACxB,YAAY;IACZ;GACD,CAAC,CACF;AAED,SAAO;;;AAIT,SAAgB,cAAc,EAC7B,OAAO,aACP,SACA,aAAa,QAK6B;CAC1C,IAAI,gBAA0C;AAE9C,SAAQ,OAAoB;AAC3B,MAAI,cACH,QAAO;AAGR,KAAG,kBAAkB,mBAAmB,mBAAmB;EAC3D,MAAM,WAAW,SAAS,QAAQ,OAAO,mBAAmB,KAAK;AAEjE,kBAAgB,GAAG,IAClB,oBAAoB,OAAO;GAC1B,MAAM;GACN,QAAQ,EAAE;GACV,MAAM;IACL,MAAM,aAAa,eAAe,aAAa,QAAQ;IACvD,SAAS,OAAO,QAAQ;IACxB,YAAY;IACZ;GACD,CAAC,CACF;AAED,SAAO;;;AAIT,MAAM,sBAAsB,OAAO;CAClC,MAAM,QAAQ;CACd,SAAS,QAAQ;CACjB,YAAY,SAAS,SAAS,CAAC,QAAQ,UAAU,CAAC,CAAC;CACnD,CAAC;AAEF,eAAsB,mBACrB,iBACA,cACA,MACC;CAGD,MAAM,4BAAY,IAAI,KAAa;CACnC,MAAM,8BAAc,IAAI,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;GACrB,WAAW,CAAC,WAAW;GACvB,CAAC,CACF;;AAKH,QAAO,MAAM;;AAGd,eAAe,yBAAyB,EACvC,UACA,SACA,QACA,OACA,WAYE;CACF,IAAI,mBAAmB;CACvB,MAAM,QAAkC,EAAE;CAC1C,MAAM,iBAAiB,OAAO,KAAK,WAAW;EAAE;EAAO;EAAU,CAAC,CAAC,MAAM,EAAE,yBAAc;AACxF,sBAAoB,OAAOC,UAAQ,eAAe;AAElD,SAAOA;GACN;CAEF,MAAM,CAAC,UAAU,mBAAmB,MAAM,QAAQ,IAAI,CAAC,eAAe,EAAE,eAAe,CAAC;AAExF,KAAI,OAAO,gBAAgB,QAAQ,GAAG,QACrC,OAAM,IAAI,MACT,2BAA2B,SAAS,aAAa,MAAM,cAAc,QAAQ,eAC5E,UAAU,mBAEX;AAGF,QAAO;EACN,OAAO;EACP,SAAS,OAAO,gBAAgB,YAAY;EAC5C,gBAAgB,OAAO,gBAAgB,eAAe;EACtD,aAAa,OAAO,gBAAgB,YAAY;EAChD;CAED,eAAe,cAAc,SAAwB,MAAyC;EAC7F,MAAM,EACL,SACA,aACA,QAAQ,eACL,MAAM,OAAO,KAAK,UAAU;GAC/B;GACA;GACA;GACA,CAAC;AAEF,QAAM;AAIN,OAAK,MAAM,QAAQ,SAAS;AAC3B,OAAI,QAAQ,IAAI,KAAK,SAAS,CAC7B;AAGD,SAAM,KAAK,KAAK;AAChB,uBAAoB,OAAO,KAAK,QAAQ;;AAIzC,MAAI,mBAAmB,MAAM,YAC5B,QAAO,cAAc,WAAW;AAGjC,SAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.mts","names":[],"sources":["../../src/transactions/object.ts"],"
|
|
1
|
+
{"version":3,"file":"object.d.mts","names":[],"sources":["../../src/transactions/object.ts"],"mappings":";;;iBAagB,mBAAA,GAAA,CAAuB,UAAA,GAAa,KAAA,EAAO,sBAAA,KAA2B,CAAA;EAAA,QAC9D,sBAAA,GAAsB,CAAA;;IAIhB,OAAA;EAAA,IAAmB,CAAA;;;;IAqCjB,OAAA;EAAA,IAAmB,CAAA;;;;;IAU7B,IAAA;IAAc,KAAA,EAAO,sBAAA;EAAA,KACxC,EAAA,EAAI,WAAA,KAAW,iBAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pure.d.mts","names":[],"sources":["../../src/transactions/pure.ts"],"
|
|
1
|
+
{"version":3,"file":"pure.d.mts","names":[],"sources":["../../src/transactions/pure.ts"],"mappings":";;;;iBAUgB,UAAA,GAAA,CAAc,QAAA,GAAW,KAAA,EAAO,aAAA,aAA0B,UAAA,KAAe,CAAA;EAAA,cAC7D,YAAA,EAAY,IAAA,EAChC,IAAA,SAAa,YAAA,GAAe,iBAAA,CAAkB,IAAA,IAAQ,IAAA,EAAI,KAAA,EACzD,qBAAA,CAAsB,IAAA,IAC3B,CAAA;EAAA,QAOK,aAAA,aAA0B,UAAA,GAC/B,CAAA;qBAiBqB,CAAA;sBACC,CAAA;sBACA,CAAA;wCACkB,CAAA;yCACC,CAAA;yCACA,CAAA;wBACjB,CAAA;yBACC,CAAA;0BACC,CAAA;yBAAA,CAAA;sBAED,YAAA,EAAY,IAAA,EACjC,IAAA,SAAa,YAAA,GAAe,iBAAA,CAAkB,IAAA,IAAQ,IAAA,EAAI,KAAA,EACzD,QAAA,CAAS,qBAAA,CAAsB,IAAA;IAAW,MAAA;EAAA,IAAgB,CAAA;sBAMtC,YAAA,EAAY,IAAA,EACjC,IAAA,SAAa,YAAA,GAAe,iBAAA,CAAkB,IAAA,IAAQ,IAAA,EAAI,KAAA,EACzD,qBAAA,CAAsB,IAAA,uBAAwB,CAAA;AAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { pureBcsSchemaFromTypeName } from "../bcs/pure.mjs";
|
|
2
|
-
import { bcs as
|
|
2
|
+
import { bcs as haneulBcs } from "../bcs/index.mjs";
|
|
3
3
|
import { isSerializedBcs } from "@haneullabs/bcs";
|
|
4
4
|
|
|
5
5
|
//#region src/transactions/pure.ts
|
|
@@ -9,21 +9,21 @@ function createPure(makePure) {
|
|
|
9
9
|
if (typeOrSerializedValue instanceof Uint8Array || isSerializedBcs(typeOrSerializedValue)) return makePure(typeOrSerializedValue);
|
|
10
10
|
throw new Error("tx.pure must be called either a bcs type name, or a serialized bcs value");
|
|
11
11
|
}
|
|
12
|
-
pure.u8 = (value) => makePure(
|
|
13
|
-
pure.u16 = (value) => makePure(
|
|
14
|
-
pure.u32 = (value) => makePure(
|
|
15
|
-
pure.u64 = (value) => makePure(
|
|
16
|
-
pure.u128 = (value) => makePure(
|
|
17
|
-
pure.u256 = (value) => makePure(
|
|
18
|
-
pure.bool = (value) => makePure(
|
|
19
|
-
pure.string = (value) => makePure(
|
|
20
|
-
pure.address = (value) => makePure(
|
|
12
|
+
pure.u8 = (value) => makePure(haneulBcs.U8.serialize(value));
|
|
13
|
+
pure.u16 = (value) => makePure(haneulBcs.U16.serialize(value));
|
|
14
|
+
pure.u32 = (value) => makePure(haneulBcs.U32.serialize(value));
|
|
15
|
+
pure.u64 = (value) => makePure(haneulBcs.U64.serialize(value));
|
|
16
|
+
pure.u128 = (value) => makePure(haneulBcs.U128.serialize(value));
|
|
17
|
+
pure.u256 = (value) => makePure(haneulBcs.U256.serialize(value));
|
|
18
|
+
pure.bool = (value) => makePure(haneulBcs.Bool.serialize(value));
|
|
19
|
+
pure.string = (value) => makePure(haneulBcs.String.serialize(value));
|
|
20
|
+
pure.address = (value) => makePure(haneulBcs.Address.serialize(value));
|
|
21
21
|
pure.id = pure.address;
|
|
22
22
|
pure.vector = (type, value) => {
|
|
23
|
-
return makePure(
|
|
23
|
+
return makePure(haneulBcs.vector(pureBcsSchemaFromTypeName(type)).serialize(value));
|
|
24
24
|
};
|
|
25
25
|
pure.option = (type, value) => {
|
|
26
|
-
return makePure(
|
|
26
|
+
return makePure(haneulBcs.option(pureBcsSchemaFromTypeName(type)).serialize(value));
|
|
27
27
|
};
|
|
28
28
|
return pure;
|
|
29
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pure.mjs","names":["bcs"],"sources":["../../src/transactions/pure.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isSerializedBcs } from '@haneullabs/bcs';\nimport type { SerializedBcs } from '@haneullabs/bcs';\n\nimport { bcs } from '../bcs/index.js';\nimport { pureBcsSchemaFromTypeName } from '../bcs/pure.js';\nimport type { PureTypeName, ShapeFromPureTypeName, ValidPureTypeName } from '../bcs/pure.js';\n\nexport function createPure<T>(makePure: (value: SerializedBcs<any, any> | Uint8Array) => T) {\n\tfunction pure<Type extends PureTypeName>(\n\t\ttype: Type extends PureTypeName ? ValidPureTypeName<Type> : Type,\n\t\tvalue: ShapeFromPureTypeName<Type>,\n\t): T;\n\n\tfunction pure(\n\t\t/**\n\t\t * The pure value, serialized to BCS. If this is a Uint8Array, then the value\n\t\t * is assumed to be raw bytes, and will be used directly.\n\t\t */\n\t\tvalue: SerializedBcs<any, any> | Uint8Array,\n\t): T;\n\n\tfunction pure(\n\t\ttypeOrSerializedValue?: PureTypeName | SerializedBcs<any, any> | Uint8Array,\n\t\tvalue?: unknown,\n\t): T {\n\t\tif (typeof typeOrSerializedValue === 'string') {\n\t\t\treturn makePure(pureBcsSchemaFromTypeName(typeOrSerializedValue).serialize(value as never));\n\t\t}\n\n\t\tif (typeOrSerializedValue instanceof Uint8Array || isSerializedBcs(typeOrSerializedValue)) {\n\t\t\treturn makePure(typeOrSerializedValue);\n\t\t}\n\n\t\tthrow new Error('tx.pure must be called either a bcs type name, or a serialized bcs value');\n\t}\n\n\tpure.u8 = (value: number) => makePure(bcs.U8.serialize(value));\n\tpure.u16 = (value: number) => makePure(bcs.U16.serialize(value));\n\tpure.u32 = (value: number) => makePure(bcs.U32.serialize(value));\n\tpure.u64 = (value: bigint | number | string) => makePure(bcs.U64.serialize(value));\n\tpure.u128 = (value: bigint | number | string) => makePure(bcs.U128.serialize(value));\n\tpure.u256 = (value: bigint | number | string) => makePure(bcs.U256.serialize(value));\n\tpure.bool = (value: boolean) => makePure(bcs.Bool.serialize(value));\n\tpure.string = (value: string) => makePure(bcs.String.serialize(value));\n\tpure.address = (value: string) => makePure(bcs.Address.serialize(value));\n\tpure.id = pure.address;\n\tpure.vector = <Type extends PureTypeName>(\n\t\ttype: Type extends PureTypeName ? ValidPureTypeName<Type> : Type,\n\t\tvalue: Iterable<ShapeFromPureTypeName<Type>> & { length: number },\n\t) => {\n\t\treturn makePure(\n\t\t\tbcs.vector(pureBcsSchemaFromTypeName(type as PureTypeName)).serialize(value as never),\n\t\t);\n\t};\n\tpure.option = <Type extends PureTypeName>(\n\t\ttype: Type extends PureTypeName ? ValidPureTypeName<Type> : Type,\n\t\tvalue: ShapeFromPureTypeName<Type> | null | undefined,\n\t) => {\n\t\treturn makePure(bcs.option(pureBcsSchemaFromTypeName(type)).serialize(value as never));\n\t};\n\n\treturn pure;\n}\n"],"mappings":";;;;;AAUA,SAAgB,WAAc,UAA8D;CAc3F,SAAS,KACR,uBACA,OACI;AACJ,MAAI,OAAO,0BAA0B,SACpC,QAAO,SAAS,0BAA0B,sBAAsB,CAAC,UAAU,MAAe,CAAC;AAG5F,MAAI,iCAAiC,cAAc,gBAAgB,sBAAsB,CACxF,QAAO,SAAS,sBAAsB;AAGvC,QAAM,IAAI,MAAM,2EAA2E;;AAG5F,MAAK,MAAM,UAAkB,SAASA,
|
|
1
|
+
{"version":3,"file":"pure.mjs","names":["bcs"],"sources":["../../src/transactions/pure.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isSerializedBcs } from '@haneullabs/bcs';\nimport type { SerializedBcs } from '@haneullabs/bcs';\n\nimport { bcs } from '../bcs/index.js';\nimport { pureBcsSchemaFromTypeName } from '../bcs/pure.js';\nimport type { PureTypeName, ShapeFromPureTypeName, ValidPureTypeName } from '../bcs/pure.js';\n\nexport function createPure<T>(makePure: (value: SerializedBcs<any, any> | Uint8Array) => T) {\n\tfunction pure<Type extends PureTypeName>(\n\t\ttype: Type extends PureTypeName ? ValidPureTypeName<Type> : Type,\n\t\tvalue: ShapeFromPureTypeName<Type>,\n\t): T;\n\n\tfunction pure(\n\t\t/**\n\t\t * The pure value, serialized to BCS. If this is a Uint8Array, then the value\n\t\t * is assumed to be raw bytes, and will be used directly.\n\t\t */\n\t\tvalue: SerializedBcs<any, any> | Uint8Array,\n\t): T;\n\n\tfunction pure(\n\t\ttypeOrSerializedValue?: PureTypeName | SerializedBcs<any, any> | Uint8Array,\n\t\tvalue?: unknown,\n\t): T {\n\t\tif (typeof typeOrSerializedValue === 'string') {\n\t\t\treturn makePure(pureBcsSchemaFromTypeName(typeOrSerializedValue).serialize(value as never));\n\t\t}\n\n\t\tif (typeOrSerializedValue instanceof Uint8Array || isSerializedBcs(typeOrSerializedValue)) {\n\t\t\treturn makePure(typeOrSerializedValue);\n\t\t}\n\n\t\tthrow new Error('tx.pure must be called either a bcs type name, or a serialized bcs value');\n\t}\n\n\tpure.u8 = (value: number) => makePure(bcs.U8.serialize(value));\n\tpure.u16 = (value: number) => makePure(bcs.U16.serialize(value));\n\tpure.u32 = (value: number) => makePure(bcs.U32.serialize(value));\n\tpure.u64 = (value: bigint | number | string) => makePure(bcs.U64.serialize(value));\n\tpure.u128 = (value: bigint | number | string) => makePure(bcs.U128.serialize(value));\n\tpure.u256 = (value: bigint | number | string) => makePure(bcs.U256.serialize(value));\n\tpure.bool = (value: boolean) => makePure(bcs.Bool.serialize(value));\n\tpure.string = (value: string) => makePure(bcs.String.serialize(value));\n\tpure.address = (value: string) => makePure(bcs.Address.serialize(value));\n\tpure.id = pure.address;\n\tpure.vector = <Type extends PureTypeName>(\n\t\ttype: Type extends PureTypeName ? ValidPureTypeName<Type> : Type,\n\t\tvalue: Iterable<ShapeFromPureTypeName<Type>> & { length: number },\n\t) => {\n\t\treturn makePure(\n\t\t\tbcs.vector(pureBcsSchemaFromTypeName(type as PureTypeName)).serialize(value as never),\n\t\t);\n\t};\n\tpure.option = <Type extends PureTypeName>(\n\t\ttype: Type extends PureTypeName ? ValidPureTypeName<Type> : Type,\n\t\tvalue: ShapeFromPureTypeName<Type> | null | undefined,\n\t) => {\n\t\treturn makePure(bcs.option(pureBcsSchemaFromTypeName(type)).serialize(value as never));\n\t};\n\n\treturn pure;\n}\n"],"mappings":";;;;;AAUA,SAAgB,WAAc,UAA8D;CAc3F,SAAS,KACR,uBACA,OACI;AACJ,MAAI,OAAO,0BAA0B,SACpC,QAAO,SAAS,0BAA0B,sBAAsB,CAAC,UAAU,MAAe,CAAC;AAG5F,MAAI,iCAAiC,cAAc,gBAAgB,sBAAsB,CACxF,QAAO,SAAS,sBAAsB;AAGvC,QAAM,IAAI,MAAM,2EAA2E;;AAG5F,MAAK,MAAM,UAAkB,SAASA,UAAI,GAAG,UAAU,MAAM,CAAC;AAC9D,MAAK,OAAO,UAAkB,SAASA,UAAI,IAAI,UAAU,MAAM,CAAC;AAChE,MAAK,OAAO,UAAkB,SAASA,UAAI,IAAI,UAAU,MAAM,CAAC;AAChE,MAAK,OAAO,UAAoC,SAASA,UAAI,IAAI,UAAU,MAAM,CAAC;AAClF,MAAK,QAAQ,UAAoC,SAASA,UAAI,KAAK,UAAU,MAAM,CAAC;AACpF,MAAK,QAAQ,UAAoC,SAASA,UAAI,KAAK,UAAU,MAAM,CAAC;AACpF,MAAK,QAAQ,UAAmB,SAASA,UAAI,KAAK,UAAU,MAAM,CAAC;AACnE,MAAK,UAAU,UAAkB,SAASA,UAAI,OAAO,UAAU,MAAM,CAAC;AACtE,MAAK,WAAW,UAAkB,SAASA,UAAI,QAAQ,UAAU,MAAM,CAAC;AACxE,MAAK,KAAK,KAAK;AACf,MAAK,UACJ,MACA,UACI;AACJ,SAAO,SACNA,UAAI,OAAO,0BAA0B,KAAqB,CAAC,CAAC,UAAU,MAAe,CACrF;;AAEF,MAAK,UACJ,MACA,UACI;AACJ,SAAO,SAASA,UAAI,OAAO,0BAA0B,KAAK,CAAC,CAAC,UAAU,MAAe,CAAC;;AAGvF,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.mts","names":[],"sources":["../../src/transactions/resolve.ts"],"
|
|
1
|
+
{"version":3,"file":"resolve.d.mts","names":[],"sources":["../../src/transactions/resolve.ts"],"mappings":";;;;;UAYiB,uBAAA;EAChB,MAAA,GAAS,iBAAA;EACT,mBAAA;AAAA;AAAA,UAGgB,2BAAA,SAAoC,uBAAA;EACpD,gBAAA;AAAA;AAAA,KAGW,iBAAA,IACX,eAAA,EAAiB,sBAAA,EACjB,OAAA,EAAS,uBAAA,EACT,IAAA,QAAY,OAAA,WACR,OAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bcs as
|
|
1
|
+
import { bcs as haneulBcs } from "../bcs/index.mjs";
|
|
2
2
|
import { Inputs } from "./Inputs.mjs";
|
|
3
3
|
import { coreClientResolveTransactionPlugin } from "../client/core-resolver.mjs";
|
|
4
4
|
|
|
@@ -37,11 +37,11 @@ function normalizeRawArguments(transactionData) {
|
|
|
37
37
|
for (const command of transactionData.commands) switch (command.$kind) {
|
|
38
38
|
case "SplitCoins":
|
|
39
39
|
command.SplitCoins.amounts.forEach((amount) => {
|
|
40
|
-
normalizeRawArgument(amount,
|
|
40
|
+
normalizeRawArgument(amount, haneulBcs.U64, transactionData);
|
|
41
41
|
});
|
|
42
42
|
break;
|
|
43
43
|
case "TransferObjects":
|
|
44
|
-
normalizeRawArgument(command.TransferObjects.address,
|
|
44
|
+
normalizeRawArgument(command.TransferObjects.address, haneulBcs.Address, transactionData);
|
|
45
45
|
break;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.mjs","names":["bcs"],"sources":["../../src/transactions/resolve.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Argument } from './data/internal.js';\n\nimport type { ClientWithCoreApi } from '../client/index.js';\nimport type { TransactionDataBuilder } from './TransactionData.js';\nimport type { BcsType } from '@haneullabs/bcs';\nimport { Inputs } from './Inputs.js';\nimport { bcs } from '../bcs/index.js';\nimport { coreClientResolveTransactionPlugin } from '../client/core-resolver.js';\n\nexport interface BuildTransactionOptions {\n\tclient?: ClientWithCoreApi;\n\tonlyTransactionKind?: boolean;\n}\n\nexport interface SerializeTransactionOptions extends BuildTransactionOptions {\n\tsupportedIntents?: string[];\n}\n\nexport type TransactionPlugin = (\n\ttransactionData: TransactionDataBuilder,\n\toptions: BuildTransactionOptions,\n\tnext: () => Promise<void>,\n) => Promise<void>;\n\nexport function needsTransactionResolution(\n\tdata: TransactionDataBuilder,\n\toptions: BuildTransactionOptions,\n): boolean {\n\tif (\n\t\tdata.inputs.some((input) => {\n\t\t\treturn input.UnresolvedObject || input.UnresolvedPure;\n\t\t})\n\t) {\n\t\treturn true;\n\t}\n\n\tif (!options.onlyTransactionKind) {\n\t\tif (!data.gasData.price || !data.gasData.budget || !data.gasData.payment) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (data.gasData.payment.length === 0 && !data.expiration) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\nexport async function resolveTransactionPlugin(\n\ttransactionData: TransactionDataBuilder,\n\toptions: BuildTransactionOptions,\n\tnext: () => Promise<void>,\n) {\n\tnormalizeRawArguments(transactionData);\n\tif (!needsTransactionResolution(transactionData, options)) {\n\t\tawait validate(transactionData);\n\t\treturn next();\n\t}\n\n\tconst client = getClient(options);\n\tconst plugin = client.core?.resolveTransactionPlugin() ?? coreClientResolveTransactionPlugin;\n\n\treturn plugin(transactionData, options, async () => {\n\t\tawait validate(transactionData);\n\t\tawait next();\n\t});\n}\n\nfunction validate(transactionData: TransactionDataBuilder) {\n\ttransactionData.inputs.forEach((input, index) => {\n\t\tif (input.$kind !== 'Object' && input.$kind !== 'Pure' && input.$kind !== 'FundsWithdrawal') {\n\t\t\tthrow new Error(\n\t\t\t\t`Input at index ${index} has not been resolved. Expected a Pure, Object, or FundsWithdrawal input, but found ${JSON.stringify(\n\t\t\t\t\tinput,\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\t});\n}\n\nexport function getClient(options: BuildTransactionOptions) {\n\tif (!options.client) {\n\t\tthrow new Error(\n\t\t\t`No haneul client passed to Transaction#build, but transaction data was not sufficient to build offline.`,\n\t\t);\n\t}\n\n\treturn options.client;\n}\n\nfunction normalizeRawArguments(transactionData: TransactionDataBuilder) {\n\tfor (const command of transactionData.commands) {\n\t\tswitch (command.$kind) {\n\t\t\tcase 'SplitCoins':\n\t\t\t\tcommand.SplitCoins.amounts.forEach((amount) => {\n\t\t\t\t\tnormalizeRawArgument(amount, bcs.U64, transactionData);\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase 'TransferObjects':\n\t\t\t\tnormalizeRawArgument(command.TransferObjects.address, bcs.Address, transactionData);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfunction normalizeRawArgument(\n\targ: Argument,\n\tschema: BcsType<any>,\n\ttransactionData: TransactionDataBuilder,\n) {\n\tif (arg.$kind !== 'Input') {\n\t\treturn;\n\t}\n\tconst input = transactionData.inputs[arg.Input];\n\n\tif (input.$kind !== 'UnresolvedPure') {\n\t\treturn;\n\t}\n\n\ttransactionData.inputs[arg.Input] = Inputs.Pure(schema.serialize(input.UnresolvedPure.value));\n}\n"],"mappings":";;;;;AA2BA,SAAgB,2BACf,MACA,SACU;AACV,KACC,KAAK,OAAO,MAAM,UAAU;AAC3B,SAAO,MAAM,oBAAoB,MAAM;GACtC,CAEF,QAAO;AAGR,KAAI,CAAC,QAAQ,qBAAqB;AACjC,MAAI,CAAC,KAAK,QAAQ,SAAS,CAAC,KAAK,QAAQ,UAAU,CAAC,KAAK,QAAQ,QAChE,QAAO;AAGR,MAAI,KAAK,QAAQ,QAAQ,WAAW,KAAK,CAAC,KAAK,WAC9C,QAAO;;AAIT,QAAO;;AAGR,eAAsB,yBACrB,iBACA,SACA,MACC;AACD,uBAAsB,gBAAgB;AACtC,KAAI,CAAC,2BAA2B,iBAAiB,QAAQ,EAAE;AAC1D,QAAM,SAAS,gBAAgB;AAC/B,SAAO,MAAM;;AAMd,SAHe,UAAU,QAAQ,CACX,MAAM,0BAA0B,IAAI,oCAE5C,iBAAiB,SAAS,YAAY;AACnD,QAAM,SAAS,gBAAgB;AAC/B,QAAM,MAAM;GACX;;AAGH,SAAS,SAAS,iBAAyC;AAC1D,iBAAgB,OAAO,SAAS,OAAO,UAAU;AAChD,MAAI,MAAM,UAAU,YAAY,MAAM,UAAU,UAAU,MAAM,UAAU,kBACzE,OAAM,IAAI,MACT,kBAAkB,MAAM,wFAAwF,KAAK,UACpH,MACA,GACD;GAED;;AAGH,SAAgB,UAAU,SAAkC;AAC3D,KAAI,CAAC,QAAQ,OACZ,OAAM,IAAI,MACT,0GACA;AAGF,QAAO,QAAQ;;AAGhB,SAAS,sBAAsB,iBAAyC;AACvE,MAAK,MAAM,WAAW,gBAAgB,SACrC,SAAQ,QAAQ,OAAhB;EACC,KAAK;AACJ,WAAQ,WAAW,QAAQ,SAAS,WAAW;AAC9C,yBAAqB,QAAQA,
|
|
1
|
+
{"version":3,"file":"resolve.mjs","names":["bcs"],"sources":["../../src/transactions/resolve.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Argument } from './data/internal.js';\n\nimport type { ClientWithCoreApi } from '../client/index.js';\nimport type { TransactionDataBuilder } from './TransactionData.js';\nimport type { BcsType } from '@haneullabs/bcs';\nimport { Inputs } from './Inputs.js';\nimport { bcs } from '../bcs/index.js';\nimport { coreClientResolveTransactionPlugin } from '../client/core-resolver.js';\n\nexport interface BuildTransactionOptions {\n\tclient?: ClientWithCoreApi;\n\tonlyTransactionKind?: boolean;\n}\n\nexport interface SerializeTransactionOptions extends BuildTransactionOptions {\n\tsupportedIntents?: string[];\n}\n\nexport type TransactionPlugin = (\n\ttransactionData: TransactionDataBuilder,\n\toptions: BuildTransactionOptions,\n\tnext: () => Promise<void>,\n) => Promise<void>;\n\nexport function needsTransactionResolution(\n\tdata: TransactionDataBuilder,\n\toptions: BuildTransactionOptions,\n): boolean {\n\tif (\n\t\tdata.inputs.some((input) => {\n\t\t\treturn input.UnresolvedObject || input.UnresolvedPure;\n\t\t})\n\t) {\n\t\treturn true;\n\t}\n\n\tif (!options.onlyTransactionKind) {\n\t\tif (!data.gasData.price || !data.gasData.budget || !data.gasData.payment) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (data.gasData.payment.length === 0 && !data.expiration) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\nexport async function resolveTransactionPlugin(\n\ttransactionData: TransactionDataBuilder,\n\toptions: BuildTransactionOptions,\n\tnext: () => Promise<void>,\n) {\n\tnormalizeRawArguments(transactionData);\n\tif (!needsTransactionResolution(transactionData, options)) {\n\t\tawait validate(transactionData);\n\t\treturn next();\n\t}\n\n\tconst client = getClient(options);\n\tconst plugin = client.core?.resolveTransactionPlugin() ?? coreClientResolveTransactionPlugin;\n\n\treturn plugin(transactionData, options, async () => {\n\t\tawait validate(transactionData);\n\t\tawait next();\n\t});\n}\n\nfunction validate(transactionData: TransactionDataBuilder) {\n\ttransactionData.inputs.forEach((input, index) => {\n\t\tif (input.$kind !== 'Object' && input.$kind !== 'Pure' && input.$kind !== 'FundsWithdrawal') {\n\t\t\tthrow new Error(\n\t\t\t\t`Input at index ${index} has not been resolved. Expected a Pure, Object, or FundsWithdrawal input, but found ${JSON.stringify(\n\t\t\t\t\tinput,\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\t});\n}\n\nexport function getClient(options: BuildTransactionOptions) {\n\tif (!options.client) {\n\t\tthrow new Error(\n\t\t\t`No haneul client passed to Transaction#build, but transaction data was not sufficient to build offline.`,\n\t\t);\n\t}\n\n\treturn options.client;\n}\n\nfunction normalizeRawArguments(transactionData: TransactionDataBuilder) {\n\tfor (const command of transactionData.commands) {\n\t\tswitch (command.$kind) {\n\t\t\tcase 'SplitCoins':\n\t\t\t\tcommand.SplitCoins.amounts.forEach((amount) => {\n\t\t\t\t\tnormalizeRawArgument(amount, bcs.U64, transactionData);\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase 'TransferObjects':\n\t\t\t\tnormalizeRawArgument(command.TransferObjects.address, bcs.Address, transactionData);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfunction normalizeRawArgument(\n\targ: Argument,\n\tschema: BcsType<any>,\n\ttransactionData: TransactionDataBuilder,\n) {\n\tif (arg.$kind !== 'Input') {\n\t\treturn;\n\t}\n\tconst input = transactionData.inputs[arg.Input];\n\n\tif (input.$kind !== 'UnresolvedPure') {\n\t\treturn;\n\t}\n\n\ttransactionData.inputs[arg.Input] = Inputs.Pure(schema.serialize(input.UnresolvedPure.value));\n}\n"],"mappings":";;;;;AA2BA,SAAgB,2BACf,MACA,SACU;AACV,KACC,KAAK,OAAO,MAAM,UAAU;AAC3B,SAAO,MAAM,oBAAoB,MAAM;GACtC,CAEF,QAAO;AAGR,KAAI,CAAC,QAAQ,qBAAqB;AACjC,MAAI,CAAC,KAAK,QAAQ,SAAS,CAAC,KAAK,QAAQ,UAAU,CAAC,KAAK,QAAQ,QAChE,QAAO;AAGR,MAAI,KAAK,QAAQ,QAAQ,WAAW,KAAK,CAAC,KAAK,WAC9C,QAAO;;AAIT,QAAO;;AAGR,eAAsB,yBACrB,iBACA,SACA,MACC;AACD,uBAAsB,gBAAgB;AACtC,KAAI,CAAC,2BAA2B,iBAAiB,QAAQ,EAAE;AAC1D,QAAM,SAAS,gBAAgB;AAC/B,SAAO,MAAM;;AAMd,SAHe,UAAU,QAAQ,CACX,MAAM,0BAA0B,IAAI,oCAE5C,iBAAiB,SAAS,YAAY;AACnD,QAAM,SAAS,gBAAgB;AAC/B,QAAM,MAAM;GACX;;AAGH,SAAS,SAAS,iBAAyC;AAC1D,iBAAgB,OAAO,SAAS,OAAO,UAAU;AAChD,MAAI,MAAM,UAAU,YAAY,MAAM,UAAU,UAAU,MAAM,UAAU,kBACzE,OAAM,IAAI,MACT,kBAAkB,MAAM,wFAAwF,KAAK,UACpH,MACA,GACD;GAED;;AAGH,SAAgB,UAAU,SAAkC;AAC3D,KAAI,CAAC,QAAQ,OACZ,OAAM,IAAI,MACT,0GACA;AAGF,QAAO,QAAQ;;AAGhB,SAAS,sBAAsB,iBAAyC;AACvE,MAAK,MAAM,WAAW,gBAAgB,SACrC,SAAQ,QAAQ,OAAhB;EACC,KAAK;AACJ,WAAQ,WAAW,QAAQ,SAAS,WAAW;AAC9C,yBAAqB,QAAQA,UAAI,KAAK,gBAAgB;KACrD;AACF;EACD,KAAK;AACJ,wBAAqB,QAAQ,gBAAgB,SAASA,UAAI,SAAS,gBAAgB;AACnF;;;AAKJ,SAAS,qBACR,KACA,QACA,iBACC;AACD,KAAI,IAAI,UAAU,QACjB;CAED,MAAM,QAAQ,gBAAgB,OAAO,IAAI;AAEzC,KAAI,MAAM,UAAU,iBACnB;AAGD,iBAAgB,OAAO,IAAI,SAAS,OAAO,KAAK,OAAO,UAAU,MAAM,eAAe,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.d.mts","names":[],"sources":["../../src/transactions/serializer.ts"],"
|
|
1
|
+
{"version":3,"file":"serializer.d.mts","names":[],"sources":["../../src/transactions/serializer.ts"],"mappings":";;;;;;iBAoCgB,gBAAA,CACf,aAAA,EAAe,iBAAA,CAAkB,iBAAA,GAC/B,OAAA;AAAA,iBA4Da,iCAAA,CACf,IAAA,EAAM,wBAAA,GACJ,iBAAA,CAAkB,aAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { normalizeHaneulAddress } from "../utils/haneul-types.mjs";
|
|
2
|
-
import { bcs as
|
|
2
|
+
import { bcs as haneulBcs } from "../bcs/index.mjs";
|
|
3
3
|
import { HANEUL_FRAMEWORK_ADDRESS, MOVE_STDLIB_ADDRESS } from "../utils/constants.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/transactions/serializer.ts
|
|
@@ -22,35 +22,35 @@ function isTxContext(param) {
|
|
|
22
22
|
}
|
|
23
23
|
function getPureBcsSchema(typeSignature) {
|
|
24
24
|
switch (typeSignature.$kind) {
|
|
25
|
-
case "address": return
|
|
26
|
-
case "bool": return
|
|
27
|
-
case "u8": return
|
|
28
|
-
case "u16": return
|
|
29
|
-
case "u32": return
|
|
30
|
-
case "u64": return
|
|
31
|
-
case "u128": return
|
|
32
|
-
case "u256": return
|
|
25
|
+
case "address": return haneulBcs.Address;
|
|
26
|
+
case "bool": return haneulBcs.Bool;
|
|
27
|
+
case "u8": return haneulBcs.U8;
|
|
28
|
+
case "u16": return haneulBcs.U16;
|
|
29
|
+
case "u32": return haneulBcs.U32;
|
|
30
|
+
case "u64": return haneulBcs.U64;
|
|
31
|
+
case "u128": return haneulBcs.U128;
|
|
32
|
+
case "u256": return haneulBcs.U256;
|
|
33
33
|
case "vector": {
|
|
34
|
-
if (typeSignature.vector.$kind === "u8") return
|
|
34
|
+
if (typeSignature.vector.$kind === "u8") return haneulBcs.byteVector().transform({
|
|
35
35
|
input: (val) => typeof val === "string" ? new TextEncoder().encode(val) : val,
|
|
36
36
|
output: (val) => val
|
|
37
37
|
});
|
|
38
38
|
const type = getPureBcsSchema(typeSignature.vector);
|
|
39
|
-
return type ?
|
|
39
|
+
return type ? haneulBcs.vector(type) : null;
|
|
40
40
|
}
|
|
41
41
|
case "datatype": {
|
|
42
42
|
const { package: pkg, module, name } = parseTypeName(typeSignature.datatype.typeName);
|
|
43
43
|
const normalizedPkg = normalizeHaneulAddress(pkg);
|
|
44
44
|
if (normalizedPkg === MOVE_STDLIB_ADDRESS) {
|
|
45
|
-
if (module === "ascii" && name === "String") return
|
|
46
|
-
if (module === "string" && name === "String") return
|
|
45
|
+
if (module === "ascii" && name === "String") return haneulBcs.String;
|
|
46
|
+
if (module === "string" && name === "String") return haneulBcs.String;
|
|
47
47
|
if (module === "option" && name === "Option") {
|
|
48
48
|
const type = getPureBcsSchema(typeSignature.datatype.typeParameters[0]);
|
|
49
|
-
return type ?
|
|
49
|
+
return type ? haneulBcs.vector(type) : null;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
if (normalizedPkg === HANEUL_FRAMEWORK_ADDRESS) {
|
|
53
|
-
if (module === "object" && name === "ID") return
|
|
53
|
+
if (module === "object" && name === "ID") return haneulBcs.Address;
|
|
54
54
|
}
|
|
55
55
|
return null;
|
|
56
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.mjs","names":["bcs"],"sources":["../../src/transactions/serializer.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { BcsType } from '@haneullabs/bcs';\n\nimport { bcs } from '../bcs/index.js';\nimport type { HaneulMoveNormalizedType } from '../jsonRpc/index.js';\nimport { MOVE_STDLIB_ADDRESS, HANEUL_FRAMEWORK_ADDRESS } from '../utils/index.js';\nimport { normalizeHaneulAddress } from '../utils/haneul-types.js';\nimport type { HaneulClientTypes } from '../client/types.js';\n\n/**\n * Parses a type name like \"0x2::tx_context::TxContext\" into package, module, and name parts.\n */\nfunction parseTypeName(typeName: string): { package: string; module: string; name: string } {\n\tconst parts = typeName.split('::');\n\tif (parts.length !== 3) {\n\t\tthrow new Error(`Invalid type name format: ${typeName}`);\n\t}\n\treturn { package: parts[0], module: parts[1], name: parts[2] };\n}\n\nexport function isTxContext(param: HaneulClientTypes.OpenSignature): boolean {\n\tif (param.body.$kind !== 'datatype') {\n\t\treturn false;\n\t}\n\n\tconst { package: pkg, module, name } = parseTypeName(param.body.datatype.typeName);\n\n\treturn (\n\t\tnormalizeHaneulAddress(pkg) === HANEUL_FRAMEWORK_ADDRESS &&\n\t\tmodule === 'tx_context' &&\n\t\tname === 'TxContext'\n\t);\n}\n\nexport function getPureBcsSchema(\n\ttypeSignature: HaneulClientTypes.OpenSignatureBody,\n): BcsType<any> | null {\n\tswitch (typeSignature.$kind) {\n\t\tcase 'address':\n\t\t\treturn bcs.Address;\n\t\tcase 'bool':\n\t\t\treturn bcs.Bool;\n\t\tcase 'u8':\n\t\t\treturn bcs.U8;\n\t\tcase 'u16':\n\t\t\treturn bcs.U16;\n\t\tcase 'u32':\n\t\t\treturn bcs.U32;\n\t\tcase 'u64':\n\t\t\treturn bcs.U64;\n\t\tcase 'u128':\n\t\t\treturn bcs.U128;\n\t\tcase 'u256':\n\t\t\treturn bcs.U256;\n\t\tcase 'vector': {\n\t\t\tif (typeSignature.vector.$kind === 'u8') {\n\t\t\t\treturn bcs.byteVector().transform({\n\t\t\t\t\tinput: (val: string | Uint8Array) =>\n\t\t\t\t\t\ttypeof val === 'string' ? new TextEncoder().encode(val) : val,\n\t\t\t\t\toutput: (val) => val,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst type = getPureBcsSchema(typeSignature.vector);\n\t\t\treturn type ? bcs.vector(type) : null;\n\t\t}\n\t\tcase 'datatype': {\n\t\t\tconst { package: pkg, module, name } = parseTypeName(typeSignature.datatype.typeName);\n\t\t\tconst normalizedPkg = normalizeHaneulAddress(pkg);\n\n\t\t\tif (normalizedPkg === MOVE_STDLIB_ADDRESS) {\n\t\t\t\tif (module === 'ascii' && name === 'String') {\n\t\t\t\t\treturn bcs.String;\n\t\t\t\t}\n\t\t\t\tif (module === 'string' && name === 'String') {\n\t\t\t\t\treturn bcs.String;\n\t\t\t\t}\n\t\t\t\tif (module === 'option' && name === 'Option') {\n\t\t\t\t\tconst type = getPureBcsSchema(typeSignature.datatype.typeParameters[0]);\n\t\t\t\t\treturn type ? bcs.vector(type) : null;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (normalizedPkg === HANEUL_FRAMEWORK_ADDRESS) {\n\t\t\t\tif (module === 'object' && name === 'ID') {\n\t\t\t\t\treturn bcs.Address;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn null;\n\t\t}\n\t\tcase 'typeParameter':\n\t\tcase 'unknown':\n\t\t\treturn null;\n\t}\n}\n\nexport function normalizedTypeToMoveTypeSignature(\n\ttype: HaneulMoveNormalizedType,\n): HaneulClientTypes.OpenSignature {\n\tif (typeof type === 'object' && 'Reference' in type) {\n\t\treturn {\n\t\t\treference: 'immutable',\n\t\t\tbody: normalizedTypeToMoveTypeSignatureBody(type.Reference),\n\t\t};\n\t}\n\tif (typeof type === 'object' && 'MutableReference' in type) {\n\t\treturn {\n\t\t\treference: 'mutable',\n\t\t\tbody: normalizedTypeToMoveTypeSignatureBody(type.MutableReference),\n\t\t};\n\t}\n\n\treturn {\n\t\treference: null,\n\t\tbody: normalizedTypeToMoveTypeSignatureBody(type),\n\t};\n}\n\nfunction normalizedTypeToMoveTypeSignatureBody(\n\ttype: HaneulMoveNormalizedType,\n): HaneulClientTypes.OpenSignatureBody {\n\tif (typeof type === 'string') {\n\t\tswitch (type) {\n\t\t\tcase 'Address':\n\t\t\t\treturn { $kind: 'address' };\n\t\t\tcase 'Bool':\n\t\t\t\treturn { $kind: 'bool' };\n\t\t\tcase 'U8':\n\t\t\t\treturn { $kind: 'u8' };\n\t\t\tcase 'U16':\n\t\t\t\treturn { $kind: 'u16' };\n\t\t\tcase 'U32':\n\t\t\t\treturn { $kind: 'u32' };\n\t\t\tcase 'U64':\n\t\t\t\treturn { $kind: 'u64' };\n\t\t\tcase 'U128':\n\t\t\t\treturn { $kind: 'u128' };\n\t\t\tcase 'U256':\n\t\t\t\treturn { $kind: 'u256' };\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unexpected type ${type}`);\n\t\t}\n\t}\n\n\tif ('Vector' in type) {\n\t\treturn { $kind: 'vector', vector: normalizedTypeToMoveTypeSignatureBody(type.Vector) };\n\t}\n\n\tif ('Struct' in type) {\n\t\treturn {\n\t\t\t$kind: 'datatype',\n\t\t\tdatatype: {\n\t\t\t\ttypeName: `${type.Struct.address}::${type.Struct.module}::${type.Struct.name}`,\n\t\t\t\ttypeParameters: type.Struct.typeArguments.map(normalizedTypeToMoveTypeSignatureBody),\n\t\t\t},\n\t\t};\n\t}\n\n\tif ('TypeParameter' in type) {\n\t\treturn { $kind: 'typeParameter', index: type.TypeParameter };\n\t}\n\n\tthrow new Error(`Unexpected type ${JSON.stringify(type)}`);\n}\n\nexport function pureBcsSchemaFromOpenSignatureBody(\n\ttypeSignature: HaneulClientTypes.OpenSignatureBody,\n): BcsType<any> {\n\tswitch (typeSignature.$kind) {\n\t\tcase 'address':\n\t\t\treturn bcs.Address;\n\t\tcase 'bool':\n\t\t\treturn bcs.Bool;\n\t\tcase 'u8':\n\t\t\treturn bcs.U8;\n\t\tcase 'u16':\n\t\t\treturn bcs.U16;\n\t\tcase 'u32':\n\t\t\treturn bcs.U32;\n\t\tcase 'u64':\n\t\t\treturn bcs.U64;\n\t\tcase 'u128':\n\t\t\treturn bcs.U128;\n\t\tcase 'u256':\n\t\t\treturn bcs.U256;\n\t\tcase 'vector':\n\t\t\treturn bcs.vector(pureBcsSchemaFromOpenSignatureBody(typeSignature.vector));\n\t\tdefault:\n\t\t\tthrow new Error(`Expected pure typeSignature, but got ${JSON.stringify(typeSignature)}`);\n\t}\n}\n"],"mappings":";;;;;;;;AAcA,SAAS,cAAc,UAAqE;CAC3F,MAAM,QAAQ,SAAS,MAAM,KAAK;AAClC,KAAI,MAAM,WAAW,EACpB,OAAM,IAAI,MAAM,6BAA6B,WAAW;AAEzD,QAAO;EAAE,SAAS,MAAM;EAAI,QAAQ,MAAM;EAAI,MAAM,MAAM;EAAI;;AAG/D,SAAgB,YAAY,OAAiD;AAC5E,KAAI,MAAM,KAAK,UAAU,WACxB,QAAO;CAGR,MAAM,EAAE,SAAS,KAAK,QAAQ,SAAS,cAAc,MAAM,KAAK,SAAS,SAAS;AAElF,QACC,uBAAuB,IAAI,KAAK,4BAChC,WAAW,gBACX,SAAS;;AAIX,SAAgB,iBACf,eACsB;AACtB,SAAQ,cAAc,OAAtB;EACC,KAAK,UACJ,QAAOA,
|
|
1
|
+
{"version":3,"file":"serializer.mjs","names":["bcs"],"sources":["../../src/transactions/serializer.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { BcsType } from '@haneullabs/bcs';\n\nimport { bcs } from '../bcs/index.js';\nimport type { HaneulMoveNormalizedType } from '../jsonRpc/index.js';\nimport { MOVE_STDLIB_ADDRESS, HANEUL_FRAMEWORK_ADDRESS } from '../utils/index.js';\nimport { normalizeHaneulAddress } from '../utils/haneul-types.js';\nimport type { HaneulClientTypes } from '../client/types.js';\n\n/**\n * Parses a type name like \"0x2::tx_context::TxContext\" into package, module, and name parts.\n */\nfunction parseTypeName(typeName: string): { package: string; module: string; name: string } {\n\tconst parts = typeName.split('::');\n\tif (parts.length !== 3) {\n\t\tthrow new Error(`Invalid type name format: ${typeName}`);\n\t}\n\treturn { package: parts[0], module: parts[1], name: parts[2] };\n}\n\nexport function isTxContext(param: HaneulClientTypes.OpenSignature): boolean {\n\tif (param.body.$kind !== 'datatype') {\n\t\treturn false;\n\t}\n\n\tconst { package: pkg, module, name } = parseTypeName(param.body.datatype.typeName);\n\n\treturn (\n\t\tnormalizeHaneulAddress(pkg) === HANEUL_FRAMEWORK_ADDRESS &&\n\t\tmodule === 'tx_context' &&\n\t\tname === 'TxContext'\n\t);\n}\n\nexport function getPureBcsSchema(\n\ttypeSignature: HaneulClientTypes.OpenSignatureBody,\n): BcsType<any> | null {\n\tswitch (typeSignature.$kind) {\n\t\tcase 'address':\n\t\t\treturn bcs.Address;\n\t\tcase 'bool':\n\t\t\treturn bcs.Bool;\n\t\tcase 'u8':\n\t\t\treturn bcs.U8;\n\t\tcase 'u16':\n\t\t\treturn bcs.U16;\n\t\tcase 'u32':\n\t\t\treturn bcs.U32;\n\t\tcase 'u64':\n\t\t\treturn bcs.U64;\n\t\tcase 'u128':\n\t\t\treturn bcs.U128;\n\t\tcase 'u256':\n\t\t\treturn bcs.U256;\n\t\tcase 'vector': {\n\t\t\tif (typeSignature.vector.$kind === 'u8') {\n\t\t\t\treturn bcs.byteVector().transform({\n\t\t\t\t\tinput: (val: string | Uint8Array) =>\n\t\t\t\t\t\ttypeof val === 'string' ? new TextEncoder().encode(val) : val,\n\t\t\t\t\toutput: (val) => val,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst type = getPureBcsSchema(typeSignature.vector);\n\t\t\treturn type ? bcs.vector(type) : null;\n\t\t}\n\t\tcase 'datatype': {\n\t\t\tconst { package: pkg, module, name } = parseTypeName(typeSignature.datatype.typeName);\n\t\t\tconst normalizedPkg = normalizeHaneulAddress(pkg);\n\n\t\t\tif (normalizedPkg === MOVE_STDLIB_ADDRESS) {\n\t\t\t\tif (module === 'ascii' && name === 'String') {\n\t\t\t\t\treturn bcs.String;\n\t\t\t\t}\n\t\t\t\tif (module === 'string' && name === 'String') {\n\t\t\t\t\treturn bcs.String;\n\t\t\t\t}\n\t\t\t\tif (module === 'option' && name === 'Option') {\n\t\t\t\t\tconst type = getPureBcsSchema(typeSignature.datatype.typeParameters[0]);\n\t\t\t\t\treturn type ? bcs.vector(type) : null;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (normalizedPkg === HANEUL_FRAMEWORK_ADDRESS) {\n\t\t\t\tif (module === 'object' && name === 'ID') {\n\t\t\t\t\treturn bcs.Address;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn null;\n\t\t}\n\t\tcase 'typeParameter':\n\t\tcase 'unknown':\n\t\t\treturn null;\n\t}\n}\n\nexport function normalizedTypeToMoveTypeSignature(\n\ttype: HaneulMoveNormalizedType,\n): HaneulClientTypes.OpenSignature {\n\tif (typeof type === 'object' && 'Reference' in type) {\n\t\treturn {\n\t\t\treference: 'immutable',\n\t\t\tbody: normalizedTypeToMoveTypeSignatureBody(type.Reference),\n\t\t};\n\t}\n\tif (typeof type === 'object' && 'MutableReference' in type) {\n\t\treturn {\n\t\t\treference: 'mutable',\n\t\t\tbody: normalizedTypeToMoveTypeSignatureBody(type.MutableReference),\n\t\t};\n\t}\n\n\treturn {\n\t\treference: null,\n\t\tbody: normalizedTypeToMoveTypeSignatureBody(type),\n\t};\n}\n\nfunction normalizedTypeToMoveTypeSignatureBody(\n\ttype: HaneulMoveNormalizedType,\n): HaneulClientTypes.OpenSignatureBody {\n\tif (typeof type === 'string') {\n\t\tswitch (type) {\n\t\t\tcase 'Address':\n\t\t\t\treturn { $kind: 'address' };\n\t\t\tcase 'Bool':\n\t\t\t\treturn { $kind: 'bool' };\n\t\t\tcase 'U8':\n\t\t\t\treturn { $kind: 'u8' };\n\t\t\tcase 'U16':\n\t\t\t\treturn { $kind: 'u16' };\n\t\t\tcase 'U32':\n\t\t\t\treturn { $kind: 'u32' };\n\t\t\tcase 'U64':\n\t\t\t\treturn { $kind: 'u64' };\n\t\t\tcase 'U128':\n\t\t\t\treturn { $kind: 'u128' };\n\t\t\tcase 'U256':\n\t\t\t\treturn { $kind: 'u256' };\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unexpected type ${type}`);\n\t\t}\n\t}\n\n\tif ('Vector' in type) {\n\t\treturn { $kind: 'vector', vector: normalizedTypeToMoveTypeSignatureBody(type.Vector) };\n\t}\n\n\tif ('Struct' in type) {\n\t\treturn {\n\t\t\t$kind: 'datatype',\n\t\t\tdatatype: {\n\t\t\t\ttypeName: `${type.Struct.address}::${type.Struct.module}::${type.Struct.name}`,\n\t\t\t\ttypeParameters: type.Struct.typeArguments.map(normalizedTypeToMoveTypeSignatureBody),\n\t\t\t},\n\t\t};\n\t}\n\n\tif ('TypeParameter' in type) {\n\t\treturn { $kind: 'typeParameter', index: type.TypeParameter };\n\t}\n\n\tthrow new Error(`Unexpected type ${JSON.stringify(type)}`);\n}\n\nexport function pureBcsSchemaFromOpenSignatureBody(\n\ttypeSignature: HaneulClientTypes.OpenSignatureBody,\n): BcsType<any> {\n\tswitch (typeSignature.$kind) {\n\t\tcase 'address':\n\t\t\treturn bcs.Address;\n\t\tcase 'bool':\n\t\t\treturn bcs.Bool;\n\t\tcase 'u8':\n\t\t\treturn bcs.U8;\n\t\tcase 'u16':\n\t\t\treturn bcs.U16;\n\t\tcase 'u32':\n\t\t\treturn bcs.U32;\n\t\tcase 'u64':\n\t\t\treturn bcs.U64;\n\t\tcase 'u128':\n\t\t\treturn bcs.U128;\n\t\tcase 'u256':\n\t\t\treturn bcs.U256;\n\t\tcase 'vector':\n\t\t\treturn bcs.vector(pureBcsSchemaFromOpenSignatureBody(typeSignature.vector));\n\t\tdefault:\n\t\t\tthrow new Error(`Expected pure typeSignature, but got ${JSON.stringify(typeSignature)}`);\n\t}\n}\n"],"mappings":";;;;;;;;AAcA,SAAS,cAAc,UAAqE;CAC3F,MAAM,QAAQ,SAAS,MAAM,KAAK;AAClC,KAAI,MAAM,WAAW,EACpB,OAAM,IAAI,MAAM,6BAA6B,WAAW;AAEzD,QAAO;EAAE,SAAS,MAAM;EAAI,QAAQ,MAAM;EAAI,MAAM,MAAM;EAAI;;AAG/D,SAAgB,YAAY,OAAiD;AAC5E,KAAI,MAAM,KAAK,UAAU,WACxB,QAAO;CAGR,MAAM,EAAE,SAAS,KAAK,QAAQ,SAAS,cAAc,MAAM,KAAK,SAAS,SAAS;AAElF,QACC,uBAAuB,IAAI,KAAK,4BAChC,WAAW,gBACX,SAAS;;AAIX,SAAgB,iBACf,eACsB;AACtB,SAAQ,cAAc,OAAtB;EACC,KAAK,UACJ,QAAOA,UAAI;EACZ,KAAK,OACJ,QAAOA,UAAI;EACZ,KAAK,KACJ,QAAOA,UAAI;EACZ,KAAK,MACJ,QAAOA,UAAI;EACZ,KAAK,MACJ,QAAOA,UAAI;EACZ,KAAK,MACJ,QAAOA,UAAI;EACZ,KAAK,OACJ,QAAOA,UAAI;EACZ,KAAK,OACJ,QAAOA,UAAI;EACZ,KAAK,UAAU;AACd,O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EACvB,KAAK,MACJ,QAAO,EAAE,OAAO,OAAO;EACxB,KAAK,MACJ,QAAO,EAAE,OAAO,OAAO;EACxB,KAAK,MACJ,QAAO,EAAE,OAAO,OAAO;EACxB,KAAK,OACJ,QAAO,EAAE,OAAO,QAAQ;EACzB,KAAK,OACJ,QAAO,EAAE,OAAO,QAAQ;EACzB,QACC,OAAM,IAAI,MAAM,mBAAmB,OAAO;;AAI7C,KAAI,YAAY,KACf,QAAO;EAAE,OAAO;EAAU,QAAQ,sCAAsC,KAAK,OAAO;EAAE;AAGvF,KAAI,YAAY,KACf,QAAO;EACN,OAAO;EACP,UAAU;GACT,UAAU,GAAG,KAAK,OAAO,QAAQ,IAAI,KAAK,OAAO,OAAO,IAAI,KAAK,OAAO;GACxE,gBAAgB,KAAK,OAAO,cAAc,IAAI,sCAAsC;GACpF;EACD;AAGF,KAAI,mBAAmB,KACtB,QAAO;EAAE,OAAO;EAAiB,OAAO,KAAK;EAAe;AAG7D,OAAM,IAAI,MAAM,mBAAmB,KAAK,UAAU,KAAK,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/transactions/utils.ts"],"
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/transactions/utils.ts"],"mappings":";;;;iBAsEgB,UAAA,CAAW,KAAA,YAAiB,KAAA,IAAS,QAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { normalizeHaneulAddress } from "./haneul-types.mjs";
|
|
2
|
+
import { TypeTagSerializer } from "../bcs/type-tag-serializer.mjs";
|
|
3
|
+
import { bcs as haneulBcs } from "../bcs/index.mjs";
|
|
4
|
+
import { deriveDynamicFieldID } from "./dynamic-fields.mjs";
|
|
5
|
+
import { ObjectRefSchema } from "../transactions/data/internal.mjs";
|
|
6
|
+
import { fromBase58, fromHex, toBase58, toHex } from "@haneullabs/bcs";
|
|
7
|
+
import { parse } from "valibot";
|
|
8
|
+
|
|
9
|
+
//#region src/utils/coin-reservation.ts
|
|
10
|
+
const HANEUL_ACCUMULATOR_ROOT_OBJECT_ID = normalizeHaneulAddress("0xacc");
|
|
11
|
+
const ACCUMULATOR_KEY_TYPE_TAG = TypeTagSerializer.parseFromStr("0x2::accumulator::Key<0x2::balance::Balance<0x2::haneul::HANEUL>>");
|
|
12
|
+
const COIN_RESERVATION_MAGIC = new Uint8Array([
|
|
13
|
+
172,
|
|
14
|
+
172,
|
|
15
|
+
172,
|
|
16
|
+
172,
|
|
17
|
+
172,
|
|
18
|
+
172,
|
|
19
|
+
172,
|
|
20
|
+
172,
|
|
21
|
+
172,
|
|
22
|
+
172,
|
|
23
|
+
172,
|
|
24
|
+
172,
|
|
25
|
+
172,
|
|
26
|
+
172,
|
|
27
|
+
172,
|
|
28
|
+
172,
|
|
29
|
+
172,
|
|
30
|
+
172,
|
|
31
|
+
172,
|
|
32
|
+
172
|
|
33
|
+
]);
|
|
34
|
+
function isCoinReservationDigest(digestBase58) {
|
|
35
|
+
return fromBase58(digestBase58).slice(12, 32).every((byte, i) => byte === COIN_RESERVATION_MAGIC[i]);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Derives the accumulator dynamic field object ID for the given owner,
|
|
39
|
+
* then XORs it with the chain identifier bytes to produce the objectId
|
|
40
|
+
* for the coin reservation ref.
|
|
41
|
+
*/
|
|
42
|
+
function deriveReservationObjectId(owner, chainIdentifier) {
|
|
43
|
+
const accBytes = fromHex(deriveDynamicFieldID(HANEUL_ACCUMULATOR_ROOT_OBJECT_ID, ACCUMULATOR_KEY_TYPE_TAG, haneulBcs.Address.serialize(owner).toBytes()).slice(2));
|
|
44
|
+
const chainBytes = fromBase58(chainIdentifier);
|
|
45
|
+
if (chainBytes.length !== 32) throw new Error(`Invalid chain identifier length: expected 32 bytes, got ${chainBytes.length}`);
|
|
46
|
+
const xored = new Uint8Array(32);
|
|
47
|
+
for (let i = 0; i < 32; i++) xored[i] = accBytes[i] ^ chainBytes[i];
|
|
48
|
+
return `0x${toHex(xored)}`;
|
|
49
|
+
}
|
|
50
|
+
function createCoinReservationRef(reservedBalance, owner, chainIdentifier, epoch) {
|
|
51
|
+
const digestBytes = new Uint8Array(32);
|
|
52
|
+
const view = new DataView(digestBytes.buffer);
|
|
53
|
+
view.setBigUint64(0, reservedBalance, true);
|
|
54
|
+
const epochNum = Number(epoch);
|
|
55
|
+
if (!Number.isSafeInteger(epochNum) || epochNum < 0 || epochNum > 4294967295) throw new Error(`Epoch ${epoch} out of u32 range for coin reservation digest`);
|
|
56
|
+
view.setUint32(8, epochNum, true);
|
|
57
|
+
digestBytes.set(COIN_RESERVATION_MAGIC, 12);
|
|
58
|
+
return parse(ObjectRefSchema, {
|
|
59
|
+
objectId: deriveReservationObjectId(owner, chainIdentifier),
|
|
60
|
+
version: "0",
|
|
61
|
+
digest: toBase58(digestBytes)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { createCoinReservationRef, isCoinReservationDigest };
|
|
67
|
+
//# sourceMappingURL=coin-reservation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coin-reservation.mjs","names":["bcs"],"sources":["../../src/utils/coin-reservation.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase58, fromHex, toBase58, toHex } from '@haneullabs/bcs';\nimport { parse } from 'valibot';\n\nimport { bcs, TypeTagSerializer } from '../bcs/index.js';\nimport { ObjectRefSchema } from '../transactions/data/internal.js';\nimport { deriveDynamicFieldID } from './dynamic-fields.js';\nimport { normalizeHaneulAddress } from './index.js';\n\nconst HANEUL_ACCUMULATOR_ROOT_OBJECT_ID = normalizeHaneulAddress('0xacc');\nconst ACCUMULATOR_KEY_TYPE_TAG = TypeTagSerializer.parseFromStr(\n\t'0x2::accumulator::Key<0x2::balance::Balance<0x2::haneul::HANEUL>>',\n);\n\nexport const COIN_RESERVATION_MAGIC = new Uint8Array([\n\t0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac,\n\t0xac, 0xac, 0xac, 0xac,\n]);\n\nexport function isCoinReservationDigest(digestBase58: string): boolean {\n\tconst digestBytes = fromBase58(digestBase58);\n\tconst last20Bytes = digestBytes.slice(12, 32);\n\treturn last20Bytes.every((byte, i) => byte === COIN_RESERVATION_MAGIC[i]);\n}\n\nexport function parseCoinReservationBalance(digestBase58: string): bigint {\n\tconst digestBytes = fromBase58(digestBase58);\n\tconst view = new DataView(digestBytes.buffer, digestBytes.byteOffset, digestBytes.byteLength);\n\treturn view.getBigUint64(0, true);\n}\n\n/**\n * Derives the accumulator dynamic field object ID for the given owner,\n * then XORs it with the chain identifier bytes to produce the objectId\n * for the coin reservation ref.\n */\nfunction deriveReservationObjectId(owner: string, chainIdentifier: string): string {\n\tconst keyBcs = bcs.Address.serialize(owner).toBytes();\n\tconst accumulatorId = deriveDynamicFieldID(\n\t\tHANEUL_ACCUMULATOR_ROOT_OBJECT_ID,\n\t\tACCUMULATOR_KEY_TYPE_TAG,\n\t\tkeyBcs,\n\t);\n\n\t// XOR the accumulator object ID bytes with the chain identifier bytes\n\tconst accBytes = fromHex(accumulatorId.slice(2));\n\tconst chainBytes = fromBase58(chainIdentifier);\n\tif (chainBytes.length !== 32) {\n\t\tthrow new Error(`Invalid chain identifier length: expected 32 bytes, got ${chainBytes.length}`);\n\t}\n\tconst xored = new Uint8Array(32);\n\tfor (let i = 0; i < 32; i++) {\n\t\txored[i] = accBytes[i] ^ chainBytes[i];\n\t}\n\treturn `0x${toHex(xored)}`;\n}\n\nexport function createCoinReservationRef(\n\treservedBalance: bigint,\n\towner: string,\n\tchainIdentifier: string,\n\tepoch: string,\n) {\n\tconst digestBytes = new Uint8Array(32);\n\tconst view = new DataView(digestBytes.buffer);\n\t// Bytes 0-7: reserved balance as LE u64\n\tview.setBigUint64(0, reservedBalance, true);\n\t// Bytes 8-11: epoch_id as LE u32\n\tconst epochNum = Number(epoch);\n\tif (!Number.isSafeInteger(epochNum) || epochNum < 0 || epochNum > 0xffffffff) {\n\t\tthrow new Error(`Epoch ${epoch} out of u32 range for coin reservation digest`);\n\t}\n\tview.setUint32(8, epochNum, true);\n\t// Bytes 12-31: magic bytes\n\tdigestBytes.set(COIN_RESERVATION_MAGIC, 12);\n\n\treturn parse(ObjectRefSchema, {\n\t\tobjectId: deriveReservationObjectId(owner, chainIdentifier),\n\t\tversion: '0',\n\t\tdigest: toBase58(digestBytes),\n\t});\n}\n"],"mappings":";;;;;;;;;AAWA,MAAM,oCAAoC,uBAAuB,QAAQ;AACzE,MAAM,2BAA2B,kBAAkB,aAClD,oEACA;AAED,MAAa,yBAAyB,IAAI,WAAW;CACpD;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAC1F;CAAM;CAAM;CAAM;CAClB,CAAC;AAEF,SAAgB,wBAAwB,cAA+B;AAGtE,QAFoB,WAAW,aAAa,CACZ,MAAM,IAAI,GAAG,CAC1B,OAAO,MAAM,MAAM,SAAS,uBAAuB,GAAG;;;;;;;AAc1E,SAAS,0BAA0B,OAAe,iBAAiC;CASlF,MAAM,WAAW,QAPK,qBACrB,mCACA,0BAHcA,UAAI,QAAQ,UAAU,MAAM,CAAC,SAAS,CAKpD,CAGsC,MAAM,EAAE,CAAC;CAChD,MAAM,aAAa,WAAW,gBAAgB;AAC9C,KAAI,WAAW,WAAW,GACzB,OAAM,IAAI,MAAM,2DAA2D,WAAW,SAAS;CAEhG,MAAM,QAAQ,IAAI,WAAW,GAAG;AAChC,MAAK,IAAI,IAAI,GAAG,IAAI,IAAI,IACvB,OAAM,KAAK,SAAS,KAAK,WAAW;AAErC,QAAO,KAAK,MAAM,MAAM;;AAGzB,SAAgB,yBACf,iBACA,OACA,iBACA,OACC;CACD,MAAM,cAAc,IAAI,WAAW,GAAG;CACtC,MAAM,OAAO,IAAI,SAAS,YAAY,OAAO;AAE7C,MAAK,aAAa,GAAG,iBAAiB,KAAK;CAE3C,MAAM,WAAW,OAAO,MAAM;AAC9B,KAAI,CAAC,OAAO,cAAc,SAAS,IAAI,WAAW,KAAK,WAAW,WACjE,OAAM,IAAI,MAAM,SAAS,MAAM,+CAA+C;AAE/E,MAAK,UAAU,GAAG,UAAU,KAAK;AAEjC,aAAY,IAAI,wBAAwB,GAAG;AAE3C,QAAO,MAAM,iBAAiB;EAC7B,UAAU,0BAA0B,OAAO,gBAAgB;EAC3D,SAAS;EACT,QAAQ,SAAS,YAAY;EAC7B,CAAC"}
|
|
@@ -9,7 +9,8 @@ declare const HANEUL_SYSTEM_MODULE_NAME = "haneul_system";
|
|
|
9
9
|
declare const HANEUL_TYPE_ARG = "0x0000000000000000000000000000000000000000000000000000000000000002::haneul::HANEUL";
|
|
10
10
|
declare const HANEUL_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
|
|
11
11
|
declare const HANEUL_RANDOM_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000008";
|
|
12
|
+
declare const HANEUL_COIN_REGISTRY_OBJECT_ID = "0x000000000000000000000000000000000000000000000000000000000000000c";
|
|
12
13
|
declare const HANEUL_DENY_LIST_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000403";
|
|
13
14
|
//#endregion
|
|
14
|
-
export { GEUNHWA_PER_HANEUL, HANEUL_CLOCK_OBJECT_ID, HANEUL_DECIMALS, HANEUL_DENY_LIST_OBJECT_ID, HANEUL_FRAMEWORK_ADDRESS, HANEUL_RANDOM_OBJECT_ID, HANEUL_SYSTEM_ADDRESS, HANEUL_SYSTEM_MODULE_NAME, HANEUL_SYSTEM_STATE_OBJECT_ID, HANEUL_TYPE_ARG, MOVE_STDLIB_ADDRESS };
|
|
15
|
+
export { GEUNHWA_PER_HANEUL, HANEUL_CLOCK_OBJECT_ID, HANEUL_COIN_REGISTRY_OBJECT_ID, HANEUL_DECIMALS, HANEUL_DENY_LIST_OBJECT_ID, HANEUL_FRAMEWORK_ADDRESS, HANEUL_RANDOM_OBJECT_ID, HANEUL_SYSTEM_ADDRESS, HANEUL_SYSTEM_MODULE_NAME, HANEUL_SYSTEM_STATE_OBJECT_ID, HANEUL_TYPE_ARG, MOVE_STDLIB_ADDRESS };
|
|
15
16
|
//# sourceMappingURL=constants.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","names":[],"sources":["../../src/utils/constants.ts"],"
|
|
1
|
+
{"version":3,"file":"constants.d.mts","names":[],"sources":["../../src/utils/constants.ts"],"mappings":";cAGa,eAAA;AAAA,cACA,kBAAA;AAAA,cAEA,mBAAA;AAAA,cAEA,wBAAA;AAAA,cAEA,qBAAA;AAAA,cAEA,sBAAA;AAAA,cAEA,yBAAA;AAAA,cACA,eAAA;AAAA,cACA,6BAAA;AAAA,cAEA,uBAAA;AAAA,cAEA,8BAAA;AAAA,cAEA,0BAAA"}
|
package/dist/utils/constants.mjs
CHANGED
|
@@ -9,8 +9,9 @@ const HANEUL_SYSTEM_MODULE_NAME = "haneul_system";
|
|
|
9
9
|
const HANEUL_TYPE_ARG = `${HANEUL_FRAMEWORK_ADDRESS}::haneul::HANEUL`;
|
|
10
10
|
const HANEUL_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
|
|
11
11
|
const HANEUL_RANDOM_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000008";
|
|
12
|
+
const HANEUL_COIN_REGISTRY_OBJECT_ID = "0x000000000000000000000000000000000000000000000000000000000000000c";
|
|
12
13
|
const HANEUL_DENY_LIST_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000403";
|
|
13
14
|
|
|
14
15
|
//#endregion
|
|
15
|
-
export { GEUNHWA_PER_HANEUL, HANEUL_CLOCK_OBJECT_ID, HANEUL_DECIMALS, HANEUL_DENY_LIST_OBJECT_ID, HANEUL_FRAMEWORK_ADDRESS, HANEUL_RANDOM_OBJECT_ID, HANEUL_SYSTEM_ADDRESS, HANEUL_SYSTEM_MODULE_NAME, HANEUL_SYSTEM_STATE_OBJECT_ID, HANEUL_TYPE_ARG, MOVE_STDLIB_ADDRESS };
|
|
16
|
+
export { GEUNHWA_PER_HANEUL, HANEUL_CLOCK_OBJECT_ID, HANEUL_COIN_REGISTRY_OBJECT_ID, HANEUL_DECIMALS, HANEUL_DENY_LIST_OBJECT_ID, HANEUL_FRAMEWORK_ADDRESS, HANEUL_RANDOM_OBJECT_ID, HANEUL_SYSTEM_ADDRESS, HANEUL_SYSTEM_MODULE_NAME, HANEUL_SYSTEM_STATE_OBJECT_ID, HANEUL_TYPE_ARG, MOVE_STDLIB_ADDRESS };
|
|
16
17
|
//# sourceMappingURL=constants.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","names":[],"sources":["../../src/utils/constants.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport const HANEUL_DECIMALS = 9;\nexport const GEUNHWA_PER_HANEUL = BigInt(1000000000);\n\nexport const MOVE_STDLIB_ADDRESS =\n\t'0x0000000000000000000000000000000000000000000000000000000000000001';\nexport const HANEUL_FRAMEWORK_ADDRESS =\n\t'0x0000000000000000000000000000000000000000000000000000000000000002';\nexport const HANEUL_SYSTEM_ADDRESS =\n\t'0x0000000000000000000000000000000000000000000000000000000000000003';\nexport const HANEUL_CLOCK_OBJECT_ID =\n\t'0x0000000000000000000000000000000000000000000000000000000000000006';\nexport const HANEUL_SYSTEM_MODULE_NAME = 'haneul_system';\nexport const HANEUL_TYPE_ARG = `${HANEUL_FRAMEWORK_ADDRESS}::haneul::HANEUL`;\nexport const HANEUL_SYSTEM_STATE_OBJECT_ID =\n\t'0x0000000000000000000000000000000000000000000000000000000000000005';\nexport const HANEUL_RANDOM_OBJECT_ID =\n\t'0x0000000000000000000000000000000000000000000000000000000000000008';\nexport const HANEUL_DENY_LIST_OBJECT_ID =\n\t'0x0000000000000000000000000000000000000000000000000000000000000403';\n"],"mappings":";AAGA,MAAa,kBAAkB;AAC/B,MAAa,qBAAqB,OAAO,IAAW;AAEpD,MAAa,sBACZ;AACD,MAAa,2BACZ;AACD,MAAa,wBACZ;AACD,MAAa,yBACZ;AACD,MAAa,4BAA4B;AACzC,MAAa,kBAAkB,GAAG,yBAAyB;AAC3D,MAAa,gCACZ;AACD,MAAa,0BACZ;AACD,MAAa,6BACZ"}
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../../src/utils/constants.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport const HANEUL_DECIMALS = 9;\nexport const GEUNHWA_PER_HANEUL = BigInt(1000000000);\n\nexport const MOVE_STDLIB_ADDRESS =\n\t'0x0000000000000000000000000000000000000000000000000000000000000001';\nexport const HANEUL_FRAMEWORK_ADDRESS =\n\t'0x0000000000000000000000000000000000000000000000000000000000000002';\nexport const HANEUL_SYSTEM_ADDRESS =\n\t'0x0000000000000000000000000000000000000000000000000000000000000003';\nexport const HANEUL_CLOCK_OBJECT_ID =\n\t'0x0000000000000000000000000000000000000000000000000000000000000006';\nexport const HANEUL_SYSTEM_MODULE_NAME = 'haneul_system';\nexport const HANEUL_TYPE_ARG = `${HANEUL_FRAMEWORK_ADDRESS}::haneul::HANEUL`;\nexport const HANEUL_SYSTEM_STATE_OBJECT_ID =\n\t'0x0000000000000000000000000000000000000000000000000000000000000005';\nexport const HANEUL_RANDOM_OBJECT_ID =\n\t'0x0000000000000000000000000000000000000000000000000000000000000008';\nexport const HANEUL_COIN_REGISTRY_OBJECT_ID =\n\t'0x000000000000000000000000000000000000000000000000000000000000000c';\nexport const HANEUL_DENY_LIST_OBJECT_ID =\n\t'0x0000000000000000000000000000000000000000000000000000000000000403';\n"],"mappings":";AAGA,MAAa,kBAAkB;AAC/B,MAAa,qBAAqB,OAAO,IAAW;AAEpD,MAAa,sBACZ;AACD,MAAa,2BACZ;AACD,MAAa,wBACZ;AACD,MAAa,yBACZ;AACD,MAAa,4BAA4B;AACzC,MAAa,kBAAkB,GAAG,yBAAyB;AAC3D,MAAa,gCACZ;AACD,MAAa,0BACZ;AACD,MAAa,iCACZ;AACD,MAAa,6BACZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derived-objects.d.mts","names":[],"sources":["../../src/utils/derived-objects.ts"],"
|
|
1
|
+
{"version":3,"file":"derived-objects.d.mts","names":[],"sources":["../../src/utils/derived-objects.ts"],"mappings":";;;;;AAUA;iBAAgB,cAAA,CACf,QAAA,UACA,OAAA,SAAgB,OAAA,CAAQ,WAAA,EACxB,GAAA,EAAK,UAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-fields.d.mts","names":[],"sources":["../../src/utils/dynamic-fields.ts"],"
|
|
1
|
+
{"version":3,"file":"dynamic-fields.d.mts","names":[],"sources":["../../src/utils/dynamic-fields.ts"],"mappings":";;;iBASgB,oBAAA,CACf,QAAA,UACA,OAAA,SAAgB,OAAA,CAAQ,WAAA,EACxB,GAAA,EAAK,UAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { bcs as
|
|
1
|
+
import { bcs as haneulBcs } from "../bcs/index.mjs";
|
|
2
2
|
import { toHex } from "@haneullabs/bcs";
|
|
3
3
|
import { blake2b } from "@noble/hashes/blake2.js";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/dynamic-fields.ts
|
|
6
6
|
function deriveDynamicFieldID(parentId, typeTag, key) {
|
|
7
|
-
const address =
|
|
8
|
-
const tag =
|
|
9
|
-
const keyLength =
|
|
7
|
+
const address = haneulBcs.Address.serialize(parentId).toBytes();
|
|
8
|
+
const tag = haneulBcs.TypeTag.serialize(typeTag).toBytes();
|
|
9
|
+
const keyLength = haneulBcs.u64().serialize(key.length).toBytes();
|
|
10
10
|
const hash = blake2b.create({ dkLen: 32 });
|
|
11
11
|
hash.update(new Uint8Array([240]));
|
|
12
12
|
hash.update(address);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-fields.mjs","names":["bcs"],"sources":["../../src/utils/dynamic-fields.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toHex } from '@haneullabs/bcs';\nimport { blake2b } from '@noble/hashes/blake2.js';\n\nimport type { TypeTag } from '../bcs/bcs.js';\nimport { bcs } from '../bcs/index.js';\n\nexport function deriveDynamicFieldID(\n\tparentId: string,\n\ttypeTag: typeof TypeTag.$inferInput,\n\tkey: Uint8Array,\n) {\n\tconst address = bcs.Address.serialize(parentId).toBytes();\n\tconst tag = bcs.TypeTag.serialize(typeTag).toBytes();\n\tconst keyLength = bcs.u64().serialize(key.length).toBytes();\n\n\tconst hash = blake2b.create({\n\t\tdkLen: 32,\n\t});\n\n\thash.update(new Uint8Array([0xf0]));\n\thash.update(address);\n\thash.update(keyLength);\n\thash.update(key);\n\thash.update(tag);\n\n\treturn `0x${toHex(hash.digest().slice(0, 32))}`;\n}\n"],"mappings":";;;;;AASA,SAAgB,qBACf,UACA,SACA,KACC;CACD,MAAM,UAAUA,
|
|
1
|
+
{"version":3,"file":"dynamic-fields.mjs","names":["bcs"],"sources":["../../src/utils/dynamic-fields.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toHex } from '@haneullabs/bcs';\nimport { blake2b } from '@noble/hashes/blake2.js';\n\nimport type { TypeTag } from '../bcs/bcs.js';\nimport { bcs } from '../bcs/index.js';\n\nexport function deriveDynamicFieldID(\n\tparentId: string,\n\ttypeTag: typeof TypeTag.$inferInput,\n\tkey: Uint8Array,\n) {\n\tconst address = bcs.Address.serialize(parentId).toBytes();\n\tconst tag = bcs.TypeTag.serialize(typeTag).toBytes();\n\tconst keyLength = bcs.u64().serialize(key.length).toBytes();\n\n\tconst hash = blake2b.create({\n\t\tdkLen: 32,\n\t});\n\n\thash.update(new Uint8Array([0xf0]));\n\thash.update(address);\n\thash.update(keyLength);\n\thash.update(key);\n\thash.update(tag);\n\n\treturn `0x${toHex(hash.digest().slice(0, 32))}`;\n}\n"],"mappings":";;;;;AASA,SAAgB,qBACf,UACA,SACA,KACC;CACD,MAAM,UAAUA,UAAI,QAAQ,UAAU,SAAS,CAAC,SAAS;CACzD,MAAM,MAAMA,UAAI,QAAQ,UAAU,QAAQ,CAAC,SAAS;CACpD,MAAM,YAAYA,UAAI,KAAK,CAAC,UAAU,IAAI,OAAO,CAAC,SAAS;CAE3D,MAAM,OAAO,QAAQ,OAAO,EAC3B,OAAO,IACP,CAAC;AAEF,MAAK,OAAO,IAAI,WAAW,CAAC,IAAK,CAAC,CAAC;AACnC,MAAK,OAAO,QAAQ;AACpB,MAAK,OAAO,UAAU;AACtB,MAAK,OAAO,IAAI;AAChB,MAAK,OAAO,IAAI;AAEhB,QAAO,KAAK,MAAM,KAAK,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.mts","names":[],"sources":["../../src/utils/format.ts"],"
|
|
1
|
+
{"version":3,"file":"format.d.mts","names":[],"sources":["../../src/utils/format.ts"],"mappings":";iBAKgB,aAAA,CAAc,OAAA;AAAA,iBAUd,YAAA,CAAa,MAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"haneul-types.d.mts","names":[],"sources":["../../src/utils/haneul-types.ts"],"
|
|
1
|
+
{"version":3,"file":"haneul-types.d.mts","names":[],"sources":["../../src/utils/haneul-types.ts"],"mappings":";;iBAUgB,wBAAA,CAAyB,KAAA,WAAgB,KAAA;AAAA,cAe5C,qBAAA;AAAA,iBACG,oBAAA,CAAqB,KAAA,WAAgB,KAAA;AAAA,iBAIrC,qBAAA,CAAsB,KAAA;AAAA,iBAoDtB,gBAAA,CAAiB,IAAA;AAAA,KASrB,SAAA;EACX,OAAA;EACA,MAAA;EACA,IAAA;EACA,UAAA,YAAsB,SAAA;AAAA;AAAA,iBAwBP,cAAA,CAAe,IAAA,WAAe,SAAA;AAAA,iBA0B9B,kBAAA,CAAmB,IAAA,WAAe,SAAA;;AAnHlD;;;;;AAoDA;;;;;iBA0FgB,sBAAA,CAAuB,KAAA,UAAe,UAAA;AAAA,iBAQtC,uBAAA,CAAwB,KAAA,UAAe,UAAA"}
|
|
@@ -57,6 +57,14 @@ function isValidStructTag(type) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
function parseTypeTag(type) {
|
|
60
|
+
if (type.startsWith("vector<")) {
|
|
61
|
+
if (!type.endsWith(">")) throw new Error(`Invalid type tag: ${type}`);
|
|
62
|
+
const inner = type.slice(7, -1);
|
|
63
|
+
if (!inner) throw new Error(`Invalid type tag: ${type}`);
|
|
64
|
+
const parsed = parseTypeTag(inner);
|
|
65
|
+
if (typeof parsed === "string") return `vector<${parsed}>`;
|
|
66
|
+
return `vector<${normalizeStructTag(parsed)}>`;
|
|
67
|
+
}
|
|
60
68
|
if (!type.includes("::")) return type;
|
|
61
69
|
return parseStructTag(type);
|
|
62
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"haneul-types.mjs","names":[],"sources":["../../src/utils/haneul-types.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase58, splitGenericParameters } from '@haneullabs/bcs';\n\nimport { isValidNamedPackage } from './move-registry.js';\n\nconst TX_DIGEST_LENGTH = 32;\n\n/** Returns whether the tx digest is valid based on the serialization format */\nexport function isValidTransactionDigest(value: string): value is string {\n\ttry {\n\t\tconst buffer = fromBase58(value);\n\t\treturn buffer.length === TX_DIGEST_LENGTH;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n// TODO - can we automatically sync this with rust length definition?\n// Source of truth is\n// https://github.com/GeunhwaJeong/haneul/blob/acb2b97ae21f47600e05b0d28127d88d0725561d/
|
|
1
|
+
{"version":3,"file":"haneul-types.mjs","names":[],"sources":["../../src/utils/haneul-types.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase58, splitGenericParameters } from '@haneullabs/bcs';\n\nimport { isValidNamedPackage } from './move-registry.js';\n\nconst TX_DIGEST_LENGTH = 32;\n\n/** Returns whether the tx digest is valid based on the serialization format */\nexport function isValidTransactionDigest(value: string): value is string {\n\ttry {\n\t\tconst buffer = fromBase58(value);\n\t\treturn buffer.length === TX_DIGEST_LENGTH;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n// TODO - can we automatically sync this with rust length definition?\n// Source of truth is\n// https://github.com/GeunhwaJeong/haneul/blob/acb2b97ae21f47600e05b0d28127d88d0725561d/crates/haneul-types/src/base_types.rs#L67\n// which uses the Move account address length\n// https://github.com/move-language/move/blob/67ec40dc50c66c34fd73512fcc412f3b68d67235/language/move-core/types/src/account_address.rs#L23 .\n\nexport const HANEUL_ADDRESS_LENGTH = 32;\nexport function isValidHaneulAddress(value: string): value is string {\n\treturn isHex(value) && getHexByteLength(value) === HANEUL_ADDRESS_LENGTH;\n}\n\nexport function isValidHaneulObjectId(value: string): boolean {\n\treturn isValidHaneulAddress(value);\n}\n\nconst MOVE_IDENTIFIER_REGEX = /^[a-zA-Z][a-zA-Z0-9_]*$/;\n\nexport function isValidMoveIdentifier(name: string): boolean {\n\treturn MOVE_IDENTIFIER_REGEX.test(name);\n}\n\nconst PRIMITIVE_TYPE_TAGS = [\n\t'bool',\n\t'u8',\n\t'u16',\n\t'u32',\n\t'u64',\n\t'u128',\n\t'u256',\n\t'address',\n\t'signer',\n];\n\nconst VECTOR_TYPE_REGEX = /^vector<(.+)>$/;\n\nfunction isValidTypeTag(type: string): boolean {\n\tif (PRIMITIVE_TYPE_TAGS.includes(type)) return true;\n\n\tconst vectorMatch = type.match(VECTOR_TYPE_REGEX);\n\tif (vectorMatch) return isValidTypeTag(vectorMatch[1]);\n\n\tif (type.includes('::')) return isValidStructTag(type);\n\n\treturn false;\n}\n\nfunction isValidParsedStructTag(tag: StructTag): boolean {\n\tif (!isValidHaneulAddress(tag.address) && !isValidNamedPackage(tag.address)) {\n\t\treturn false;\n\t}\n\n\tif (!isValidMoveIdentifier(tag.module) || !isValidMoveIdentifier(tag.name)) {\n\t\treturn false;\n\t}\n\n\treturn tag.typeParams.every((param) => {\n\t\tif (typeof param === 'string') {\n\t\t\treturn isValidTypeTag(param);\n\t\t}\n\t\treturn isValidParsedStructTag(param);\n\t});\n}\n\nexport function isValidStructTag(type: string): boolean {\n\ttry {\n\t\tconst tag = parseStructTag(type);\n\t\treturn isValidParsedStructTag(tag);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport type StructTag = {\n\taddress: string;\n\tmodule: string;\n\tname: string;\n\ttypeParams: (string | StructTag)[];\n};\n\nfunction parseTypeTag(type: string): string | StructTag {\n\tif (type.startsWith('vector<')) {\n\t\tif (!type.endsWith('>')) {\n\t\t\tthrow new Error(`Invalid type tag: ${type}`);\n\t\t}\n\t\tconst inner = type.slice(7, -1);\n\t\tif (!inner) {\n\t\t\tthrow new Error(`Invalid type tag: ${type}`);\n\t\t}\n\t\tconst parsed = parseTypeTag(inner);\n\t\tif (typeof parsed === 'string') {\n\t\t\treturn `vector<${parsed}>`;\n\t\t}\n\t\treturn `vector<${normalizeStructTag(parsed)}>`;\n\t}\n\n\tif (!type.includes('::')) return type;\n\n\treturn parseStructTag(type);\n}\n\nexport function parseStructTag(type: string): StructTag {\n\tconst parts = type.split('::');\n\n\tif (parts.length < 3) {\n\t\tthrow new Error(`Invalid struct tag: ${type}`);\n\t}\n\n\tconst [address, module] = parts;\n\tconst isMvrPackage = isValidNamedPackage(address);\n\n\tconst rest = type.slice(address.length + module.length + 4);\n\tconst name = rest.includes('<') ? rest.slice(0, rest.indexOf('<')) : rest;\n\tconst typeParams = rest.includes('<')\n\t\t? splitGenericParameters(rest.slice(rest.indexOf('<') + 1, rest.lastIndexOf('>'))).map(\n\t\t\t\t(typeParam) => parseTypeTag(typeParam.trim()),\n\t\t\t)\n\t\t: [];\n\n\treturn {\n\t\taddress: isMvrPackage ? address : normalizeHaneulAddress(address),\n\t\tmodule,\n\t\tname,\n\t\ttypeParams,\n\t};\n}\n\nexport function normalizeStructTag(type: string | StructTag): string {\n\tconst { address, module, name, typeParams } =\n\t\ttypeof type === 'string' ? parseStructTag(type) : type;\n\n\tconst formattedTypeParams =\n\t\ttypeParams?.length > 0\n\t\t\t? `<${typeParams\n\t\t\t\t\t.map((typeParam) =>\n\t\t\t\t\t\ttypeof typeParam === 'string' ? typeParam : normalizeStructTag(typeParam),\n\t\t\t\t\t)\n\t\t\t\t\t.join(',')}>`\n\t\t\t: '';\n\n\treturn `${address}::${module}::${name}${formattedTypeParams}`;\n}\n\n/**\n * Perform the following operations:\n * 1. Make the address lower case\n * 2. Prepend `0x` if the string does not start with `0x`.\n * 3. Add more zeros if the length of the address(excluding `0x`) is less than `HANEUL_ADDRESS_LENGTH`\n *\n * WARNING: if the address value itself starts with `0x`, e.g., `0x0x`, the default behavior\n * is to treat the first `0x` not as part of the address. The default behavior can be overridden by\n * setting `forceAdd0x` to true\n *\n */\nexport function normalizeHaneulAddress(value: string, forceAdd0x: boolean = false): string {\n\tlet address = value.toLowerCase();\n\tif (!forceAdd0x && address.startsWith('0x')) {\n\t\taddress = address.slice(2);\n\t}\n\treturn `0x${address.padStart(HANEUL_ADDRESS_LENGTH * 2, '0')}`;\n}\n\nexport function normalizeHaneulObjectId(value: string, forceAdd0x: boolean = false): string {\n\treturn normalizeHaneulAddress(value, forceAdd0x);\n}\n\nfunction isHex(value: string): boolean {\n\treturn /^(0x|0X)?[a-fA-F0-9]+$/.test(value) && value.length % 2 === 0;\n}\n\nfunction getHexByteLength(value: string): number {\n\tretur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AAC,KACX;;;;;;;;;;;;;AAgBL,SAAgB,uBAAuB,OAAe,aAAsB,OAAe;CAC1F,IAAI,UAAU,MAAM,aAAa;AACjC,KAAI,CAAC,cAAc,QAAQ,WAAW,KAAK,CAC1C,WAAU,QAAQ,MAAM,EAAE;AAE3B,QAAO,KAAK,QAAQ,SAAS,wBAAwB,GAAG,IAAI;;AAG7D,SAAgB,wBAAwB,OAAe,aAAsB,OAAe;AAC3F,QAAO,uBAAuB,OAAO,WAAW;;AAGjD,SAAS,MAAM,OAAwB;AACtC,QAAO,yBAAyB,KAAK,MAAM,IAAI,MAAM,SAAS,MAAM;;AAGrE,SAAS,iBAAiB,OAAuB;AAChD,QAAO,WAAW,KAAK,MAAM,IAAI,MAAM,SAAS,KAAK,IAAI,MAAM,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"haneulns.d.mts","names":[],"sources":["../../src/utils/haneulns.ts"],"
|
|
1
|
+
{"version":3,"file":"haneulns.d.mts","names":[],"sources":["../../src/utils/haneulns.ts"],"mappings":";iBAQgB,mBAAA,CAAoB,IAAA;AAAA,iBAYpB,qBAAA,CAAsB,IAAA,UAAc,MAAA"}
|