wowok 2.1.40 → 2.1.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bcs/bcs.js +1 -253
- package/dist/cjs/bcs/effects.js +1 -199
- package/dist/cjs/bcs/index.js +1 -51
- package/dist/cjs/bcs/pure.js +1 -36
- package/dist/cjs/bcs/type-tag-serializer.js +1 -104
- package/dist/cjs/bcs/types.js +1 -3
- package/dist/cjs/client/index.js +1 -4
- package/dist/cjs/client/network.js +1 -15
- package/dist/cjs/cryptography/index.js +1 -6
- package/dist/cjs/cryptography/intent.js +1 -14
- package/dist/cjs/cryptography/keypair.js +1 -74
- package/dist/cjs/cryptography/mnemonics.js +1 -20
- package/dist/cjs/cryptography/publickey.js +1 -80
- package/dist/cjs/cryptography/signature-scheme.js +1 -22
- package/dist/cjs/cryptography/signature.js +1 -41
- package/dist/cjs/experimental/cache.js +1 -58
- package/dist/cjs/experimental/client.js +1 -19
- package/dist/cjs/experimental/core.js +1 -80
- package/dist/cjs/experimental/errors.js +1 -24
- package/dist/cjs/experimental/index.js +1 -5
- package/dist/cjs/experimental/persistent-storage.js +1 -220
- package/dist/cjs/experimental/persistent-storage.test.js +1 -144
- package/dist/cjs/experimental/transports/utils.js +1 -96
- package/dist/cjs/experimental/types.js +1 -1
- package/dist/cjs/faucet/faucet.js +1 -99
- package/dist/cjs/faucet/index.js +1 -1
- package/dist/cjs/grpc/client.js +1 -42
- package/dist/cjs/grpc/core.js +1 -587
- package/dist/cjs/grpc/index.js +1 -2
- package/dist/cjs/grpc/proto/google/protobuf/any.js +1 -106
- package/dist/cjs/grpc/proto/google/protobuf/duration.js +1 -58
- package/dist/cjs/grpc/proto/google/protobuf/empty.js +1 -7
- package/dist/cjs/grpc/proto/google/protobuf/field_mask.js +1 -47
- package/dist/cjs/grpc/proto/google/protobuf/struct.js +1 -191
- package/dist/cjs/grpc/proto/google/protobuf/timestamp.js +1 -91
- package/dist/cjs/grpc/proto/google/rpc/error_details.js +1 -265
- package/dist/cjs/grpc/proto/google/rpc/status.js +1 -23
- package/dist/cjs/grpc/proto/sui/rpc/v2/argument.js +1 -46
- package/dist/cjs/grpc/proto/sui/rpc/v2/balance_change.js +1 -29
- package/dist/cjs/grpc/proto/sui/rpc/v2/bcs.js +1 -22
- package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint.js +1 -54
- package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_contents.js +1 -60
- package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_summary.js +1 -144
- package/dist/cjs/grpc/proto/sui/rpc/v2/effects.js +1 -271
- package/dist/cjs/grpc/proto/sui/rpc/v2/epoch.js +1 -64
- package/dist/cjs/grpc/proto/sui/rpc/v2/error_reason.js +1 -6
- package/dist/cjs/grpc/proto/sui/rpc/v2/event.js +1 -62
- package/dist/cjs/grpc/proto/sui/rpc/v2/executed_transaction.js +1 -64
- package/dist/cjs/grpc/proto/sui/rpc/v2/execution_status.js +1 -481
- package/dist/cjs/grpc/proto/sui/rpc/v2/gas_cost_summary.js +1 -40
- package/dist/cjs/grpc/proto/sui/rpc/v2/input.js +1 -61
- package/dist/cjs/grpc/proto/sui/rpc/v2/jwk.js +1 -57
- package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.client.js +1 -39
- package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.js +1 -329
- package/dist/cjs/grpc/proto/sui/rpc/v2/move_package.js +1 -447
- package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.client.js +1 -27
- package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.js +1 -206
- package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.client.js +1 -19
- package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.js +1 -109
- package/dist/cjs/grpc/proto/sui/rpc/v2/object.js +1 -90
- package/dist/cjs/grpc/proto/sui/rpc/v2/object_reference.js +1 -30
- package/dist/cjs/grpc/proto/sui/rpc/v2/owner.js +1 -39
- package/dist/cjs/grpc/proto/sui/rpc/v2/protocol_config.js +1 -30
- package/dist/cjs/grpc/proto/sui/rpc/v2/signature.js +1 -501
- package/dist/cjs/grpc/proto/sui/rpc/v2/signature_scheme.js +1 -10
- package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.client.js +1 -15
- package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.js +1 -62
- package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.client.js +1 -31
- package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.js +1 -504
- package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.client.js +1 -15
- package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.js +1 -37
- package/dist/cjs/grpc/proto/sui/rpc/v2/system_state.js +1 -709
- package/dist/cjs/grpc/proto/sui/rpc/v2/transaction.js +1 -950
- package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js +1 -19
- package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.js +1 -144
- package/dist/cjs/index.js +1 -22
- package/dist/cjs/jsonRpc/client.js +1 -516
- package/dist/cjs/jsonRpc/core.js +1 -587
- package/dist/cjs/jsonRpc/errors.js +1 -38
- package/dist/cjs/jsonRpc/http-transport.js +1 -70
- package/dist/cjs/jsonRpc/index.js +1 -3
- package/dist/cjs/jsonRpc/json-rpc-resolver.js +1 -296
- package/dist/cjs/jsonRpc/rpc-websocket-client.js +1 -155
- package/dist/cjs/jsonRpc/types/chain.js +1 -1
- package/dist/cjs/jsonRpc/types/changes.js +1 -1
- package/dist/cjs/jsonRpc/types/coins.js +1 -1
- package/dist/cjs/jsonRpc/types/common.js +1 -1
- package/dist/cjs/jsonRpc/types/generated.js +1 -1
- package/dist/cjs/jsonRpc/types/index.js +1 -1
- package/dist/cjs/jsonRpc/types/params.js +1 -1
- package/dist/cjs/keypairs/ed25519/ed25519-hd-key.js +1 -58
- package/dist/cjs/keypairs/ed25519/index.js +1 -2
- package/dist/cjs/keypairs/ed25519/keypair.js +1 -90
- package/dist/cjs/keypairs/ed25519/publickey.js +1 -50
- package/dist/cjs/keypairs/index.js +1 -4
- package/dist/cjs/keypairs/passkey/index.js +1 -2
- package/dist/cjs/keypairs/passkey/keypair.js +1 -155
- package/dist/cjs/keypairs/passkey/publickey.js +1 -117
- package/dist/cjs/keypairs/passkey/types.js +1 -1
- package/dist/cjs/keypairs/secp256k1/index.js +1 -2
- package/dist/cjs/keypairs/secp256k1/keypair.js +1 -82
- package/dist/cjs/keypairs/secp256k1/publickey.js +1 -51
- package/dist/cjs/keypairs/secp256r1/index.js +1 -2
- package/dist/cjs/keypairs/secp256r1/keypair.js +1 -78
- package/dist/cjs/keypairs/secp256r1/publickey.js +1 -52
- package/dist/cjs/multisig/index.js +1 -2
- package/dist/cjs/multisig/publickey.js +1 -201
- package/dist/cjs/multisig/signer.js +1 -58
- package/dist/cjs/transactions/Arguments.js +1 -9
- package/dist/cjs/transactions/Commands.js +1 -102
- package/dist/cjs/transactions/Inputs.js +1 -52
- package/dist/cjs/transactions/ObjectCache.js +1 -205
- package/dist/cjs/transactions/Transaction.js +1 -574
- package/dist/cjs/transactions/TransactionData.js +1 -409
- package/dist/cjs/transactions/__tests__/Transaction.test.js +1 -160
- package/dist/cjs/transactions/__tests__/bcs.test.js +1 -182
- package/dist/cjs/transactions/data/internal.js +1 -169
- package/dist/cjs/transactions/data/v1.js +1 -469
- package/dist/cjs/transactions/data/v2.js +1 -97
- package/dist/cjs/transactions/executor/caching.js +1 -65
- package/dist/cjs/transactions/executor/parallel.js +1 -347
- package/dist/cjs/transactions/executor/queue.js +1 -59
- package/dist/cjs/transactions/executor/serial.js +1 -99
- package/dist/cjs/transactions/hash.js +1 -8
- package/dist/cjs/transactions/index.js +1 -12
- package/dist/cjs/transactions/intents/CoinWithBalance.js +1 -145
- package/dist/cjs/transactions/object.js +1 -87
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js +1 -11
- package/dist/cjs/transactions/pure.js +1 -36
- package/dist/cjs/transactions/resolve.js +1 -69
- package/dist/cjs/transactions/serializer.js +1 -167
- package/dist/cjs/transactions/utils.js +1 -121
- package/dist/cjs/utils/constants.js +1 -18
- package/dist/cjs/utils/derived-objects.js +1 -8
- package/dist/cjs/utils/dynamic-fields.js +1 -17
- package/dist/cjs/utils/format.js +1 -11
- package/dist/cjs/utils/index.js +1 -8
- package/dist/cjs/utils/move-registry.js +1 -24
- package/dist/cjs/utils/sui-types.js +1 -66
- package/dist/cjs/utils/suins.js +1 -33
- package/dist/cjs/verify/index.js +1 -1
- package/dist/cjs/verify/verify.js +1 -87
- package/dist/cjs/version.js +1 -2
- package/dist/cjs/w/call/allocation.js +1 -345
- package/dist/cjs/w/call/arb.js +1 -103
- package/dist/cjs/w/call/arbitration.js +1 -1192
- package/dist/cjs/w/call/base.js +1 -293
- package/dist/cjs/w/call/contact.js +1 -345
- package/dist/cjs/w/call/demand.js +1 -681
- package/dist/cjs/w/call/entity.js +1 -173
- package/dist/cjs/w/call/guard-ins.js +1 -4449
- package/dist/cjs/w/call/guard.d.ts +111 -0
- package/dist/cjs/w/call/guard.js +1 -1048
- package/dist/cjs/w/call/index.js +1 -22
- package/dist/cjs/w/call/machine.js +1 -1127
- package/dist/cjs/w/call/order.js +1 -337
- package/dist/cjs/w/call/passport.js +1 -220
- package/dist/cjs/w/call/payment.js +1 -178
- package/dist/cjs/w/call/permission.js +1 -1162
- package/dist/cjs/w/call/personal.js +1 -139
- package/dist/cjs/w/call/progress.js +1 -678
- package/dist/cjs/w/call/proof.js +1 -66
- package/dist/cjs/w/call/repository.js +1 -1024
- package/dist/cjs/w/call/resource.js +1 -108
- package/dist/cjs/w/call/reward.js +1 -675
- package/dist/cjs/w/call/service.js +1 -1960
- package/dist/cjs/w/call/treasury.js +1 -873
- package/dist/cjs/w/call/util.d.ts +1 -0
- package/dist/cjs/w/call/util.js +1 -566
- package/dist/cjs/w/common.js +1 -571
- package/dist/cjs/w/exception.js +1 -618
- package/dist/cjs/w/index.js +1 -8
- package/dist/cjs/w/local/account.js +1 -656
- package/dist/cjs/w/local/cache.js +1 -161
- package/dist/cjs/w/local/config.js +1 -43
- package/dist/cjs/w/local/index.js +1 -228
- package/dist/cjs/w/local/local.js +1 -574
- package/dist/cjs/w/local/storage.js +1 -185
- package/dist/cjs/w/local/token.js +1 -131
- package/dist/cjs/w/local/util.js +1 -26
- package/dist/cjs/w/local/wip.js +1 -864
- package/dist/cjs/w/messenger/crypto.js +1 -380
- package/dist/cjs/w/messenger/index.js +1 -4
- package/dist/cjs/w/messenger/messenger-api.js +1 -1154
- package/dist/cjs/w/messenger/messenger-manager.js +1 -1003
- package/dist/cjs/w/messenger/messenger.js +1 -1093
- package/dist/cjs/w/messenger/server.js +1 -343
- package/dist/cjs/w/messenger/session.js +1 -628
- package/dist/cjs/w/messenger/storage.js +1 -1023
- package/dist/cjs/w/messenger/templates/wts-html-template.js +1 -371
- package/dist/cjs/w/messenger/types.js +1 -76
- package/dist/cjs/w/messenger/utils.js +1 -12
- package/dist/cjs/w/query/bult-in.js +1 -95
- package/dist/cjs/w/query/event.js +1 -137
- package/dist/cjs/w/query/index.js +1 -5
- package/dist/cjs/w/query/object.js +1 -1550
- package/dist/cjs/w/query/received.js +1 -62
- package/dist/cjs/w/query/util.js +1 -49
- package/dist/cjs/w/util.js +1 -587
- package/dist/esm/bcs/bcs.js +1 -253
- package/dist/esm/bcs/effects.js +1 -199
- package/dist/esm/bcs/index.js +1 -51
- package/dist/esm/bcs/pure.js +1 -36
- package/dist/esm/bcs/type-tag-serializer.js +1 -104
- package/dist/esm/bcs/types.js +1 -3
- package/dist/esm/client/index.js +1 -4
- package/dist/esm/client/network.js +1 -15
- package/dist/esm/cryptography/index.js +1 -6
- package/dist/esm/cryptography/intent.js +1 -14
- package/dist/esm/cryptography/keypair.js +1 -74
- package/dist/esm/cryptography/mnemonics.js +1 -20
- package/dist/esm/cryptography/publickey.js +1 -80
- package/dist/esm/cryptography/signature-scheme.js +1 -22
- package/dist/esm/cryptography/signature.js +1 -41
- package/dist/esm/experimental/cache.js +1 -58
- package/dist/esm/experimental/client.js +1 -19
- package/dist/esm/experimental/core.js +1 -80
- package/dist/esm/experimental/errors.js +1 -24
- package/dist/esm/experimental/index.js +1 -5
- package/dist/esm/experimental/persistent-storage.js +1 -220
- package/dist/esm/experimental/persistent-storage.test.js +1 -144
- package/dist/esm/experimental/transports/utils.js +1 -96
- package/dist/esm/experimental/types.js +1 -1
- package/dist/esm/faucet/faucet.js +1 -99
- package/dist/esm/faucet/index.js +1 -1
- package/dist/esm/grpc/client.js +1 -42
- package/dist/esm/grpc/core.js +1 -587
- package/dist/esm/grpc/index.js +1 -2
- package/dist/esm/grpc/proto/google/protobuf/any.js +1 -106
- package/dist/esm/grpc/proto/google/protobuf/duration.js +1 -58
- package/dist/esm/grpc/proto/google/protobuf/empty.js +1 -7
- package/dist/esm/grpc/proto/google/protobuf/field_mask.js +1 -47
- package/dist/esm/grpc/proto/google/protobuf/struct.js +1 -191
- package/dist/esm/grpc/proto/google/protobuf/timestamp.js +1 -91
- package/dist/esm/grpc/proto/google/rpc/error_details.js +1 -265
- package/dist/esm/grpc/proto/google/rpc/status.js +1 -23
- package/dist/esm/grpc/proto/sui/rpc/v2/argument.js +1 -46
- package/dist/esm/grpc/proto/sui/rpc/v2/balance_change.js +1 -29
- package/dist/esm/grpc/proto/sui/rpc/v2/bcs.js +1 -22
- package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint.js +1 -54
- package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_contents.js +1 -60
- package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_summary.js +1 -144
- package/dist/esm/grpc/proto/sui/rpc/v2/effects.js +1 -271
- package/dist/esm/grpc/proto/sui/rpc/v2/epoch.js +1 -64
- package/dist/esm/grpc/proto/sui/rpc/v2/error_reason.js +1 -6
- package/dist/esm/grpc/proto/sui/rpc/v2/event.js +1 -62
- package/dist/esm/grpc/proto/sui/rpc/v2/executed_transaction.js +1 -64
- package/dist/esm/grpc/proto/sui/rpc/v2/execution_status.js +1 -481
- package/dist/esm/grpc/proto/sui/rpc/v2/gas_cost_summary.js +1 -40
- package/dist/esm/grpc/proto/sui/rpc/v2/input.js +1 -61
- package/dist/esm/grpc/proto/sui/rpc/v2/jwk.js +1 -57
- package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.client.js +1 -39
- package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.js +1 -329
- package/dist/esm/grpc/proto/sui/rpc/v2/move_package.js +1 -447
- package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.client.js +1 -27
- package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.js +1 -206
- package/dist/esm/grpc/proto/sui/rpc/v2/name_service.client.js +1 -19
- package/dist/esm/grpc/proto/sui/rpc/v2/name_service.js +1 -109
- package/dist/esm/grpc/proto/sui/rpc/v2/object.js +1 -90
- package/dist/esm/grpc/proto/sui/rpc/v2/object_reference.js +1 -30
- package/dist/esm/grpc/proto/sui/rpc/v2/owner.js +1 -39
- package/dist/esm/grpc/proto/sui/rpc/v2/protocol_config.js +1 -30
- package/dist/esm/grpc/proto/sui/rpc/v2/signature.js +1 -501
- package/dist/esm/grpc/proto/sui/rpc/v2/signature_scheme.js +1 -10
- package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.client.js +1 -15
- package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.js +1 -62
- package/dist/esm/grpc/proto/sui/rpc/v2/state_service.client.js +1 -31
- package/dist/esm/grpc/proto/sui/rpc/v2/state_service.js +1 -504
- package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.client.js +1 -15
- package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.js +1 -37
- package/dist/esm/grpc/proto/sui/rpc/v2/system_state.js +1 -709
- package/dist/esm/grpc/proto/sui/rpc/v2/transaction.js +1 -950
- package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js +1 -19
- package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.js +1 -144
- package/dist/esm/index.js +1 -22
- package/dist/esm/jsonRpc/client.js +1 -516
- package/dist/esm/jsonRpc/core.js +1 -587
- package/dist/esm/jsonRpc/errors.js +1 -38
- package/dist/esm/jsonRpc/http-transport.js +1 -70
- package/dist/esm/jsonRpc/index.js +1 -3
- package/dist/esm/jsonRpc/json-rpc-resolver.js +1 -296
- package/dist/esm/jsonRpc/rpc-websocket-client.js +1 -155
- package/dist/esm/jsonRpc/types/chain.js +1 -1
- package/dist/esm/jsonRpc/types/changes.js +1 -1
- package/dist/esm/jsonRpc/types/coins.js +1 -1
- package/dist/esm/jsonRpc/types/common.js +1 -1
- package/dist/esm/jsonRpc/types/generated.js +1 -1
- package/dist/esm/jsonRpc/types/index.js +1 -1
- package/dist/esm/jsonRpc/types/params.js +1 -1
- package/dist/esm/keypairs/ed25519/ed25519-hd-key.js +1 -58
- package/dist/esm/keypairs/ed25519/index.js +1 -2
- package/dist/esm/keypairs/ed25519/keypair.js +1 -90
- package/dist/esm/keypairs/ed25519/publickey.js +1 -50
- package/dist/esm/keypairs/index.js +1 -4
- package/dist/esm/keypairs/passkey/index.js +1 -2
- package/dist/esm/keypairs/passkey/keypair.js +1 -155
- package/dist/esm/keypairs/passkey/publickey.js +1 -117
- package/dist/esm/keypairs/passkey/types.js +1 -1
- package/dist/esm/keypairs/secp256k1/index.js +1 -2
- package/dist/esm/keypairs/secp256k1/keypair.js +1 -82
- package/dist/esm/keypairs/secp256k1/publickey.js +1 -51
- package/dist/esm/keypairs/secp256r1/index.js +1 -2
- package/dist/esm/keypairs/secp256r1/keypair.js +1 -78
- package/dist/esm/keypairs/secp256r1/publickey.js +1 -52
- package/dist/esm/multisig/index.js +1 -2
- package/dist/esm/multisig/publickey.js +1 -201
- package/dist/esm/multisig/signer.js +1 -58
- package/dist/esm/transactions/Arguments.js +1 -9
- package/dist/esm/transactions/Commands.js +1 -102
- package/dist/esm/transactions/Inputs.js +1 -52
- package/dist/esm/transactions/ObjectCache.js +1 -205
- package/dist/esm/transactions/Transaction.js +1 -574
- package/dist/esm/transactions/TransactionData.js +1 -409
- package/dist/esm/transactions/__tests__/Transaction.test.js +1 -160
- package/dist/esm/transactions/__tests__/bcs.test.js +1 -182
- package/dist/esm/transactions/data/internal.js +1 -169
- package/dist/esm/transactions/data/v1.js +1 -469
- package/dist/esm/transactions/data/v2.js +1 -97
- package/dist/esm/transactions/executor/caching.js +1 -65
- package/dist/esm/transactions/executor/parallel.js +1 -347
- package/dist/esm/transactions/executor/queue.js +1 -59
- package/dist/esm/transactions/executor/serial.js +1 -99
- package/dist/esm/transactions/hash.js +1 -8
- package/dist/esm/transactions/index.js +1 -12
- package/dist/esm/transactions/intents/CoinWithBalance.js +1 -145
- package/dist/esm/transactions/object.js +1 -87
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.js +1 -11
- package/dist/esm/transactions/pure.js +1 -36
- package/dist/esm/transactions/resolve.js +1 -69
- package/dist/esm/transactions/serializer.js +1 -167
- package/dist/esm/transactions/utils.js +1 -121
- package/dist/esm/utils/constants.js +1 -18
- package/dist/esm/utils/derived-objects.js +1 -8
- package/dist/esm/utils/dynamic-fields.js +1 -17
- package/dist/esm/utils/format.js +1 -11
- package/dist/esm/utils/index.js +1 -8
- package/dist/esm/utils/move-registry.js +1 -24
- package/dist/esm/utils/sui-types.js +1 -66
- package/dist/esm/utils/suins.js +1 -33
- package/dist/esm/verify/index.js +1 -1
- package/dist/esm/verify/verify.js +1 -87
- package/dist/esm/version.js +1 -2
- package/dist/esm/w/call/allocation.js +1 -345
- package/dist/esm/w/call/arb.js +1 -103
- package/dist/esm/w/call/arbitration.js +1 -1192
- package/dist/esm/w/call/base.js +1 -293
- package/dist/esm/w/call/contact.js +1 -345
- package/dist/esm/w/call/demand.js +1 -681
- package/dist/esm/w/call/entity.js +1 -173
- package/dist/esm/w/call/guard-ins.js +1 -4449
- package/dist/esm/w/call/guard.d.ts +111 -0
- package/dist/esm/w/call/guard.js +1 -1048
- package/dist/esm/w/call/index.js +1 -22
- package/dist/esm/w/call/machine.js +1 -1127
- package/dist/esm/w/call/order.js +1 -337
- package/dist/esm/w/call/passport.js +1 -220
- package/dist/esm/w/call/payment.js +1 -178
- package/dist/esm/w/call/permission.js +1 -1162
- package/dist/esm/w/call/personal.js +1 -139
- package/dist/esm/w/call/progress.js +1 -678
- package/dist/esm/w/call/proof.js +1 -66
- package/dist/esm/w/call/repository.js +1 -1024
- package/dist/esm/w/call/resource.js +1 -108
- package/dist/esm/w/call/reward.js +1 -675
- package/dist/esm/w/call/service.js +1 -1960
- package/dist/esm/w/call/treasury.js +1 -873
- package/dist/esm/w/call/util.d.ts +1 -0
- package/dist/esm/w/call/util.js +1 -566
- package/dist/esm/w/common.js +1 -571
- package/dist/esm/w/exception.js +1 -618
- package/dist/esm/w/index.js +1 -8
- package/dist/esm/w/local/account.js +1 -656
- package/dist/esm/w/local/cache.js +1 -161
- package/dist/esm/w/local/config.js +1 -43
- package/dist/esm/w/local/index.js +1 -228
- package/dist/esm/w/local/local.js +1 -574
- package/dist/esm/w/local/storage.js +1 -185
- package/dist/esm/w/local/token.js +1 -131
- package/dist/esm/w/local/util.js +1 -26
- package/dist/esm/w/local/wip.js +1 -864
- package/dist/esm/w/messenger/crypto.js +1 -380
- package/dist/esm/w/messenger/index.js +1 -4
- package/dist/esm/w/messenger/messenger-api.js +1 -1154
- package/dist/esm/w/messenger/messenger-manager.js +1 -1003
- package/dist/esm/w/messenger/messenger.js +1 -1093
- package/dist/esm/w/messenger/server.js +1 -343
- package/dist/esm/w/messenger/session.js +1 -628
- package/dist/esm/w/messenger/storage.js +1 -1023
- package/dist/esm/w/messenger/templates/wts-html-template.js +1 -371
- package/dist/esm/w/messenger/types.js +1 -76
- package/dist/esm/w/messenger/utils.js +1 -12
- package/dist/esm/w/query/bult-in.js +1 -95
- package/dist/esm/w/query/event.js +1 -137
- package/dist/esm/w/query/index.js +1 -5
- package/dist/esm/w/query/object.js +1 -1550
- package/dist/esm/w/query/received.js +1 -62
- package/dist/esm/w/query/util.js +1 -49
- package/dist/esm/w/util.js +1 -587
- package/package.json +5 -2
|
@@ -1,656 +1 @@
|
|
|
1
|
-
import { Ed25519Keypair } from "../../keypairs/ed25519/index.js";
|
|
2
|
-
import { W_ERROR, WErrors } from "../exception.js";
|
|
3
|
-
import { GasTokenType, isGasTokenType, isValidName, MAX_NAME_LENGTH, } from "../common.js";
|
|
4
|
-
import { getFaucetHost, requestSuiFromFaucetV2 } from "../../faucet/index.js";
|
|
5
|
-
import { Transaction } from "../../transactions/index.js";
|
|
6
|
-
import { getFullnodeUrl } from "../../client/network.js";
|
|
7
|
-
import { SuiClient } from "../../client/index.js";
|
|
8
|
-
import { Config } from "./config.js";
|
|
9
|
-
import { SQLiteAccountStorage } from "./storage.js";
|
|
10
|
-
import { isValidWowAddress } from "../../utils/sui-types.js";
|
|
11
|
-
export const DEFAULT_ACCOUNT_NAME = "";
|
|
12
|
-
export const MAX_MESSENGER_ACCOUNTS = 130;
|
|
13
|
-
export class Account {
|
|
14
|
-
static _instance;
|
|
15
|
-
static storage;
|
|
16
|
-
setStorage(storage) {
|
|
17
|
-
Account.storage = storage;
|
|
18
|
-
}
|
|
19
|
-
async getStorage() {
|
|
20
|
-
if (!Account.storage) {
|
|
21
|
-
Account.storage = new SQLiteAccountStorage();
|
|
22
|
-
}
|
|
23
|
-
return Account.storage;
|
|
24
|
-
}
|
|
25
|
-
static Instance() {
|
|
26
|
-
if (!Account._instance) {
|
|
27
|
-
Account._instance = new Account();
|
|
28
|
-
}
|
|
29
|
-
return Account._instance;
|
|
30
|
-
}
|
|
31
|
-
accountData(data) {
|
|
32
|
-
if (!data || !data.secret)
|
|
33
|
-
return undefined;
|
|
34
|
-
const r = Ed25519Keypair.fromSecretKey(data.secret);
|
|
35
|
-
data.pubkey = r.getPublicKey().toWPublicKey();
|
|
36
|
-
data.secret = undefined;
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
async gen(name, replaceExistName, m) {
|
|
40
|
-
name = this.name_resolve(name);
|
|
41
|
-
if (name && !isValidName(name)) {
|
|
42
|
-
W_ERROR(WErrors.IsValidName, `Name ${name} is exceeds max ${MAX_NAME_LENGTH}`);
|
|
43
|
-
}
|
|
44
|
-
if (m && !isValidName(m)) {
|
|
45
|
-
W_ERROR(WErrors.IsValidName, `Messenger name ${m} is exceeds max ${MAX_NAME_LENGTH}`);
|
|
46
|
-
}
|
|
47
|
-
const secret = Ed25519Keypair.generate().getSecretKey();
|
|
48
|
-
const address = Ed25519Keypair.fromSecretKey(secret)
|
|
49
|
-
.getPublicKey()
|
|
50
|
-
.toWAddress();
|
|
51
|
-
const now = Date.now();
|
|
52
|
-
const ret = {
|
|
53
|
-
name: name,
|
|
54
|
-
address: address,
|
|
55
|
-
secret: secret,
|
|
56
|
-
m: undefined,
|
|
57
|
-
createdAt: now,
|
|
58
|
-
updatedAt: now,
|
|
59
|
-
};
|
|
60
|
-
const storage = await this.getStorage();
|
|
61
|
-
const value = await storage.get();
|
|
62
|
-
if (value) {
|
|
63
|
-
const data = JSON.parse(value);
|
|
64
|
-
const found = data.findIndex((d) => d.name === name);
|
|
65
|
-
if (found !== -1) {
|
|
66
|
-
if (replaceExistName) {
|
|
67
|
-
data[found].name = undefined;
|
|
68
|
-
data.push(ret);
|
|
69
|
-
await storage.put(JSON.stringify(data));
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
W_ERROR(WErrors.AccountNameExist, `Name ${name || ""} already exist`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
await storage.put(JSON.stringify([...data, ret]));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
await storage.put(JSON.stringify([ret]));
|
|
81
|
-
}
|
|
82
|
-
if (m) {
|
|
83
|
-
const storage2 = await this.getStorage();
|
|
84
|
-
const value2 = await storage2.get();
|
|
85
|
-
if (value2) {
|
|
86
|
-
const data = JSON.parse(value2);
|
|
87
|
-
const messengerCount = data.filter((d) => d.m != null).length;
|
|
88
|
-
if (messengerCount >= MAX_MESSENGER_ACCOUNTS) {
|
|
89
|
-
W_ERROR(WErrors.InvalidParam, `Maximum ${MAX_MESSENGER_ACCOUNTS} messenger accounts allowed, current count: ${messengerCount}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
ret.m = m;
|
|
93
|
-
const storage3 = await this.getStorage();
|
|
94
|
-
const value3 = await storage3.get();
|
|
95
|
-
if (value3) {
|
|
96
|
-
const data = JSON.parse(value3);
|
|
97
|
-
const account = data.find((d) => d.address === address);
|
|
98
|
-
if (account) {
|
|
99
|
-
account.m = m;
|
|
100
|
-
account.updatedAt = Date.now();
|
|
101
|
-
await storage3.put(JSON.stringify(data));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return this.accountData(ret);
|
|
106
|
-
}
|
|
107
|
-
async default() {
|
|
108
|
-
return this.accountData(await this.get_imp(DEFAULT_ACCOUNT_NAME));
|
|
109
|
-
}
|
|
110
|
-
async get(address_or_name, notFoundGenerate) {
|
|
111
|
-
if (!notFoundGenerate) {
|
|
112
|
-
return this.accountData(await this.get_imp(address_or_name));
|
|
113
|
-
}
|
|
114
|
-
return this.gen(address_or_name);
|
|
115
|
-
}
|
|
116
|
-
async get_address(address_or_name) {
|
|
117
|
-
if (address_or_name && isValidWowAddress(address_or_name)) {
|
|
118
|
-
return address_or_name.toLowerCase();
|
|
119
|
-
}
|
|
120
|
-
return (await this.get_imp(address_or_name))?.address;
|
|
121
|
-
}
|
|
122
|
-
async get_many_address(address_or_names) {
|
|
123
|
-
const storage = await this.getStorage();
|
|
124
|
-
const value = await storage.get();
|
|
125
|
-
if (value) {
|
|
126
|
-
const s = JSON.parse(value);
|
|
127
|
-
return address_or_names.map((i) => {
|
|
128
|
-
if (i && isValidWowAddress(i))
|
|
129
|
-
return i.toLowerCase();
|
|
130
|
-
const resolved = this.name_resolve(i);
|
|
131
|
-
return s.find((v) => v.address.toLowerCase() === resolved.toLowerCase() ||
|
|
132
|
-
v.name === resolved)?.address;
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
return address_or_names.map((i) => i && isValidWowAddress(i) ? i.toLowerCase() : undefined);
|
|
136
|
-
}
|
|
137
|
-
async get_imp(address_or_name) {
|
|
138
|
-
address_or_name = this.name_resolve(address_or_name);
|
|
139
|
-
const storage = await this.getStorage();
|
|
140
|
-
const value = await storage.get();
|
|
141
|
-
if (value) {
|
|
142
|
-
return JSON.parse(value).find((d) => d.name === address_or_name ||
|
|
143
|
-
d.address.toLowerCase() === address_or_name.toLowerCase());
|
|
144
|
-
}
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
147
|
-
name_resolve(address_or_name) {
|
|
148
|
-
return address_or_name || DEFAULT_ACCOUNT_NAME;
|
|
149
|
-
}
|
|
150
|
-
async get_many_imp(address_or_names) {
|
|
151
|
-
const storage = await this.getStorage();
|
|
152
|
-
const value = await storage.get();
|
|
153
|
-
if (value) {
|
|
154
|
-
const s = JSON.parse(value);
|
|
155
|
-
return address_or_names.map((i) => {
|
|
156
|
-
const resolved = this.name_resolve(i);
|
|
157
|
-
return s.find((v) => v.address.toLowerCase() === resolved.toLowerCase() ||
|
|
158
|
-
v.name === resolved);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
return address_or_names.map((_) => undefined);
|
|
162
|
-
}
|
|
163
|
-
async swap_name(name1, name2) {
|
|
164
|
-
name1 = this.name_resolve(name1);
|
|
165
|
-
name2 = this.name_resolve(name2);
|
|
166
|
-
if (name1 === name2)
|
|
167
|
-
return true;
|
|
168
|
-
if (name1 && !isValidName(name1)) {
|
|
169
|
-
W_ERROR(WErrors.IsValidName, `Name ${name1 || ""} is exceeds max ${MAX_NAME_LENGTH}`);
|
|
170
|
-
}
|
|
171
|
-
if (name2 && !isValidName(name2)) {
|
|
172
|
-
W_ERROR(WErrors.IsValidName, `Name ${name2 || ""} is exceeds max ${MAX_NAME_LENGTH}`);
|
|
173
|
-
}
|
|
174
|
-
const storage = await this.getStorage();
|
|
175
|
-
const value = await storage.get();
|
|
176
|
-
if (!value)
|
|
177
|
-
return false;
|
|
178
|
-
const data = JSON.parse(value);
|
|
179
|
-
const f1 = data.find((d) => d.name === name1);
|
|
180
|
-
const f2 = data.find((d) => d.name === name2);
|
|
181
|
-
if (!f1 || !f2)
|
|
182
|
-
return false;
|
|
183
|
-
const now = Date.now();
|
|
184
|
-
f1.name = name2;
|
|
185
|
-
f1.updatedAt = now;
|
|
186
|
-
f2.name = name1;
|
|
187
|
-
f2.updatedAt = now;
|
|
188
|
-
await storage.put(JSON.stringify(data));
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
async rename(name_or_address, new_name) {
|
|
192
|
-
if (new_name && !isValidName(new_name)) {
|
|
193
|
-
W_ERROR(WErrors.IsValidName, `Invalid new name: "${new_name || ""}". Must be a valid name (not an address)`);
|
|
194
|
-
}
|
|
195
|
-
const resolved_name = this.name_resolve(name_or_address);
|
|
196
|
-
if (resolved_name === new_name)
|
|
197
|
-
return true;
|
|
198
|
-
const storage = await this.getStorage();
|
|
199
|
-
const value = await storage.get();
|
|
200
|
-
if (value) {
|
|
201
|
-
const data = JSON.parse(value);
|
|
202
|
-
if (data.find((d) => d.name === new_name)) {
|
|
203
|
-
W_ERROR(WErrors.IsValidName, `New name "${new_name || ""}" already exists`);
|
|
204
|
-
}
|
|
205
|
-
const f = data.find((d) => d.name === resolved_name ||
|
|
206
|
-
d.address.toLowerCase() === resolved_name.toLowerCase());
|
|
207
|
-
if (!f) {
|
|
208
|
-
W_ERROR(WErrors.AccountNotFound, `Source account "${name_or_address || ""}" not found`);
|
|
209
|
-
}
|
|
210
|
-
const now = Date.now();
|
|
211
|
-
f.name = new_name;
|
|
212
|
-
f.updatedAt = now;
|
|
213
|
-
await storage.put(JSON.stringify(data));
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
async list(filter) {
|
|
219
|
-
const storage = await this.getStorage();
|
|
220
|
-
const value = await storage.get();
|
|
221
|
-
if (value) {
|
|
222
|
-
let accounts = JSON.parse(value);
|
|
223
|
-
if (filter?.suspended !== undefined) {
|
|
224
|
-
accounts = accounts.filter((v) => filter.suspended ? v.suspended === true : !v.suspended);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
accounts = accounts.filter((v) => !v.suspended);
|
|
228
|
-
}
|
|
229
|
-
if (filter?.hasMessenger !== undefined) {
|
|
230
|
-
accounts = accounts.filter((v) => filter.hasMessenger ? v.m != null : v.m == null);
|
|
231
|
-
}
|
|
232
|
-
if (filter?.m != null) {
|
|
233
|
-
accounts = accounts.filter((v) => v.m != null);
|
|
234
|
-
}
|
|
235
|
-
if (filter?.createdAt) {
|
|
236
|
-
if (filter.createdAt.gte !== undefined) {
|
|
237
|
-
accounts = accounts.filter((v) => v.createdAt &&
|
|
238
|
-
v.createdAt >= filter.createdAt.gte);
|
|
239
|
-
}
|
|
240
|
-
if (filter.createdAt.lte !== undefined) {
|
|
241
|
-
accounts = accounts.filter((v) => v.createdAt &&
|
|
242
|
-
v.createdAt <= filter.createdAt.lte);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
if (filter?.updatedAt) {
|
|
246
|
-
if (filter.updatedAt.gte !== undefined) {
|
|
247
|
-
accounts = accounts.filter((v) => v.updatedAt &&
|
|
248
|
-
v.updatedAt >= filter.updatedAt.gte);
|
|
249
|
-
}
|
|
250
|
-
if (filter.updatedAt.lte !== undefined) {
|
|
251
|
-
accounts = accounts.filter((v) => v.updatedAt &&
|
|
252
|
-
v.updatedAt <= filter.updatedAt.lte);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (filter?.name != null || filter?.address || filter?.m != null) {
|
|
256
|
-
accounts = accounts
|
|
257
|
-
.map((account) => {
|
|
258
|
-
let score = 0;
|
|
259
|
-
if (filter?.name != null) {
|
|
260
|
-
const lowerName = account.name?.toLowerCase() || "";
|
|
261
|
-
const lowerFilterName = filter.name.toLowerCase();
|
|
262
|
-
if (lowerName === lowerFilterName) {
|
|
263
|
-
score += 100;
|
|
264
|
-
}
|
|
265
|
-
else if (lowerName.startsWith(lowerFilterName)) {
|
|
266
|
-
score += 50;
|
|
267
|
-
}
|
|
268
|
-
else if (lowerName.includes(lowerFilterName)) {
|
|
269
|
-
score += 25;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (filter?.address) {
|
|
273
|
-
const lowerAddress = account.address.toLowerCase();
|
|
274
|
-
const lowerFilterAddress = filter.address.toLowerCase();
|
|
275
|
-
if (lowerAddress === lowerFilterAddress) {
|
|
276
|
-
score += 100;
|
|
277
|
-
}
|
|
278
|
-
else if (lowerAddress.startsWith(lowerFilterAddress)) {
|
|
279
|
-
score += 50;
|
|
280
|
-
}
|
|
281
|
-
else if (lowerAddress.includes(lowerFilterAddress)) {
|
|
282
|
-
score += 25;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
if (filter?.m != null && account.m != null) {
|
|
286
|
-
const lowerM = account.m.toLowerCase();
|
|
287
|
-
const lowerFilterM = filter.m.toLowerCase();
|
|
288
|
-
if (lowerM === lowerFilterM) {
|
|
289
|
-
score += 100;
|
|
290
|
-
}
|
|
291
|
-
else if (lowerM.startsWith(lowerFilterM)) {
|
|
292
|
-
score += 50;
|
|
293
|
-
}
|
|
294
|
-
else if (lowerM.includes(lowerFilterM)) {
|
|
295
|
-
score += 25;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
if ((filter?.name ||
|
|
299
|
-
filter?.address ||
|
|
300
|
-
filter?.m != null) &&
|
|
301
|
-
score === 0) {
|
|
302
|
-
score = -1;
|
|
303
|
-
}
|
|
304
|
-
return { account, score };
|
|
305
|
-
})
|
|
306
|
-
.filter(({ score }) => score >= 0)
|
|
307
|
-
.sort((a, b) => b.score - a.score)
|
|
308
|
-
.map(({ account }) => account);
|
|
309
|
-
}
|
|
310
|
-
return accounts
|
|
311
|
-
.map((v) => this.accountData(v))
|
|
312
|
-
.filter((v) => v !== undefined);
|
|
313
|
-
}
|
|
314
|
-
return [];
|
|
315
|
-
}
|
|
316
|
-
async suspend(address_or_name) {
|
|
317
|
-
address_or_name = this.name_resolve(address_or_name);
|
|
318
|
-
const storage = await this.getStorage();
|
|
319
|
-
const value = await storage.get();
|
|
320
|
-
if (value) {
|
|
321
|
-
const s = JSON.parse(value);
|
|
322
|
-
const f = s.find((v) => v.address.toLowerCase() === address_or_name.toLowerCase() ||
|
|
323
|
-
v.name === address_or_name);
|
|
324
|
-
if (f) {
|
|
325
|
-
const now = Date.now();
|
|
326
|
-
f.suspended = true;
|
|
327
|
-
f.name = undefined;
|
|
328
|
-
f.m = undefined;
|
|
329
|
-
f.updatedAt = now;
|
|
330
|
-
await storage.put(JSON.stringify(s));
|
|
331
|
-
return true;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return false;
|
|
335
|
-
}
|
|
336
|
-
async suspend_many(address_or_names) {
|
|
337
|
-
const storage = await this.getStorage();
|
|
338
|
-
const value = await storage.get();
|
|
339
|
-
const result = { success: [], failed: [] };
|
|
340
|
-
if (value) {
|
|
341
|
-
const s = JSON.parse(value);
|
|
342
|
-
const now = Date.now();
|
|
343
|
-
let modified = false;
|
|
344
|
-
for (const address_or_name of address_or_names) {
|
|
345
|
-
const resolved = this.name_resolve(address_or_name);
|
|
346
|
-
const f = s.find((v) => v.address.toLowerCase() === resolved.toLowerCase() ||
|
|
347
|
-
v.name === resolved);
|
|
348
|
-
if (f) {
|
|
349
|
-
f.suspended = true;
|
|
350
|
-
f.name = undefined;
|
|
351
|
-
f.m = undefined;
|
|
352
|
-
f.updatedAt = now;
|
|
353
|
-
result.success.push(address_or_name);
|
|
354
|
-
modified = true;
|
|
355
|
-
}
|
|
356
|
-
else {
|
|
357
|
-
result.failed.push(address_or_name);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (modified) {
|
|
361
|
-
await storage.put(JSON.stringify(s));
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
result.failed = [...address_or_names];
|
|
366
|
-
}
|
|
367
|
-
return result;
|
|
368
|
-
}
|
|
369
|
-
async resume(address, name) {
|
|
370
|
-
name = this.name_resolve(name);
|
|
371
|
-
address = address.toLowerCase();
|
|
372
|
-
const storage = await this.getStorage();
|
|
373
|
-
const value = await storage.get();
|
|
374
|
-
if (value) {
|
|
375
|
-
const s = JSON.parse(value);
|
|
376
|
-
if (s.find((v) => v.name === name)) {
|
|
377
|
-
W_ERROR(WErrors.IsValidName, `Name "${name || ""}" already exists`);
|
|
378
|
-
}
|
|
379
|
-
const f = s.find((v) => v.address.toLowerCase() === address.toLowerCase());
|
|
380
|
-
if (f) {
|
|
381
|
-
const now = Date.now();
|
|
382
|
-
f.suspended = false;
|
|
383
|
-
f.name = name;
|
|
384
|
-
f.updatedAt = now;
|
|
385
|
-
await storage.put(JSON.stringify(s));
|
|
386
|
-
return true;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
return false;
|
|
390
|
-
}
|
|
391
|
-
async faucet(address_or_name, network) {
|
|
392
|
-
const a = await this.get_imp(address_or_name);
|
|
393
|
-
if (a) {
|
|
394
|
-
try {
|
|
395
|
-
const r = await requestSuiFromFaucetV2({
|
|
396
|
-
host: getFaucetHost(network),
|
|
397
|
-
recipient: a.address,
|
|
398
|
-
});
|
|
399
|
-
return r.coins_sent || [];
|
|
400
|
-
}
|
|
401
|
-
catch (_e) {
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return [];
|
|
405
|
-
}
|
|
406
|
-
async sign_and_commit(tx, address_or_name, network) {
|
|
407
|
-
const a = await this.get_imp(address_or_name);
|
|
408
|
-
if (a) {
|
|
409
|
-
const pair = Ed25519Keypair.fromSecretKey(a.secret);
|
|
410
|
-
if (pair) {
|
|
411
|
-
const client = new SuiClient({
|
|
412
|
-
url: getFullnodeUrl(await Config.Instance().network_get(network)),
|
|
413
|
-
});
|
|
414
|
-
return client.signAndExecuteTransaction({
|
|
415
|
-
transaction: tx,
|
|
416
|
-
signer: pair,
|
|
417
|
-
options: { showObjectChanges: true, showEffects: true },
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
return undefined;
|
|
422
|
-
}
|
|
423
|
-
balance = async (token_type, address_or_name, network) => {
|
|
424
|
-
const a = await this.get(address_or_name);
|
|
425
|
-
token_type = token_type ?? GasTokenType;
|
|
426
|
-
if (a) {
|
|
427
|
-
const client = new SuiClient({
|
|
428
|
-
url: getFullnodeUrl(await Config.Instance().network_get(network)),
|
|
429
|
-
});
|
|
430
|
-
return client.getBalance({
|
|
431
|
-
owner: a.address,
|
|
432
|
-
coinType: token_type,
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
return undefined;
|
|
436
|
-
};
|
|
437
|
-
coin = async (token_type, cursor, limit, address_or_name, network) => {
|
|
438
|
-
const a = await this.get(address_or_name);
|
|
439
|
-
token_type = token_type ?? GasTokenType;
|
|
440
|
-
if (a) {
|
|
441
|
-
const client = new SuiClient({
|
|
442
|
-
url: getFullnodeUrl(await Config.Instance().network_get(network)),
|
|
443
|
-
});
|
|
444
|
-
return client.getCoins({
|
|
445
|
-
owner: a.address,
|
|
446
|
-
coinType: token_type,
|
|
447
|
-
cursor,
|
|
448
|
-
limit,
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
return undefined;
|
|
452
|
-
};
|
|
453
|
-
get_coin_object = async (txb, balance_required, token_type, address_or_name, network) => {
|
|
454
|
-
const a = await this.get(address_or_name);
|
|
455
|
-
if (a) {
|
|
456
|
-
const b = BigInt(balance_required);
|
|
457
|
-
const client = new SuiClient({
|
|
458
|
-
url: getFullnodeUrl(await Config.Instance().network_get(network)),
|
|
459
|
-
});
|
|
460
|
-
if (b >= BigInt(0)) {
|
|
461
|
-
if (!token_type || isGasTokenType(token_type)) {
|
|
462
|
-
return txb.splitCoins(txb.gas, [b]);
|
|
463
|
-
}
|
|
464
|
-
else {
|
|
465
|
-
const r = await client.getCoins({
|
|
466
|
-
owner: a.address,
|
|
467
|
-
coinType: token_type,
|
|
468
|
-
});
|
|
469
|
-
const objects = [];
|
|
470
|
-
const seen = new Set();
|
|
471
|
-
let current = BigInt(0);
|
|
472
|
-
for (let i = 0; i < r.data.length; ++i) {
|
|
473
|
-
const coinId = r.data[i].coinObjectId;
|
|
474
|
-
if (seen.has(coinId)) {
|
|
475
|
-
continue;
|
|
476
|
-
}
|
|
477
|
-
seen.add(coinId);
|
|
478
|
-
current += BigInt(r.data[i].balance);
|
|
479
|
-
objects.push(coinId);
|
|
480
|
-
if (current >= b) {
|
|
481
|
-
break;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
if (objects.length === 0) {
|
|
485
|
-
return undefined;
|
|
486
|
-
}
|
|
487
|
-
if (objects.length === 1) {
|
|
488
|
-
return txb.splitCoins(objects[0], [b]);
|
|
489
|
-
}
|
|
490
|
-
else {
|
|
491
|
-
const ret = objects.pop();
|
|
492
|
-
txb.mergeCoins(ret, objects);
|
|
493
|
-
return txb.splitCoins(ret, [b]);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
return undefined;
|
|
499
|
-
};
|
|
500
|
-
get_many_coin_object = async (txb, balance_required, token_type, address_or_name, network) => {
|
|
501
|
-
const coinObjects = [];
|
|
502
|
-
for (const balance of balance_required) {
|
|
503
|
-
const coinObject = await this.get_coin_object(txb, balance, address_or_name, token_type, network);
|
|
504
|
-
if (!coinObject) {
|
|
505
|
-
W_ERROR(WErrors.InvalidParam, `Invalid coin object: ${balance}`);
|
|
506
|
-
}
|
|
507
|
-
else {
|
|
508
|
-
coinObjects.push(coinObject);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
return txb.makeMoveVec({ elements: coinObjects });
|
|
512
|
-
};
|
|
513
|
-
async refund_coin(txb, coin, to_address_or_name) {
|
|
514
|
-
const to = await this.get_address(to_address_or_name);
|
|
515
|
-
if (!to)
|
|
516
|
-
W_ERROR(WErrors.InvalidParam, `Invalid to address or name ${to_address_or_name}`);
|
|
517
|
-
txb.transferObjects([coin], txb.pure.address(to));
|
|
518
|
-
}
|
|
519
|
-
async transfer(amount, token_type, to_address_or_name, from_address_or_name, network) {
|
|
520
|
-
const [from, to] = await this.get_many_imp([
|
|
521
|
-
from_address_or_name,
|
|
522
|
-
to_address_or_name,
|
|
523
|
-
]);
|
|
524
|
-
if (!from)
|
|
525
|
-
W_ERROR(WErrors.InvalidParam, `Invalid from address or name ${from_address_or_name}`);
|
|
526
|
-
const to_address = to?.address ?? to_address_or_name;
|
|
527
|
-
if (!to_address)
|
|
528
|
-
W_ERROR(WErrors.InvalidParam, `Invalid to address or name ${to_address_or_name}`);
|
|
529
|
-
const pair = Ed25519Keypair.fromSecretKey(from.secret);
|
|
530
|
-
if (pair) {
|
|
531
|
-
const txb = new Transaction();
|
|
532
|
-
const coin = await this.get_coin_object(txb, amount, token_type, from_address_or_name, network);
|
|
533
|
-
if (coin) {
|
|
534
|
-
txb.transferObjects([coin], to_address);
|
|
535
|
-
const client = new SuiClient({
|
|
536
|
-
url: getFullnodeUrl(await Config.Instance().network_get(network)),
|
|
537
|
-
});
|
|
538
|
-
const r = client.signAndExecuteTransaction({
|
|
539
|
-
transaction: txb,
|
|
540
|
-
signer: pair,
|
|
541
|
-
options: { showObjectChanges: true },
|
|
542
|
-
});
|
|
543
|
-
return r;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
return undefined;
|
|
547
|
-
}
|
|
548
|
-
coinObject_with_balance = async (balance_required, token_type, address_or_name, network) => {
|
|
549
|
-
const a = await this.get_imp(address_or_name);
|
|
550
|
-
if (!a)
|
|
551
|
-
return undefined;
|
|
552
|
-
const pair = Ed25519Keypair.fromSecretKey(a.secret);
|
|
553
|
-
if (!pair)
|
|
554
|
-
return undefined;
|
|
555
|
-
const txb = new Transaction();
|
|
556
|
-
const res = await this.get_coin_object(txb, balance_required, token_type, address_or_name, network);
|
|
557
|
-
if (res) {
|
|
558
|
-
txb.transferObjects([res], a.address);
|
|
559
|
-
const client = new SuiClient({
|
|
560
|
-
url: getFullnodeUrl(await Config.Instance().network_get(network)),
|
|
561
|
-
});
|
|
562
|
-
const r = await client.signAndExecuteTransaction({
|
|
563
|
-
transaction: txb,
|
|
564
|
-
signer: pair,
|
|
565
|
-
options: { showObjectChanges: true },
|
|
566
|
-
});
|
|
567
|
-
const t = token_type ?? GasTokenType;
|
|
568
|
-
return r?.objectChanges?.find((v) => v?.type === "created" &&
|
|
569
|
-
(v?.objectType).includes(t))?.objectId;
|
|
570
|
-
}
|
|
571
|
-
return undefined;
|
|
572
|
-
};
|
|
573
|
-
async sign(address_or_name, data) {
|
|
574
|
-
const account = await this.get_imp(address_or_name);
|
|
575
|
-
if (!account?.secret) {
|
|
576
|
-
W_ERROR(WErrors.InvalidParam, `Account not found or no secret key: ${address_or_name}`);
|
|
577
|
-
}
|
|
578
|
-
const pair = Ed25519Keypair.fromSecretKey(account.secret);
|
|
579
|
-
const dataBytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
580
|
-
const signature = await pair.sign(dataBytes);
|
|
581
|
-
return "0x" + Buffer.from(signature).toString("hex");
|
|
582
|
-
}
|
|
583
|
-
async signData(address_or_name, data) {
|
|
584
|
-
const account = await this.get_imp(address_or_name);
|
|
585
|
-
if (!account?.secret) {
|
|
586
|
-
W_ERROR(WErrors.InvalidParam, `Account not found or no secret key: ${address_or_name}`);
|
|
587
|
-
}
|
|
588
|
-
const pair = Ed25519Keypair.fromSecretKey(account.secret);
|
|
589
|
-
const dataBytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
590
|
-
const signature = await pair.sign(dataBytes);
|
|
591
|
-
return {
|
|
592
|
-
signature: "0x" + Buffer.from(signature).toString("hex"),
|
|
593
|
-
publicKey: pair.getPublicKey().toWPublicKey(),
|
|
594
|
-
address: account.address,
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
async deriveX25519KeyPair(address_or_name) {
|
|
598
|
-
const account = await this.get_imp(address_or_name);
|
|
599
|
-
if (!account?.secret) {
|
|
600
|
-
W_ERROR(WErrors.InvalidParam, `Account not found or no secret key: ${address_or_name}`);
|
|
601
|
-
}
|
|
602
|
-
const ed25519SecretKey = account.secret;
|
|
603
|
-
const { sha512 } = await import("@noble/hashes/sha512");
|
|
604
|
-
const hash = sha512(ed25519SecretKey);
|
|
605
|
-
const privateKey = new Uint8Array(hash.slice(0, 32));
|
|
606
|
-
privateKey[0] &= 248;
|
|
607
|
-
privateKey[31] &= 127;
|
|
608
|
-
privateKey[31] |= 64;
|
|
609
|
-
const { x25519 } = await import("@noble/curves/ed25519");
|
|
610
|
-
const publicKey = x25519.getPublicKey(privateKey);
|
|
611
|
-
return { privateKey, publicKey };
|
|
612
|
-
}
|
|
613
|
-
async set_messenger(address_or_name, m) {
|
|
614
|
-
const resolved_address_or_name = this.name_resolve(address_or_name);
|
|
615
|
-
const storage = await this.getStorage();
|
|
616
|
-
const value = await storage.get();
|
|
617
|
-
if (!value)
|
|
618
|
-
return false;
|
|
619
|
-
const data = JSON.parse(value);
|
|
620
|
-
const f = data.find((v) => v.address.toLowerCase() ===
|
|
621
|
-
resolved_address_or_name.toLowerCase() ||
|
|
622
|
-
v.name === resolved_address_or_name);
|
|
623
|
-
if (!f)
|
|
624
|
-
return false;
|
|
625
|
-
if (!m) {
|
|
626
|
-
const now = Date.now();
|
|
627
|
-
f.m = undefined;
|
|
628
|
-
f.updatedAt = now;
|
|
629
|
-
await storage.put(JSON.stringify(data));
|
|
630
|
-
return true;
|
|
631
|
-
}
|
|
632
|
-
if (!isValidName(m)) {
|
|
633
|
-
W_ERROR(WErrors.IsValidName, `Messenger name ${m} is exceeds max ${MAX_NAME_LENGTH}`);
|
|
634
|
-
}
|
|
635
|
-
const currentCount = data.filter((d) => d.m != null && !d.suspended && d.address !== f.address).length;
|
|
636
|
-
if (currentCount >= MAX_MESSENGER_ACCOUNTS) {
|
|
637
|
-
W_ERROR(WErrors.InvalidParam, `Maximum ${MAX_MESSENGER_ACCOUNTS} messenger accounts allowed, current count: ${currentCount}`);
|
|
638
|
-
}
|
|
639
|
-
const now = Date.now();
|
|
640
|
-
f.m = m;
|
|
641
|
-
f.updatedAt = now;
|
|
642
|
-
await storage.put(JSON.stringify(data));
|
|
643
|
-
return true;
|
|
644
|
-
}
|
|
645
|
-
async list_messenger_accounts() {
|
|
646
|
-
return this.list({ hasMessenger: true });
|
|
647
|
-
}
|
|
648
|
-
async count_messenger_accounts() {
|
|
649
|
-
const storage = await this.getStorage();
|
|
650
|
-
const value = await storage.get();
|
|
651
|
-
if (!value)
|
|
652
|
-
return 0;
|
|
653
|
-
const data = JSON.parse(value);
|
|
654
|
-
return data.filter((d) => d.m != null && !d.suspended).length;
|
|
655
|
-
}
|
|
656
|
-
}
|
|
1
|
+
import{Ed25519Keypair}from'../../keypairs/ed25519/index.js';import{W_ERROR,WErrors}from'../exception.js';import{GasTokenType,isGasTokenType,isValidName,MAX_NAME_LENGTH}from'../common.js';import{getFaucetHost,requestSuiFromFaucetV2}from'../../faucet/index.js';import{Transaction}from'../../transactions/index.js';import{getFullnodeUrl}from'../../client/network.js';import{SuiClient}from'../../client/index.js';import{Config}from'./config.js';import{SQLiteAccountStorage}from'./storage.js';import{isValidWowAddress}from'../../utils/sui-types.js';export const DEFAULT_ACCOUNT_NAME='';export const MAX_MESSENGER_ACCOUNTS=0x82;export class Account{static ['_instance'];static ['storage'];['setStorage'](a){Account['storage']=a;}async['getStorage'](){return!Account['storage']&&(Account['storage']=new SQLiteAccountStorage()),Account['storage'];}static['Instance'](){return!Account['_instance']&&(Account['_instance']=new Account()),Account['_instance'];}['accountData'](a){if(!a||!a['secret'])return undefined;const b=Ed25519Keypair['fromSecretKey'](a['secret']);return a['pubkey']=b['getPublicKey']()['toWPublicKey'](),a['secret']=undefined,a;}async['gen'](a,b,c){a=this['name_resolve'](a);a&&!isValidName(a)&&W_ERROR(WErrors['IsValidName'],'Name\x20'+a+'\x20is\x20exceeds\x20max\x20'+MAX_NAME_LENGTH);c&&!isValidName(c)&&W_ERROR(WErrors['IsValidName'],'Messenger\x20name\x20'+c+'\x20is\x20exceeds\x20max\x20'+MAX_NAME_LENGTH);const d=Ed25519Keypair['generate']()['getSecretKey'](),e=Ed25519Keypair['fromSecretKey'](d)['getPublicKey']()['toWAddress'](),f=Date['now'](),g={'name':a,'address':e,'secret':d,'m':undefined,'createdAt':f,'updatedAt':f},h=await this['getStorage'](),i=await h['get']();if(i){const j=JSON['parse'](i),k=j['findIndex'](l=>l['name']===a);k!==-0x1?b?(j[k]['name']=undefined,j['push'](g),await h['put'](JSON['stringify'](j))):W_ERROR(WErrors['AccountNameExist'],'Name\x20'+(a||'')+'\x20already\x20exist'):await h['put'](JSON['stringify']([...j,g]));}else await h['put'](JSON['stringify']([g]));if(c){const l=await this['getStorage'](),n=await l['get']();if(n){const q=JSON['parse'](n),r=q['filter'](s=>s['m']!=null)['length'];r>=MAX_MESSENGER_ACCOUNTS&&W_ERROR(WErrors['InvalidParam'],'Maximum\x20'+MAX_MESSENGER_ACCOUNTS+'\x20messenger\x20accounts\x20allowed,\x20current\x20count:\x20'+r);}g['m']=c;const o=await this['getStorage'](),p=await o['get']();if(p){const s=JSON['parse'](p),t=s['find'](u=>u['address']===e);t&&(t['m']=c,t['updatedAt']=Date['now'](),await o['put'](JSON['stringify'](s)));}}return this['accountData'](g);}async['default'](){return this['accountData'](await this['get_imp'](DEFAULT_ACCOUNT_NAME));}async['get'](a,b){if(!b)return this['accountData'](await this['get_imp'](a));return this['gen'](a);}async['get_address'](a){if(a&&isValidWowAddress(a))return a['toLowerCase']();return(await this['get_imp'](a))?.['address'];}async['get_many_address'](a){const b=await this['getStorage'](),c=await b['get']();if(c){const d=JSON['parse'](c);return a['map'](e=>{if(e&&isValidWowAddress(e))return e['toLowerCase']();const f=this['name_resolve'](e);return d['find'](g=>g['address']['toLowerCase']()===f['toLowerCase']()||g['name']===f)?.['address'];});}return a['map'](e=>e&&isValidWowAddress(e)?e['toLowerCase']():undefined);}async['get_imp'](a){a=this['name_resolve'](a);const b=await this['getStorage'](),c=await b['get']();if(c)return JSON['parse'](c)['find'](e=>e['name']===a||e['address']['toLowerCase']()===a['toLowerCase']());return undefined;}['name_resolve'](a){return a||DEFAULT_ACCOUNT_NAME;}async['get_many_imp'](a){const b=await this['getStorage'](),c=await b['get']();if(c){const d=JSON['parse'](c);return a['map'](e=>{const f=this['name_resolve'](e);return d['find'](g=>g['address']['toLowerCase']()===f['toLowerCase']()||g['name']===f);});}return a['map'](e=>undefined);}async['swap_name'](a,b){a=this['name_resolve'](a),b=this['name_resolve'](b);if(a===b)return!![];a&&!isValidName(a)&&W_ERROR(WErrors['IsValidName'],'Name\x20'+(a||'')+'\x20is\x20exceeds\x20max\x20'+MAX_NAME_LENGTH);b&&!isValidName(b)&&W_ERROR(WErrors['IsValidName'],'Name\x20'+(b||'')+'\x20is\x20exceeds\x20max\x20'+MAX_NAME_LENGTH);const c=await this['getStorage'](),d=await c['get']();if(!d)return![];const e=JSON['parse'](d),f=e['find'](i=>i['name']===a),g=e['find'](i=>i['name']===b);if(!f||!g)return![];const h=Date['now']();return f['name']=b,f['updatedAt']=h,g['name']=a,g['updatedAt']=h,await c['put'](JSON['stringify'](e)),!![];}async['rename'](a,b){b&&!isValidName(b)&&W_ERROR(WErrors['IsValidName'],'Invalid\x20new\x20name:\x20\x22'+(b||'')+'\x22.\x20Must\x20be\x20a\x20valid\x20name\x20(not\x20an\x20address)');const c=this['name_resolve'](a);if(c===b)return!![];const d=await this['getStorage'](),e=await d['get']();if(e){const g=JSON['parse'](e);g['find'](j=>j['name']===b)&&W_ERROR(WErrors['IsValidName'],'New\x20name\x20\x22'+(b||'')+'\x22\x20already\x20exists');const h=g['find'](j=>j['name']===c||j['address']['toLowerCase']()===c['toLowerCase']());!h&&W_ERROR(WErrors['AccountNotFound'],'Source\x20account\x20\x22'+(a||'')+'\x22\x20not\x20found');const i=Date['now']();return h['name']=b,h['updatedAt']=i,await d['put'](JSON['stringify'](g)),!![];}return![];}async['list'](a){const b=await this['getStorage'](),c=await b['get']();if(c){let d=JSON['parse'](c);return a?.['suspended']!==undefined?d=d['filter'](e=>a['suspended']?e['suspended']===!![]:!e['suspended']):d=d['filter'](e=>!e['suspended']),a?.['hasMessenger']!==undefined&&(d=d['filter'](e=>a['hasMessenger']?e['m']!=null:e['m']==null)),a?.['m']!=null&&(d=d['filter'](e=>e['m']!=null)),a?.['createdAt']&&(a['createdAt']['gte']!==undefined&&(d=d['filter'](e=>e['createdAt']&&e['createdAt']>=a['createdAt']['gte'])),a['createdAt']['lte']!==undefined&&(d=d['filter'](e=>e['createdAt']&&e['createdAt']<=a['createdAt']['lte']))),a?.['updatedAt']&&(a['updatedAt']['gte']!==undefined&&(d=d['filter'](e=>e['updatedAt']&&e['updatedAt']>=a['updatedAt']['gte'])),a['updatedAt']['lte']!==undefined&&(d=d['filter'](e=>e['updatedAt']&&e['updatedAt']<=a['updatedAt']['lte']))),(a?.['name']!=null||a?.['address']||a?.['m']!=null)&&(d=d['map'](e=>{let f=0x0;if(a?.['name']!=null){const g=e['name']?.['toLowerCase']()||'',h=a['name']['toLowerCase']();if(g===h)f+=0x64;else{if(g['startsWith'](h))f+=0x32;else g['includes'](h)&&(f+=0x19);}}if(a?.['address']){const i=e['address']['toLowerCase'](),j=a['address']['toLowerCase']();if(i===j)f+=0x64;else{if(i['startsWith'](j))f+=0x32;else i['includes'](j)&&(f+=0x19);}}if(a?.['m']!=null&&e['m']!=null){const k=e['m']['toLowerCase'](),l=a['m']['toLowerCase']();if(k===l)f+=0x64;else{if(k['startsWith'](l))f+=0x32;else k['includes'](l)&&(f+=0x19);}}return(a?.['name']||a?.['address']||a?.['m']!=null)&&f===0x0&&(f=-0x1),{'account':e,'score':f};})['filter'](({score:e})=>e>=0x0)['sort']((e,f)=>f['score']-e['score'])['map'](({account:e})=>e)),d['map'](e=>this['accountData'](e))['filter'](e=>e!==undefined);}return[];}async['suspend'](a){a=this['name_resolve'](a);const b=await this['getStorage'](),c=await b['get']();if(c){const d=JSON['parse'](c),e=d['find'](g=>g['address']['toLowerCase']()===a['toLowerCase']()||g['name']===a);if(e){const g=Date['now']();return e['suspended']=!![],e['name']=undefined,e['m']=undefined,e['updatedAt']=g,await b['put'](JSON['stringify'](d)),!![];}}return![];}async['suspend_many'](a){const b=await this['getStorage'](),c=await b['get'](),d={'success':[],'failed':[]};if(c){const e=JSON['parse'](c),g=Date['now']();let h=![];for(const i of a){const j=this['name_resolve'](i),k=e['find'](l=>l['address']['toLowerCase']()===j['toLowerCase']()||l['name']===j);k?(k['suspended']=!![],k['name']=undefined,k['m']=undefined,k['updatedAt']=g,d['success']['push'](i),h=!![]):d['failed']['push'](i);}h&&await b['put'](JSON['stringify'](e));}else d['failed']=[...a];return d;}async['resume'](a,b){b=this['name_resolve'](b),a=a['toLowerCase']();const c=await this['getStorage'](),d=await c['get']();if(d){const e=JSON['parse'](d);e['find'](h=>h['name']===b)&&W_ERROR(WErrors['IsValidName'],'Name\x20\x22'+(b||'')+'\x22\x20already\x20exists');const g=e['find'](h=>h['address']['toLowerCase']()===a['toLowerCase']());if(g){const h=Date['now']();return g['suspended']=![],g['name']=b,g['updatedAt']=h,await c['put'](JSON['stringify'](e)),!![];}}return![];}async['faucet'](b,c){const d=await this['get_imp'](b);if(d)try{const e=await requestSuiFromFaucetV2({'host':getFaucetHost(c),'recipient':d['address']});return e['coins_sent']||[];}catch(f){}return[];}async['sign_and_commit'](b,c,d){const e=await this['get_imp'](c);if(e){const f=Ed25519Keypair['fromSecretKey'](e['secret']);if(f){const g=new SuiClient({'url':getFullnodeUrl(await Config['Instance']()['network_get'](d))});return g['signAndExecuteTransaction']({'transaction':b,'signer':f,'options':{'showObjectChanges':!![],'showEffects':!![]}});}}return undefined;}['balance']=async(b,c,d)=>{const e=await this['get'](c);b=b??GasTokenType;if(e){const f=new SuiClient({'url':getFullnodeUrl(await Config['Instance']()['network_get'](d))});return f['getBalance']({'owner':e['address'],'coinType':b});}return undefined;};['coin']=async(b,c,d,e,f)=>{const g=await this['get'](e);b=b??GasTokenType;if(g){const h=new SuiClient({'url':getFullnodeUrl(await Config['Instance']()['network_get'](f))});return h['getCoins']({'owner':g['address'],'coinType':b,'cursor':c,'limit':d});}return undefined;};['get_coin_object']=async(c,d,e,f,g)=>{const h=await this['get'](f);if(h){const j=BigInt(d),k=new SuiClient({'url':getFullnodeUrl(await Config['Instance']()['network_get'](g))});if(j>=BigInt(0x0)){if(!e||isGasTokenType(e))return c['splitCoins'](c['gas'],[j]);else{const l=await k['getCoins']({'owner':h['address'],'coinType':e}),m=[],n=new Set();let o=BigInt(0x0);for(let p=0x0;p<l['data']['length'];++p){const q=l['data'][p]['coinObjectId'];if(n['has'](q))continue;n['add'](q),o+=BigInt(l['data'][p]['balance']),m['push'](q);if(o>=j)break;}if(m['length']===0x0)return undefined;if(m['length']===0x1)return c['splitCoins'](m[0x0],[j]);else{const s=m['pop']();return c['mergeCoins'](s,m),c['splitCoins'](s,[j]);}}}}return undefined;};['get_many_coin_object']=async(a,b,c,d,e)=>{const f=[];for(const g of b){const h=await this['get_coin_object'](a,g,d,c,e);!h?W_ERROR(WErrors['InvalidParam'],'Invalid\x20coin\x20object:\x20'+g):f['push'](h);}return a['makeMoveVec']({'elements':f});};async['refund_coin'](a,b,c){const d=await this['get_address'](c);if(!d)W_ERROR(WErrors['InvalidParam'],'Invalid\x20to\x20address\x20or\x20name\x20'+c);a['transferObjects']([b],a['pure']['address'](d));}async['transfer'](a,b,c,d,e){const [f,g]=await this['get_many_imp']([d,c]);if(!f)W_ERROR(WErrors['InvalidParam'],'Invalid\x20from\x20address\x20or\x20name\x20'+d);const h=g?.['address']??c;if(!h)W_ERROR(WErrors['InvalidParam'],'Invalid\x20to\x20address\x20or\x20name\x20'+c);const i=Ed25519Keypair['fromSecretKey'](f['secret']);if(i){const j=new Transaction(),k=await this['get_coin_object'](j,a,b,d,e);if(k){j['transferObjects']([k],h);const l=new SuiClient({'url':getFullnodeUrl(await Config['Instance']()['network_get'](e))}),m=l['signAndExecuteTransaction']({'transaction':j,'signer':i,'options':{'showObjectChanges':!![]}});return m;}}return undefined;}['coinObject_with_balance']=async(b,c,d,e)=>{const f=await this['get_imp'](d);if(!f)return undefined;const g=Ed25519Keypair['fromSecretKey'](f['secret']);if(!g)return undefined;const h=new Transaction(),i=await this['get_coin_object'](h,b,c,d,e);if(i){h['transferObjects']([i],f['address']);const j=new SuiClient({'url':getFullnodeUrl(await Config['Instance']()['network_get'](e))}),k=await j['signAndExecuteTransaction']({'transaction':h,'signer':g,'options':{'showObjectChanges':!![]}}),l=c??GasTokenType;return k?.['objectChanges']?.['find'](m=>m?.['type']==='created'&&(m?.['objectType'])['includes'](l))?.['objectId'];}return undefined;};async['sign'](a,b){const c=await this['get_imp'](a);!c?.['secret']&&W_ERROR(WErrors['InvalidParam'],'Account\x20not\x20found\x20or\x20no\x20secret\x20key:\x20'+a);const d=Ed25519Keypair['fromSecretKey'](c['secret']),e=typeof b==='string'?new TextEncoder()['encode'](b):b,f=await d['sign'](e);return'0x'+Buffer['from'](f)['toString']('hex');}async['signData'](a,b){const c=await this['get_imp'](a);!c?.['secret']&&W_ERROR(WErrors['InvalidParam'],'Account\x20not\x20found\x20or\x20no\x20secret\x20key:\x20'+a);const d=Ed25519Keypair['fromSecretKey'](c['secret']),e=typeof b==='string'?new TextEncoder()['encode'](b):b,f=await d['sign'](e);return{'signature':'0x'+Buffer['from'](f)['toString']('hex'),'publicKey':d['getPublicKey']()['toWPublicKey'](),'address':c['address']};}async['deriveX25519KeyPair'](a){const b=await this['get_imp'](a);!b?.['secret']&&W_ERROR(WErrors['InvalidParam'],'Account\x20not\x20found\x20or\x20no\x20secret\x20key:\x20'+a);const c=b['secret'],{sha512:d}=await import('@noble/hashes/sha512'),e=d(c),f=new Uint8Array(e['slice'](0x0,0x20));f[0x0]&=0xf8,f[0x1f]&=0x7f,f[0x1f]|=0x40;const {x25519:g}=await import('@noble/curves/ed25519'),h=g['getPublicKey'](f);return{'privateKey':f,'publicKey':h};}async['set_messenger'](a,b){const c=this['name_resolve'](a),d=await this['getStorage'](),e=await d['get']();if(!e)return![];const g=JSON['parse'](e),h=g['find'](k=>k['address']['toLowerCase']()===c['toLowerCase']()||k['name']===c);if(!h)return![];if(!b){const k=Date['now']();return h['m']=undefined,h['updatedAt']=k,await d['put'](JSON['stringify'](g)),!![];}!isValidName(b)&&W_ERROR(WErrors['IsValidName'],'Messenger\x20name\x20'+b+'\x20is\x20exceeds\x20max\x20'+MAX_NAME_LENGTH);const i=g['filter'](l=>l['m']!=null&&!l['suspended']&&l['address']!==h['address'])['length'];i>=MAX_MESSENGER_ACCOUNTS&&W_ERROR(WErrors['InvalidParam'],'Maximum\x20'+MAX_MESSENGER_ACCOUNTS+'\x20messenger\x20accounts\x20allowed,\x20current\x20count:\x20'+i);const j=Date['now']();return h['m']=b,h['updatedAt']=j,await d['put'](JSON['stringify'](g)),!![];}async['list_messenger_accounts'](){return this['list']({'hasMessenger':!![]});}async['count_messenger_accounts'](){const a=await this['getStorage'](),b=await a['get']();if(!b)return 0x0;const c=JSON['parse'](b);return c['filter'](e=>e['m']!=null&&!e['suspended'])['length'];}}
|