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
package/dist/cjs/w/call/guard.js
CHANGED
|
@@ -1,1048 +1 @@
|
|
|
1
|
-
import { toTxObject, toTxString, isValidDescription, MAX_DESCRIPTION_LENGTH, isValidU8, isValidName, ValueType, parseValueType, OperatorType, ContextType, isWitnessType, PackageAddress, ObjectType, MAX_INPUT_SIZE, MAX_DEPENDED_COUNT, MAX_MULTI_OPERANDS, } from "../common.js";
|
|
2
|
-
import _ from "lodash";
|
|
3
|
-
import { W_ERROR, WErrors } from "../exception.js";
|
|
4
|
-
import { CallBase } from "./base.js";
|
|
5
|
-
import { LocalMark } from "../local/local.js";
|
|
6
|
-
import { WitnessSourceType, WitnessTargetType, query_objects, } from "../query/object.js";
|
|
7
|
-
import { bcs } from "../../bcs/index.js";
|
|
8
|
-
import { valueToBcsBytes } from "../util.js";
|
|
9
|
-
import { getGuardQueryInfo, GUARDQUERY } from "./guard-ins.js";
|
|
10
|
-
import { checkType, resolveCallEnv } from "./util.js";
|
|
11
|
-
import { isValidWowAddress } from "../../utils/sui-types.js";
|
|
12
|
-
import { get_guardSubmissions, verify_guard } from "./passport.js";
|
|
13
|
-
import { writeFileSync } from "fs";
|
|
14
|
-
import { resolve } from "path";
|
|
15
|
-
export function guardFn(name) {
|
|
16
|
-
return `${PackageAddress}::guard::${name}`;
|
|
17
|
-
}
|
|
18
|
-
export class CallGuard extends CallBase {
|
|
19
|
-
data;
|
|
20
|
-
constructor(data) {
|
|
21
|
-
super();
|
|
22
|
-
this.data = data;
|
|
23
|
-
}
|
|
24
|
-
async call(env) {
|
|
25
|
-
await this.prepare(env);
|
|
26
|
-
return await this.exec(env);
|
|
27
|
-
}
|
|
28
|
-
async operate(env, tx, _passport, _submission) {
|
|
29
|
-
if (!this.data.table || this.data.table.length === 0) {
|
|
30
|
-
W_ERROR(WErrors.InvalidParam, "table is empty");
|
|
31
|
-
}
|
|
32
|
-
if (!this.data.root) {
|
|
33
|
-
W_ERROR(WErrors.InvalidParam, "root is empty");
|
|
34
|
-
}
|
|
35
|
-
const guard = await newGuard(tx, this.data?.description || "", this.data?.table, this.data?.root);
|
|
36
|
-
if (this.data?.rely != null) {
|
|
37
|
-
const relyGuards = await LocalMark.Instance().get_many_address(this.data.rely.guards);
|
|
38
|
-
const undefinedIndex = relyGuards.findIndex((v) => v === undefined);
|
|
39
|
-
if (undefinedIndex !== -1) {
|
|
40
|
-
W_ERROR(WErrors.InvalidParam, `rely.guards invalid: guard at index ${undefinedIndex} not found`);
|
|
41
|
-
}
|
|
42
|
-
reliesAdd(tx, guard, relyGuards.filter((v) => v !== undefined));
|
|
43
|
-
}
|
|
44
|
-
await this.new_with_mark(env, tx, ObjectType.Guard, create(tx, guard), this.data?.namedNew);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export const newGuard = async (tx, description, table, root) => {
|
|
48
|
-
if (!isValidDescription(description)) {
|
|
49
|
-
W_ERROR(WErrors.IsValidDescription, `Description exceeds maximum length ${MAX_DESCRIPTION_LENGTH}`);
|
|
50
|
-
}
|
|
51
|
-
for (let i = 0; i < table.length; i++) {
|
|
52
|
-
const v = table[i];
|
|
53
|
-
if (!isValidU8(v.identifier))
|
|
54
|
-
W_ERROR(WErrors.InvalidParam, `table.identifier ${v.identifier} invalid`);
|
|
55
|
-
if (!v.b_submission && (v.value === undefined || v.value === null))
|
|
56
|
-
W_ERROR(WErrors.InvalidParam, `table.value ${v.value} with identifier ${v.identifier} invalid`);
|
|
57
|
-
if (!isValidName(v.name))
|
|
58
|
-
W_ERROR(WErrors.InvalidParam, "table.name");
|
|
59
|
-
}
|
|
60
|
-
const grouped = _.groupBy(table, "identifier");
|
|
61
|
-
const duplicates = Object.keys(grouped).filter((key) => grouped[key].length > 1);
|
|
62
|
-
if (duplicates.length > 0) {
|
|
63
|
-
W_ERROR(WErrors.InvalidParam, `table.identifier duplicates: ${duplicates.join(", ")}`);
|
|
64
|
-
}
|
|
65
|
-
var output = [];
|
|
66
|
-
await buildNode(root, ValueType.Bool, table, output);
|
|
67
|
-
const totalLength = output.reduce((acc, arr) => acc + arr.length, 0);
|
|
68
|
-
const input = new Uint8Array(totalLength);
|
|
69
|
-
let offset = 0;
|
|
70
|
-
for (const arr of output) {
|
|
71
|
-
input.set(arr, offset);
|
|
72
|
-
offset += arr.length;
|
|
73
|
-
}
|
|
74
|
-
if (input.length > MAX_INPUT_SIZE) {
|
|
75
|
-
W_ERROR(WErrors.NewGuardCheckFailed, `Input size exceeds maximum limit ${MAX_INPUT_SIZE}`);
|
|
76
|
-
}
|
|
77
|
-
if (input.length === 0) {
|
|
78
|
-
W_ERROR(WErrors.NewGuardCheckFailed, `Input cannot be empty`);
|
|
79
|
-
}
|
|
80
|
-
const tableItems = [];
|
|
81
|
-
for (let i = 0; i < table.length; i++) {
|
|
82
|
-
const item = table[i];
|
|
83
|
-
const valueType = parseValueType(item.value_type);
|
|
84
|
-
let bcsValue;
|
|
85
|
-
if (item.b_submission) {
|
|
86
|
-
bcsValue = new Uint8Array(1);
|
|
87
|
-
bcsValue[0] = valueType;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
if (item.value === undefined || item.value === null) {
|
|
91
|
-
W_ERROR(WErrors.NewGuardCheckFailed, `Table item value is required when b_submission is false`);
|
|
92
|
-
}
|
|
93
|
-
bcsValue = await valueToBcsBytes(valueType, item.value);
|
|
94
|
-
}
|
|
95
|
-
tableItems.push(tx.moveCall({
|
|
96
|
-
target: guardFn("table_item"),
|
|
97
|
-
arguments: [
|
|
98
|
-
tx.pure.u8(item.identifier),
|
|
99
|
-
tx.pure.bool(item.b_submission),
|
|
100
|
-
tx.pure.vector("u8", Array.from(bcsValue)),
|
|
101
|
-
toTxString(tx, item.name),
|
|
102
|
-
],
|
|
103
|
-
}));
|
|
104
|
-
}
|
|
105
|
-
return tx.moveCall({
|
|
106
|
-
target: guardFn("new"),
|
|
107
|
-
arguments: [
|
|
108
|
-
toTxString(tx, description),
|
|
109
|
-
tx.makeMoveVec({
|
|
110
|
-
elements: tableItems,
|
|
111
|
-
type: `${PackageAddress}::guard::TableItem`,
|
|
112
|
-
}),
|
|
113
|
-
tx.pure.vector("u8", Array.from(input)),
|
|
114
|
-
],
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
export function create(tx, guard) {
|
|
118
|
-
return tx.moveCall({
|
|
119
|
-
target: guardFn("create"),
|
|
120
|
-
arguments: [
|
|
121
|
-
toTxObject(tx, guard),
|
|
122
|
-
tx.object.mutRegistrar(),
|
|
123
|
-
tx.object.clock(),
|
|
124
|
-
],
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
export function reliesAdd(tx, guard, rely_guards) {
|
|
128
|
-
const guards = _.uniq(rely_guards);
|
|
129
|
-
if (guards.length > MAX_DEPENDED_COUNT) {
|
|
130
|
-
W_ERROR(WErrors.NewGuardCheckFailed, `Relies count exceeds maximum limit ${MAX_DEPENDED_COUNT}`);
|
|
131
|
-
}
|
|
132
|
-
guards.forEach((g) => {
|
|
133
|
-
if (g === guard) {
|
|
134
|
-
W_ERROR(WErrors.NewGuardCheckFailed, `Guard cannot rely on itself`);
|
|
135
|
-
}
|
|
136
|
-
tx.moveCall({
|
|
137
|
-
target: guardFn("relies_add"),
|
|
138
|
-
arguments: [
|
|
139
|
-
toTxObject(tx, guard),
|
|
140
|
-
toTxObject(tx, g),
|
|
141
|
-
tx.object.mutRegistrar(),
|
|
142
|
-
tx.object.clock(),
|
|
143
|
-
],
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
export function reliesRemove(tx, guard, rely_guards) {
|
|
148
|
-
const guards = _.uniq(rely_guards);
|
|
149
|
-
if (guards.length > MAX_DEPENDED_COUNT) {
|
|
150
|
-
W_ERROR(WErrors.NewGuardCheckFailed, `Relies count exceeds maximum limit ${MAX_DEPENDED_COUNT}`);
|
|
151
|
-
}
|
|
152
|
-
guards.forEach((g) => {
|
|
153
|
-
tx.moveCall({
|
|
154
|
-
target: guardFn("relies_remove"),
|
|
155
|
-
arguments: [
|
|
156
|
-
toTxObject(tx, guard),
|
|
157
|
-
toTxObject(tx, g),
|
|
158
|
-
tx.object.mutRegistrar(),
|
|
159
|
-
],
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
export function reliesClear(tx, guard) {
|
|
164
|
-
tx.moveCall({
|
|
165
|
-
target: guardFn("relies_clear"),
|
|
166
|
-
arguments: [toTxObject(tx, guard), tx.object.mutRegistrar()],
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
export function reliesLogic(tx, guard, logic_and) {
|
|
170
|
-
tx.moveCall({
|
|
171
|
-
target: guardFn("relies_logic_and"),
|
|
172
|
-
arguments: [toTxObject(tx, guard), tx.pure.bool(logic_and)],
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
const buildNode = async (guard_node, type_required, table, output) => {
|
|
176
|
-
const node = guard_node;
|
|
177
|
-
switch (node.type) {
|
|
178
|
-
case "identifier": {
|
|
179
|
-
const f = table.find((v) => v.identifier === node.identifier);
|
|
180
|
-
if (f) {
|
|
181
|
-
const fValueType = parseValueType(f.value_type);
|
|
182
|
-
checkType(fValueType, type_required, node);
|
|
183
|
-
output.push(bcs.U8.serialize(ContextType.TypeConstant).toBytes());
|
|
184
|
-
output.push(bcs.U8.serialize(node.identifier).toBytes());
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
W_ERROR(WErrors.InvalidParam, "node identifier - " + JSON.stringify(node));
|
|
188
|
-
}
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
case "query": {
|
|
192
|
-
const q = getGuardQueryInfo(node.query);
|
|
193
|
-
if (!q) {
|
|
194
|
-
W_ERROR(WErrors.InvalidParam, `query not found: ${node.query}`);
|
|
195
|
-
}
|
|
196
|
-
checkType(q.return, type_required, node);
|
|
197
|
-
if (q.parameters.length === node.parameters.length) {
|
|
198
|
-
for (let i = node.parameters.length - 1; i >= 0; --i) {
|
|
199
|
-
await buildNode(node.parameters[i], q.parameters[i], table, output);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
W_ERROR(WErrors.InvalidParam, "node query parameters length not match - " +
|
|
204
|
-
JSON.stringify(node));
|
|
205
|
-
}
|
|
206
|
-
const tableItem = table.find((v) => v.identifier === node.object.identifier);
|
|
207
|
-
if (!tableItem) {
|
|
208
|
-
W_ERROR(WErrors.InvalidParam, "node object from identifier - " + JSON.stringify(node));
|
|
209
|
-
}
|
|
210
|
-
const tableItemValueType = parseValueType(tableItem.value_type);
|
|
211
|
-
if (tableItemValueType !== ValueType.Address) {
|
|
212
|
-
W_ERROR(WErrors.InvalidParam, `object to query must be address in table ${tableItem}. ${node.object}`);
|
|
213
|
-
}
|
|
214
|
-
output.push(bcs.U8.serialize(OperatorType.TypeQuery).toBytes());
|
|
215
|
-
if (isWitnessType(node.object.convert_witness)) {
|
|
216
|
-
const target = WitnessTargetType(node.object.convert_witness);
|
|
217
|
-
if (target !== q.objectType) {
|
|
218
|
-
W_ERROR(WErrors.InvalidParam, `witness object type(${target}) not consistent with query object type(${q.objectType})`);
|
|
219
|
-
}
|
|
220
|
-
const source = WitnessSourceType(node.object.convert_witness);
|
|
221
|
-
if (tableItem.object_type) {
|
|
222
|
-
if (tableItem.object_type !== source) {
|
|
223
|
-
W_ERROR(WErrors.InvalidParam, `witness object type(${source}) not consistent with query object type(${tableItem.object_type})`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
tableItem.object_type = source;
|
|
228
|
-
}
|
|
229
|
-
output.push(bcs.U8.serialize(node.object.convert_witness).toBytes());
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
if (tableItem?.object_type) {
|
|
233
|
-
if (tableItem.object_type !== q.objectType) {
|
|
234
|
-
W_ERROR(WErrors.InvalidParam, `witness object type(${q.objectType}) not consistent with query object type(${tableItem.object_type})`);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
tableItem.object_type = q.objectType;
|
|
239
|
-
}
|
|
240
|
-
output.push(bcs.U8.serialize(ContextType.TypeConstant).toBytes());
|
|
241
|
-
}
|
|
242
|
-
output.push(bcs.U8.serialize(node.object.identifier).toBytes());
|
|
243
|
-
output.push(bcs.U16.serialize(q.id).toBytes());
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
case "logic_as_u256_greater_or_equal":
|
|
247
|
-
case "logic_as_u256_lesser_or_equal":
|
|
248
|
-
case "logic_as_u256_equal":
|
|
249
|
-
case "logic_as_u256_greater":
|
|
250
|
-
case "logic_as_u256_lesser":
|
|
251
|
-
case "logic_equal":
|
|
252
|
-
case "logic_and":
|
|
253
|
-
case "logic_or":
|
|
254
|
-
case "logic_string_contains":
|
|
255
|
-
case "logic_string_nocase_contains":
|
|
256
|
-
case "logic_string_nocase_equal":
|
|
257
|
-
case "calc_number_add":
|
|
258
|
-
case "calc_number_subtract":
|
|
259
|
-
case "calc_number_multiply":
|
|
260
|
-
case "calc_number_divide":
|
|
261
|
-
case "calc_number_mod":
|
|
262
|
-
case "calc_string_nocase_contains":
|
|
263
|
-
case "calc_string_nocase_equal":
|
|
264
|
-
case "calc_string_contains": {
|
|
265
|
-
const opCodeMap = {
|
|
266
|
-
logic_as_u256_greater_or_equal: OperatorType.TypeLogicAsU256GreaterEqual,
|
|
267
|
-
logic_as_u256_lesser_or_equal: OperatorType.TypeLogicAsU256LesserEqual,
|
|
268
|
-
logic_as_u256_equal: OperatorType.TypeLogicAsU256Equal,
|
|
269
|
-
logic_as_u256_greater: OperatorType.TypeLogicAsU256Greater,
|
|
270
|
-
logic_as_u256_lesser: OperatorType.TypeLogicAsU256Lesser,
|
|
271
|
-
logic_equal: OperatorType.TypeLogicEqual,
|
|
272
|
-
logic_and: OperatorType.TypeLogicAnd,
|
|
273
|
-
logic_or: OperatorType.TypeLogicOr,
|
|
274
|
-
logic_string_contains: OperatorType.TypeStringContains,
|
|
275
|
-
logic_string_nocase_contains: OperatorType.TypeStringNocaseContains,
|
|
276
|
-
logic_string_nocase_equal: OperatorType.TypeStringNocaseEqual,
|
|
277
|
-
calc_number_add: OperatorType.TypeNumberAdd,
|
|
278
|
-
calc_number_subtract: OperatorType.TypeNumberSubtract,
|
|
279
|
-
calc_number_multiply: OperatorType.TypeNumberMultiply,
|
|
280
|
-
calc_number_divide: OperatorType.TypeNumberDivide,
|
|
281
|
-
calc_number_mod: OperatorType.TypeNumberMod,
|
|
282
|
-
calc_string_nocase_contains: OperatorType.TypeStringNocaseContains,
|
|
283
|
-
calc_string_nocase_equal: OperatorType.TypeStringNocaseEqual,
|
|
284
|
-
calc_string_contains: OperatorType.TypeStringContains,
|
|
285
|
-
};
|
|
286
|
-
const requiredTypeMap = {
|
|
287
|
-
logic_as_u256_greater_or_equal: "number",
|
|
288
|
-
logic_as_u256_lesser_or_equal: "number",
|
|
289
|
-
logic_as_u256_equal: "number",
|
|
290
|
-
logic_as_u256_greater: "number",
|
|
291
|
-
logic_as_u256_lesser: "number",
|
|
292
|
-
logic_equal: "variable",
|
|
293
|
-
logic_and: ValueType.Bool,
|
|
294
|
-
logic_or: ValueType.Bool,
|
|
295
|
-
logic_string_contains: ValueType.String,
|
|
296
|
-
logic_string_nocase_contains: ValueType.String,
|
|
297
|
-
logic_string_nocase_equal: ValueType.String,
|
|
298
|
-
calc_number_add: "number",
|
|
299
|
-
calc_number_subtract: "number",
|
|
300
|
-
calc_number_multiply: "number",
|
|
301
|
-
calc_number_divide: "number",
|
|
302
|
-
calc_number_mod: "number",
|
|
303
|
-
calc_string_nocase_contains: ValueType.String,
|
|
304
|
-
calc_string_nocase_equal: ValueType.String,
|
|
305
|
-
calc_string_contains: ValueType.String,
|
|
306
|
-
};
|
|
307
|
-
const returnTypeMap = {
|
|
308
|
-
logic_as_u256_greater_or_equal: ValueType.Bool,
|
|
309
|
-
logic_as_u256_lesser_or_equal: ValueType.Bool,
|
|
310
|
-
logic_as_u256_equal: ValueType.Bool,
|
|
311
|
-
logic_as_u256_greater: ValueType.Bool,
|
|
312
|
-
logic_as_u256_lesser: ValueType.Bool,
|
|
313
|
-
logic_equal: ValueType.Bool,
|
|
314
|
-
logic_and: ValueType.Bool,
|
|
315
|
-
logic_or: ValueType.Bool,
|
|
316
|
-
logic_string_contains: ValueType.Bool,
|
|
317
|
-
logic_string_nocase_contains: ValueType.Bool,
|
|
318
|
-
logic_string_nocase_equal: ValueType.Bool,
|
|
319
|
-
calc_number_add: ValueType.U256,
|
|
320
|
-
calc_number_subtract: ValueType.U256,
|
|
321
|
-
calc_number_multiply: ValueType.U256,
|
|
322
|
-
calc_number_divide: ValueType.U256,
|
|
323
|
-
calc_number_mod: ValueType.U256,
|
|
324
|
-
calc_string_nocase_contains: ValueType.Bool,
|
|
325
|
-
calc_string_nocase_equal: ValueType.Bool,
|
|
326
|
-
calc_string_contains: ValueType.Bool,
|
|
327
|
-
};
|
|
328
|
-
checkType(returnTypeMap[node.type], type_required, node);
|
|
329
|
-
await multi_operand_op(opCodeMap[node.type], node.nodes, requiredTypeMap[node.type], table, output);
|
|
330
|
-
break;
|
|
331
|
-
}
|
|
332
|
-
case "vec_contains_bool":
|
|
333
|
-
case "vec_contains_address":
|
|
334
|
-
case "vec_contains_string":
|
|
335
|
-
case "vec_contains_string_nocase":
|
|
336
|
-
case "vec_contains_number": {
|
|
337
|
-
const opCodeMap = {
|
|
338
|
-
vec_contains_bool: OperatorType.TypedValueVecContains_Bool,
|
|
339
|
-
vec_contains_address: OperatorType.TypedValueVecContains_Address,
|
|
340
|
-
vec_contains_string: OperatorType.TypedValueVecContains_String,
|
|
341
|
-
vec_contains_string_nocase: OperatorType.TypedValueVecContains_StringNoCase,
|
|
342
|
-
vec_contains_number: OperatorType.TypedValueVecContains_Number,
|
|
343
|
-
};
|
|
344
|
-
const vecTypeMap = {
|
|
345
|
-
vec_contains_bool: ValueType.VecBool,
|
|
346
|
-
vec_contains_address: ValueType.VecAddress,
|
|
347
|
-
vec_contains_string: ValueType.VecString,
|
|
348
|
-
vec_contains_string_nocase: ValueType.VecString,
|
|
349
|
-
vec_contains_number: "vec_number",
|
|
350
|
-
};
|
|
351
|
-
const elemTypeMap = {
|
|
352
|
-
vec_contains_bool: ValueType.Bool,
|
|
353
|
-
vec_contains_address: ValueType.Address,
|
|
354
|
-
vec_contains_string: ValueType.String,
|
|
355
|
-
vec_contains_string_nocase: ValueType.String,
|
|
356
|
-
vec_contains_number: "number",
|
|
357
|
-
};
|
|
358
|
-
checkType(ValueType.Bool, type_required, node);
|
|
359
|
-
for (let i = node.nodes.length - 1; i >= 0; --i) {
|
|
360
|
-
const nodeType = i === 0 ? vecTypeMap[node.type] : elemTypeMap[node.type];
|
|
361
|
-
await buildNode(node.nodes[i], nodeType, table, output);
|
|
362
|
-
}
|
|
363
|
-
output.push(bcs.U8.serialize(opCodeMap[node.type]).toBytes());
|
|
364
|
-
output.push(bcs.U8.serialize(node.nodes.length).toBytes());
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
case "logic_not":
|
|
368
|
-
case "calc_string_length":
|
|
369
|
-
case "convert_number_address":
|
|
370
|
-
case "convert_address_number":
|
|
371
|
-
case "convert_number_string":
|
|
372
|
-
case "convert_string_number":
|
|
373
|
-
case "convert_safe_u8":
|
|
374
|
-
case "convert_safe_u16":
|
|
375
|
-
case "convert_safe_u32":
|
|
376
|
-
case "convert_safe_u64":
|
|
377
|
-
case "convert_safe_u128":
|
|
378
|
-
case "convert_safe_u256":
|
|
379
|
-
case "value_type":
|
|
380
|
-
case "vec_length": {
|
|
381
|
-
const opCodeMap = {
|
|
382
|
-
logic_not: OperatorType.TypeLogicNot,
|
|
383
|
-
calc_string_length: OperatorType.TypeStringLength,
|
|
384
|
-
convert_number_address: OperatorType.TypeNumberAddress,
|
|
385
|
-
convert_address_number: OperatorType.TypeAddressNumber,
|
|
386
|
-
convert_number_string: OperatorType.TypeNumberString,
|
|
387
|
-
convert_string_number: OperatorType.TypeStringNumber,
|
|
388
|
-
convert_safe_u8: OperatorType.TypeSafeU8,
|
|
389
|
-
convert_safe_u16: OperatorType.TypeSafeU16,
|
|
390
|
-
convert_safe_u32: OperatorType.TypeSafeU32,
|
|
391
|
-
convert_safe_u64: OperatorType.TypeSafeU64,
|
|
392
|
-
convert_safe_u128: OperatorType.TypeSafeU128,
|
|
393
|
-
convert_safe_u256: OperatorType.TypeSafeU256,
|
|
394
|
-
value_type: OperatorType.TypedValueType,
|
|
395
|
-
vec_length: OperatorType.TypedValueVecLength,
|
|
396
|
-
};
|
|
397
|
-
const requiredTypeMap = {
|
|
398
|
-
logic_not: ValueType.Bool,
|
|
399
|
-
calc_string_length: ValueType.String,
|
|
400
|
-
convert_number_address: "number",
|
|
401
|
-
convert_address_number: ValueType.Address,
|
|
402
|
-
convert_number_string: "number",
|
|
403
|
-
convert_string_number: ValueType.String,
|
|
404
|
-
convert_safe_u8: "number",
|
|
405
|
-
convert_safe_u16: "number",
|
|
406
|
-
convert_safe_u32: "number",
|
|
407
|
-
convert_safe_u64: "number",
|
|
408
|
-
convert_safe_u128: "number",
|
|
409
|
-
convert_safe_u256: "number",
|
|
410
|
-
value_type: "variable",
|
|
411
|
-
vec_length: "vec",
|
|
412
|
-
};
|
|
413
|
-
const returnTypeMap = {
|
|
414
|
-
logic_not: ValueType.Bool,
|
|
415
|
-
calc_string_length: ValueType.U64,
|
|
416
|
-
convert_number_address: ValueType.Address,
|
|
417
|
-
convert_address_number: ValueType.U256,
|
|
418
|
-
convert_number_string: ValueType.String,
|
|
419
|
-
convert_string_number: ValueType.U256,
|
|
420
|
-
convert_safe_u8: ValueType.U8,
|
|
421
|
-
convert_safe_u16: ValueType.U16,
|
|
422
|
-
convert_safe_u32: ValueType.U32,
|
|
423
|
-
convert_safe_u64: ValueType.U64,
|
|
424
|
-
convert_safe_u128: ValueType.U128,
|
|
425
|
-
convert_safe_u256: ValueType.U256,
|
|
426
|
-
value_type: ValueType.U8,
|
|
427
|
-
vec_length: ValueType.U64,
|
|
428
|
-
};
|
|
429
|
-
checkType(returnTypeMap[node.type], type_required, node);
|
|
430
|
-
await single_operand_op(opCodeMap[node.type], node.node, requiredTypeMap[node.type], table, output);
|
|
431
|
-
break;
|
|
432
|
-
}
|
|
433
|
-
case "calc_string_indexof":
|
|
434
|
-
case "calc_string_nocase_indexof": {
|
|
435
|
-
const opCodeMap = {
|
|
436
|
-
calc_string_indexof: OperatorType.TypeStringIndexof,
|
|
437
|
-
calc_string_nocase_indexof: OperatorType.TypeStringNocaseIndexof,
|
|
438
|
-
};
|
|
439
|
-
checkType(ValueType.U64, type_required, node);
|
|
440
|
-
await buildNode(node.nodeRight, ValueType.String, table, output);
|
|
441
|
-
await buildNode(node.nodeLeft, ValueType.String, table, output);
|
|
442
|
-
output.push(bcs.U8.serialize(opCodeMap[node.type]).toBytes());
|
|
443
|
-
output.push(bcs.U8.serialize(node.order === "forward" ? 0 : 1).toBytes());
|
|
444
|
-
break;
|
|
445
|
-
}
|
|
446
|
-
case "vec_indexof_bool":
|
|
447
|
-
case "vec_indexof_address":
|
|
448
|
-
case "vec_indexof_string":
|
|
449
|
-
case "vec_indexof_string_nocase":
|
|
450
|
-
case "vec_indexof_number": {
|
|
451
|
-
const opCodeMap = {
|
|
452
|
-
vec_indexof_bool: OperatorType.TypedValueVecIndexOf_Bool,
|
|
453
|
-
vec_indexof_address: OperatorType.TypedValueVecIndexOf_Address,
|
|
454
|
-
vec_indexof_string: OperatorType.TypedValueVecIndexOf_String,
|
|
455
|
-
vec_indexof_string_nocase: OperatorType.TypedValueVecIndexOf_StringNoCase,
|
|
456
|
-
vec_indexof_number: OperatorType.TypedValueVecIndexOf_Number,
|
|
457
|
-
};
|
|
458
|
-
const rightTypeMap = {
|
|
459
|
-
vec_indexof_bool: ValueType.Bool,
|
|
460
|
-
vec_indexof_address: ValueType.Address,
|
|
461
|
-
vec_indexof_string: ValueType.String,
|
|
462
|
-
vec_indexof_string_nocase: ValueType.String,
|
|
463
|
-
vec_indexof_number: "number",
|
|
464
|
-
};
|
|
465
|
-
const leftTypeMap = {
|
|
466
|
-
vec_indexof_bool: ValueType.VecBool,
|
|
467
|
-
vec_indexof_address: ValueType.VecAddress,
|
|
468
|
-
vec_indexof_string: ValueType.VecString,
|
|
469
|
-
vec_indexof_string_nocase: ValueType.VecString,
|
|
470
|
-
vec_indexof_number: "vec_number",
|
|
471
|
-
};
|
|
472
|
-
checkType(ValueType.U64, type_required, node);
|
|
473
|
-
await buildNode(node.nodeRight, rightTypeMap[node.type], table, output);
|
|
474
|
-
await buildNode(node.nodeLeft, leftTypeMap[node.type], table, output);
|
|
475
|
-
output.push(bcs.U8.serialize(opCodeMap[node.type]).toBytes());
|
|
476
|
-
output.push(bcs.U8.serialize(node.order === "forward" ? 0 : 1).toBytes());
|
|
477
|
-
break;
|
|
478
|
-
}
|
|
479
|
-
case "context": {
|
|
480
|
-
let contextValue;
|
|
481
|
-
switch (node.context) {
|
|
482
|
-
case "Signer":
|
|
483
|
-
contextValue = ContextType.TypeSigner;
|
|
484
|
-
break;
|
|
485
|
-
case "Clock":
|
|
486
|
-
contextValue = ContextType.TypeClock;
|
|
487
|
-
break;
|
|
488
|
-
case "Guard":
|
|
489
|
-
contextValue = ContextType.TypeGuard;
|
|
490
|
-
break;
|
|
491
|
-
default:
|
|
492
|
-
W_ERROR(WErrors.InvalidParam, "Invalid context type: " + node.context);
|
|
493
|
-
}
|
|
494
|
-
output.push(bcs.U8.serialize(contextValue).toBytes());
|
|
495
|
-
if (node.context === "Clock") {
|
|
496
|
-
checkType(ContextType.TypeClock, type_required, node);
|
|
497
|
-
}
|
|
498
|
-
else {
|
|
499
|
-
checkType(ValueType.Address, type_required, node);
|
|
500
|
-
}
|
|
501
|
-
break;
|
|
502
|
-
}
|
|
503
|
-
default:
|
|
504
|
-
W_ERROR(WErrors.InvalidParam, "node:" + JSON.stringify(node));
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
const multi_operand_op = async (op_code, parameters, required_type, table, output) => {
|
|
508
|
-
if (parameters.length < 2 || parameters.length > MAX_MULTI_OPERANDS) {
|
|
509
|
-
W_ERROR(WErrors.InvalidParam, `op ${op_code} parameters length must >= 2 and <=
|
|
510
|
-
${MAX_MULTI_OPERANDS}. parameters:
|
|
511
|
-
${JSON.stringify(parameters)}`);
|
|
512
|
-
}
|
|
513
|
-
for (let i = parameters.length - 1; i >= 0; --i) {
|
|
514
|
-
await buildNode(parameters[i], required_type, table, output);
|
|
515
|
-
}
|
|
516
|
-
output.push(bcs.U8.serialize(op_code).toBytes());
|
|
517
|
-
output.push(bcs.U8.serialize(parameters.length).toBytes());
|
|
518
|
-
};
|
|
519
|
-
const single_operand_op = async (op_code, parameter, required_type, table, output) => {
|
|
520
|
-
await buildNode(parameter, required_type, table, output);
|
|
521
|
-
output.push(bcs.U8.serialize(op_code).toBytes());
|
|
522
|
-
};
|
|
523
|
-
export const guard2file = async (guard, file_path, format = "json", network) => {
|
|
524
|
-
const queryResult = await query_objects({
|
|
525
|
-
objects: [guard],
|
|
526
|
-
network,
|
|
527
|
-
});
|
|
528
|
-
const objects = queryResult.objects;
|
|
529
|
-
if (!objects || objects.length === 0 || objects[0].type !== "Guard") {
|
|
530
|
-
W_ERROR(WErrors.InvalidParam, `guard2file: Guard object not found: ${guard}`);
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
const guardObj = objects[0];
|
|
534
|
-
if (!guardObj) {
|
|
535
|
-
W_ERROR(WErrors.InvalidParam, `guard2file: Failed to get Guard object data: ${guard}`);
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
let content;
|
|
539
|
-
if (format === "json") {
|
|
540
|
-
content = generateGuardJson(guardObj);
|
|
541
|
-
}
|
|
542
|
-
else {
|
|
543
|
-
content = generateGuardMarkdown(guardObj);
|
|
544
|
-
}
|
|
545
|
-
try {
|
|
546
|
-
const resolvedPath = resolve(file_path);
|
|
547
|
-
writeFileSync(resolvedPath, content, "utf-8");
|
|
548
|
-
}
|
|
549
|
-
catch (e) {
|
|
550
|
-
W_ERROR(WErrors.InvalidParam, `guard2file: Failed to write file '${file_path}': ${e.message}`);
|
|
551
|
-
}
|
|
552
|
-
};
|
|
553
|
-
const generateGuardJson = (guardObj) => {
|
|
554
|
-
const output = {};
|
|
555
|
-
if (guardObj.description) {
|
|
556
|
-
output.description = guardObj.description;
|
|
557
|
-
}
|
|
558
|
-
if (guardObj.table && guardObj.table.length > 0) {
|
|
559
|
-
output.table = guardObj.table.map((item) => ({
|
|
560
|
-
identifier: item.identifier,
|
|
561
|
-
b_submission: item.b_submission,
|
|
562
|
-
value_type: item.value_type,
|
|
563
|
-
value: item.value,
|
|
564
|
-
name: item.name,
|
|
565
|
-
}));
|
|
566
|
-
}
|
|
567
|
-
if (guardObj.root) {
|
|
568
|
-
output.root = guardObj.root;
|
|
569
|
-
}
|
|
570
|
-
if (guardObj.relies && guardObj.relies.length > 0) {
|
|
571
|
-
output.rely = {
|
|
572
|
-
guards: guardObj.relies,
|
|
573
|
-
logic_or: !guardObj.relies_logic_and,
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
return JSON.stringify(output, null, 2);
|
|
577
|
-
};
|
|
578
|
-
const generateGuardMarkdown = (guardObj) => {
|
|
579
|
-
const lines = [];
|
|
580
|
-
lines.push(`# Guard Definition`);
|
|
581
|
-
lines.push("");
|
|
582
|
-
lines.push(`**Object ID:** ${guardObj.object}`);
|
|
583
|
-
lines.push("");
|
|
584
|
-
lines.push("## Summary");
|
|
585
|
-
lines.push("");
|
|
586
|
-
const description = guardObj.description || "";
|
|
587
|
-
const tableCount = guardObj.table ? guardObj.table.length : 0;
|
|
588
|
-
let summary = `${description.length > 100 ? description.substring(0, 97) + "..." : description}`;
|
|
589
|
-
summary += ` [${tableCount} tables]`;
|
|
590
|
-
lines.push(summary);
|
|
591
|
-
lines.push("");
|
|
592
|
-
lines.push("## Description");
|
|
593
|
-
lines.push("");
|
|
594
|
-
lines.push(guardObj.description || "");
|
|
595
|
-
lines.push("");
|
|
596
|
-
lines.push("## Table (Data Definitions)");
|
|
597
|
-
lines.push("");
|
|
598
|
-
lines.push("| Identifier | b_submission | value_type | value | name |");
|
|
599
|
-
lines.push("|------------|--------------|------------|-------|------|");
|
|
600
|
-
if (guardObj.table && guardObj.table.length > 0) {
|
|
601
|
-
for (const item of guardObj.table) {
|
|
602
|
-
const itemValueType = parseValueType(item.value_type);
|
|
603
|
-
const valueTypeStr = valueTypeToString(itemValueType);
|
|
604
|
-
const valueStr = formatValueForMarkdown(item.value);
|
|
605
|
-
lines.push(`| ${item.identifier} | ${item.b_submission} | ${valueTypeStr} (${item.value_type}) | ${valueStr} | ${item.name} |`);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
else {
|
|
609
|
-
lines.push("| - | - | - | - | - |");
|
|
610
|
-
}
|
|
611
|
-
lines.push("");
|
|
612
|
-
lines.push("## Root (Computational Tree)");
|
|
613
|
-
lines.push("");
|
|
614
|
-
lines.push("The root node MUST return a Bool value (pass/fail).");
|
|
615
|
-
lines.push("");
|
|
616
|
-
if (guardObj.root) {
|
|
617
|
-
lines.push("```json");
|
|
618
|
-
lines.push(JSON.stringify(guardObj.root, null, 2));
|
|
619
|
-
lines.push("```");
|
|
620
|
-
lines.push("");
|
|
621
|
-
const nodeComments = generateNodeComments(guardObj.root);
|
|
622
|
-
if (nodeComments.length > 0) {
|
|
623
|
-
lines.push("### Node Comments");
|
|
624
|
-
lines.push("");
|
|
625
|
-
for (const comment of nodeComments) {
|
|
626
|
-
lines.push(`- **${comment.type}**: ${comment.description}`);
|
|
627
|
-
}
|
|
628
|
-
lines.push("");
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
else {
|
|
632
|
-
lines.push("*No root node data available*");
|
|
633
|
-
lines.push("");
|
|
634
|
-
}
|
|
635
|
-
if (guardObj.relies && guardObj.relies.length > 0) {
|
|
636
|
-
lines.push("## Rely (Dependencies)");
|
|
637
|
-
lines.push("");
|
|
638
|
-
lines.push(`**Logic:** ${guardObj.relies_logic_and ? "AND" : "OR"}`);
|
|
639
|
-
lines.push("");
|
|
640
|
-
lines.push("**Dependent Guards:**");
|
|
641
|
-
for (const rely of guardObj.relies) {
|
|
642
|
-
lines.push(`- ${rely}`);
|
|
643
|
-
}
|
|
644
|
-
lines.push("");
|
|
645
|
-
}
|
|
646
|
-
return lines.join("\n");
|
|
647
|
-
};
|
|
648
|
-
const formatValueForMarkdown = (value) => {
|
|
649
|
-
if (value === undefined || value === null) {
|
|
650
|
-
return "-";
|
|
651
|
-
}
|
|
652
|
-
if (typeof value === "boolean") {
|
|
653
|
-
return value ? "true" : "false";
|
|
654
|
-
}
|
|
655
|
-
if (typeof value === "string") {
|
|
656
|
-
if (value.length > 30) {
|
|
657
|
-
return value.substring(0, 27) + "...";
|
|
658
|
-
}
|
|
659
|
-
return value;
|
|
660
|
-
}
|
|
661
|
-
if (typeof value === "number") {
|
|
662
|
-
return value.toString();
|
|
663
|
-
}
|
|
664
|
-
if (Array.isArray(value)) {
|
|
665
|
-
if (value.length === 0)
|
|
666
|
-
return "[]";
|
|
667
|
-
if (value.length > 3) {
|
|
668
|
-
return `[${value.slice(0, 3).join(", ")}, ... (${value.length} items)]`;
|
|
669
|
-
}
|
|
670
|
-
return `[${value.join(", ")}]`;
|
|
671
|
-
}
|
|
672
|
-
if (typeof value === "object") {
|
|
673
|
-
return "{...}";
|
|
674
|
-
}
|
|
675
|
-
return String(value);
|
|
676
|
-
};
|
|
677
|
-
export const generateNodeComments = (node, comments = []) => {
|
|
678
|
-
if (!node)
|
|
679
|
-
return comments;
|
|
680
|
-
if (node.type === "query") {
|
|
681
|
-
const queryId = typeof node.query === "number" ? node.query : undefined;
|
|
682
|
-
if (queryId !== undefined) {
|
|
683
|
-
const queryInfo = GUARDQUERY.find((q) => q.id === queryId);
|
|
684
|
-
if (queryInfo) {
|
|
685
|
-
comments.push({
|
|
686
|
-
type: `query(${node.query})`,
|
|
687
|
-
description: `${queryInfo.name}: ${queryInfo.description}`,
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
else if (node.type.startsWith("logic_")) {
|
|
693
|
-
comments.push({
|
|
694
|
-
type: node.type,
|
|
695
|
-
description: `Logic operation: ${node.type.replace(/_/g, " ")}`,
|
|
696
|
-
});
|
|
697
|
-
}
|
|
698
|
-
else if (node.type.startsWith("calc_")) {
|
|
699
|
-
comments.push({
|
|
700
|
-
type: node.type,
|
|
701
|
-
description: `Calculation: ${node.type.replace(/_/g, " ")}`,
|
|
702
|
-
});
|
|
703
|
-
}
|
|
704
|
-
else if (node.type.startsWith("convert_")) {
|
|
705
|
-
comments.push({
|
|
706
|
-
type: node.type,
|
|
707
|
-
description: `Type conversion: ${node.type.replace(/_/g, " ")}`,
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
if ("nodes" in node && Array.isArray(node.nodes)) {
|
|
711
|
-
for (const childNode of node.nodes) {
|
|
712
|
-
generateNodeComments(childNode, comments);
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
if ("node" in node && node.node) {
|
|
716
|
-
generateNodeComments(node.node, comments);
|
|
717
|
-
}
|
|
718
|
-
if ("parameters" in node && Array.isArray(node.parameters)) {
|
|
719
|
-
for (const param of node.parameters) {
|
|
720
|
-
generateNodeComments(param, comments);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
if ("nodeLeft" in node && node.nodeLeft) {
|
|
724
|
-
generateNodeComments(node.nodeLeft, comments);
|
|
725
|
-
}
|
|
726
|
-
if ("nodeRight" in node && node.nodeRight) {
|
|
727
|
-
generateNodeComments(node.nodeRight, comments);
|
|
728
|
-
}
|
|
729
|
-
return comments;
|
|
730
|
-
};
|
|
731
|
-
const valueTypeToString = (valueType) => {
|
|
732
|
-
const typeMap = {
|
|
733
|
-
[ValueType.Bool]: "Bool",
|
|
734
|
-
[ValueType.Address]: "Address",
|
|
735
|
-
[ValueType.String]: "String",
|
|
736
|
-
[ValueType.U8]: "U8",
|
|
737
|
-
[ValueType.U16]: "U16",
|
|
738
|
-
[ValueType.U32]: "U32",
|
|
739
|
-
[ValueType.U64]: "U64",
|
|
740
|
-
[ValueType.U128]: "U128",
|
|
741
|
-
[ValueType.U256]: "U256",
|
|
742
|
-
[ValueType.VecBool]: "VecBool",
|
|
743
|
-
[ValueType.VecAddress]: "VecAddress",
|
|
744
|
-
[ValueType.VecString]: "VecString",
|
|
745
|
-
[ValueType.VecU8]: "VecU8",
|
|
746
|
-
[ValueType.VecU16]: "VecU16",
|
|
747
|
-
[ValueType.VecU32]: "VecU32",
|
|
748
|
-
[ValueType.VecU64]: "VecU64",
|
|
749
|
-
[ValueType.VecU128]: "VecU128",
|
|
750
|
-
[ValueType.VecU256]: "VecU256",
|
|
751
|
-
[ValueType.VecVecU8]: "VecVecU8",
|
|
752
|
-
[ValueType.Value]: "Value",
|
|
753
|
-
};
|
|
754
|
-
return typeMap[valueType] || `Unknown(${valueType})`;
|
|
755
|
-
};
|
|
756
|
-
export const gen_passport = async (env, guard, info) => {
|
|
757
|
-
if (!isValidWowAddress(guard)) {
|
|
758
|
-
W_ERROR(WErrors.InvalidParam, "guard invalid: guard empty");
|
|
759
|
-
}
|
|
760
|
-
await resolveCallEnv(env);
|
|
761
|
-
const s = await get_guardSubmissions(env, [guard]);
|
|
762
|
-
if (s.submission.length > 0) {
|
|
763
|
-
if (!info) {
|
|
764
|
-
return {
|
|
765
|
-
type: "submission",
|
|
766
|
-
guard: s.guard,
|
|
767
|
-
submission: s.submission,
|
|
768
|
-
};
|
|
769
|
-
}
|
|
770
|
-
else {
|
|
771
|
-
return await verify_guard(env, info);
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
else {
|
|
775
|
-
return await verify_guard(env, {
|
|
776
|
-
type: "submission",
|
|
777
|
-
guard: [{ object: guard, impack: true }],
|
|
778
|
-
submission: [],
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
};
|
|
782
|
-
function detectFileFormatFromContent(text) {
|
|
783
|
-
const trimmed = text.trim();
|
|
784
|
-
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
785
|
-
return "json";
|
|
786
|
-
}
|
|
787
|
-
return "markdown";
|
|
788
|
-
}
|
|
789
|
-
function extractJsonFromMarkdown(markdown) {
|
|
790
|
-
const codeBlockRegex = /```(?:json)?\s*\n([\s\S]*?)```/g;
|
|
791
|
-
let match;
|
|
792
|
-
let lastMatch = null;
|
|
793
|
-
while ((match = codeBlockRegex.exec(markdown)) !== null) {
|
|
794
|
-
const jsonContent = match[1].trim();
|
|
795
|
-
if (jsonContent.startsWith("{") || jsonContent.startsWith("[")) {
|
|
796
|
-
const beforeMatch = markdown.substring(0, match.index);
|
|
797
|
-
const lineOffset = (beforeMatch.match(/\n/g) || []).length + 1;
|
|
798
|
-
lastMatch = { json: jsonContent, lineOffset };
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
return lastMatch;
|
|
802
|
-
}
|
|
803
|
-
function parseTableFromMarkdown(section) {
|
|
804
|
-
const jsonMatch = section.match(/```(?:json)?\s*\n([\s\S]*?)```/);
|
|
805
|
-
if (jsonMatch) {
|
|
806
|
-
try {
|
|
807
|
-
const parsed = JSON.parse(jsonMatch[1]);
|
|
808
|
-
if (Array.isArray(parsed)) {
|
|
809
|
-
return parsed;
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
catch {
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
const tableRows = section.match(/\|[^\n]+\|/g);
|
|
816
|
-
if (tableRows && tableRows.length > 2) {
|
|
817
|
-
return tableRows.slice(2).map((row) => {
|
|
818
|
-
const cells = row
|
|
819
|
-
.split("|")
|
|
820
|
-
.filter((c) => c.trim())
|
|
821
|
-
.map((c) => c.trim());
|
|
822
|
-
const valueTypeCell = cells[2];
|
|
823
|
-
let value_type;
|
|
824
|
-
const numericMatch = valueTypeCell.match(/\d+/);
|
|
825
|
-
if (numericMatch) {
|
|
826
|
-
value_type = parseInt(numericMatch[0], 10);
|
|
827
|
-
}
|
|
828
|
-
else {
|
|
829
|
-
const typeNameMatch = valueTypeCell.match(/^([A-Za-z]+)/);
|
|
830
|
-
if (typeNameMatch) {
|
|
831
|
-
value_type = typeNameMatch[1];
|
|
832
|
-
}
|
|
833
|
-
else {
|
|
834
|
-
throw new Error(`Invalid value_type in table row: "${valueTypeCell}". Expected a number (0-19) or type name (e.g., "U64", "Address")`);
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
return {
|
|
838
|
-
identifier: parseInt(cells[0], 10),
|
|
839
|
-
b_submission: cells[1].toLowerCase() === "true",
|
|
840
|
-
value_type,
|
|
841
|
-
value: cells[3] === "-" ? undefined : cells[3],
|
|
842
|
-
name: cells[4] === "-" ? undefined : cells[4],
|
|
843
|
-
};
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
return undefined;
|
|
847
|
-
}
|
|
848
|
-
function parseRelyFromMarkdown(section) {
|
|
849
|
-
const logicMatch = section.match(/\*\*Logic:\*\*\s*(AND|OR)/i);
|
|
850
|
-
const guardListMatches = section.match(/^\s*[-*]\s*(\S+)$/gm);
|
|
851
|
-
if (logicMatch || guardListMatches) {
|
|
852
|
-
return {
|
|
853
|
-
logic_or: logicMatch ? logicMatch[1].toUpperCase() === "OR" : false,
|
|
854
|
-
guards: guardListMatches
|
|
855
|
-
? guardListMatches.map((g) => g.replace(/^\s*[-*]\s*/, "").trim())
|
|
856
|
-
: [],
|
|
857
|
-
};
|
|
858
|
-
}
|
|
859
|
-
return undefined;
|
|
860
|
-
}
|
|
861
|
-
export function parseGuardFromMarkdown(content) {
|
|
862
|
-
const errors = [];
|
|
863
|
-
const result = {};
|
|
864
|
-
const jsonMatch = extractJsonFromMarkdown(content);
|
|
865
|
-
if (jsonMatch) {
|
|
866
|
-
try {
|
|
867
|
-
const parsed = JSON.parse(jsonMatch.json);
|
|
868
|
-
Object.assign(result, parsed);
|
|
869
|
-
}
|
|
870
|
-
catch (e) {
|
|
871
|
-
errors.push({
|
|
872
|
-
message: `Failed to parse JSON from code block: ${e.message}`,
|
|
873
|
-
path: "/",
|
|
874
|
-
line: jsonMatch.lineOffset,
|
|
875
|
-
});
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
if (!result.description) {
|
|
879
|
-
const descMatch = content.match(/(?:^|\n)#+\s*(?:Description|Description|Description)[^\n]*\n+([^\n#]+)/i);
|
|
880
|
-
if (descMatch) {
|
|
881
|
-
result.description = descMatch[1].trim();
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
if (!result.table) {
|
|
885
|
-
const tableMatch = content.match(/(?:^|\n)#+\s*(?:Table|Data Table|数据表)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);
|
|
886
|
-
if (tableMatch) {
|
|
887
|
-
const table = parseTableFromMarkdown(tableMatch[1]);
|
|
888
|
-
if (table) {
|
|
889
|
-
result.table = table;
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
if (!result.root) {
|
|
894
|
-
const rootMatch = content.match(/(?:^|\n)#+\s*(?:Root|根节点)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);
|
|
895
|
-
if (rootMatch) {
|
|
896
|
-
const rootSection = rootMatch[1];
|
|
897
|
-
const rootJsonMatch = rootSection.match(/```(?:json)?\s*\n([\s\S]*?)```/);
|
|
898
|
-
if (rootJsonMatch) {
|
|
899
|
-
try {
|
|
900
|
-
result.root = JSON.parse(rootJsonMatch[1]);
|
|
901
|
-
}
|
|
902
|
-
catch (e) {
|
|
903
|
-
errors.push({
|
|
904
|
-
message: `Failed to parse root JSON: ${e.message}`,
|
|
905
|
-
path: "/root",
|
|
906
|
-
});
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
if (!result.rely) {
|
|
912
|
-
const relyMatch = content.match(/(?:^|\n)#+\s*(?:Rely|Dependencies|依赖)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);
|
|
913
|
-
if (relyMatch) {
|
|
914
|
-
const rely = parseRelyFromMarkdown(relyMatch[1]);
|
|
915
|
-
if (rely) {
|
|
916
|
-
result.rely = rely;
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
if (!result.root) {
|
|
921
|
-
errors.push({
|
|
922
|
-
message: "Guard root node not found in markdown file",
|
|
923
|
-
path: "/root",
|
|
924
|
-
});
|
|
925
|
-
return { success: false, errors };
|
|
926
|
-
}
|
|
927
|
-
return {
|
|
928
|
-
success: true,
|
|
929
|
-
data: result,
|
|
930
|
-
errors,
|
|
931
|
-
};
|
|
932
|
-
}
|
|
933
|
-
export function parseGuardFile(content, format) {
|
|
934
|
-
const detectedFormat = format ?? detectFileFormatFromContent(content);
|
|
935
|
-
if (detectedFormat === "json") {
|
|
936
|
-
try {
|
|
937
|
-
const parsed = JSON.parse(content);
|
|
938
|
-
if (!parsed.root) {
|
|
939
|
-
return {
|
|
940
|
-
success: false,
|
|
941
|
-
errors: [
|
|
942
|
-
{
|
|
943
|
-
message: "Missing required field: root",
|
|
944
|
-
path: "/root",
|
|
945
|
-
},
|
|
946
|
-
],
|
|
947
|
-
};
|
|
948
|
-
}
|
|
949
|
-
return { success: true, data: parsed, errors: [] };
|
|
950
|
-
}
|
|
951
|
-
catch (e) {
|
|
952
|
-
return {
|
|
953
|
-
success: false,
|
|
954
|
-
errors: [
|
|
955
|
-
{
|
|
956
|
-
message: `JSON parse error: ${e.message}`,
|
|
957
|
-
path: "/",
|
|
958
|
-
},
|
|
959
|
-
],
|
|
960
|
-
};
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
return parseGuardFromMarkdown(content);
|
|
964
|
-
}
|
|
965
|
-
export function validateGuardNode(node) {
|
|
966
|
-
const errors = [];
|
|
967
|
-
if (!node || typeof node !== "object") {
|
|
968
|
-
errors.push({ message: "GuardNode must be an object", path: "/" });
|
|
969
|
-
return { success: false, errors };
|
|
970
|
-
}
|
|
971
|
-
const n = node;
|
|
972
|
-
if (!n.type || typeof n.type !== "string") {
|
|
973
|
-
errors.push({
|
|
974
|
-
message: "GuardNode must have a 'type' property",
|
|
975
|
-
path: "/type",
|
|
976
|
-
});
|
|
977
|
-
return { success: false, errors };
|
|
978
|
-
}
|
|
979
|
-
const validTypes = [
|
|
980
|
-
"identifier",
|
|
981
|
-
"query",
|
|
982
|
-
"context",
|
|
983
|
-
"logic_not",
|
|
984
|
-
"logic_and",
|
|
985
|
-
"logic_or",
|
|
986
|
-
"logic_equal",
|
|
987
|
-
"logic_as_u256_greater_or_equal",
|
|
988
|
-
"logic_as_u256_lesser_or_equal",
|
|
989
|
-
"logic_as_u256_greater",
|
|
990
|
-
"logic_as_u256_lesser",
|
|
991
|
-
"logic_as_u256_equal",
|
|
992
|
-
"logic_string_contains",
|
|
993
|
-
"logic_string_nocase_contains",
|
|
994
|
-
"logic_string_nocase_equal",
|
|
995
|
-
"calc_number_add",
|
|
996
|
-
"calc_number_subtract",
|
|
997
|
-
"calc_number_multiply",
|
|
998
|
-
"calc_number_divide",
|
|
999
|
-
"calc_number_mod",
|
|
1000
|
-
"calc_string_length",
|
|
1001
|
-
"calc_string_nocase_contains",
|
|
1002
|
-
"calc_string_nocase_equal",
|
|
1003
|
-
"calc_string_contains",
|
|
1004
|
-
"calc_string_indexof",
|
|
1005
|
-
"calc_string_nocase_indexof",
|
|
1006
|
-
"convert_number_address",
|
|
1007
|
-
"convert_address_number",
|
|
1008
|
-
"convert_number_string",
|
|
1009
|
-
"convert_string_number",
|
|
1010
|
-
"convert_safe_u8",
|
|
1011
|
-
"convert_safe_u16",
|
|
1012
|
-
"convert_safe_u32",
|
|
1013
|
-
"convert_safe_u64",
|
|
1014
|
-
"convert_safe_u128",
|
|
1015
|
-
"convert_safe_u256",
|
|
1016
|
-
"value_type",
|
|
1017
|
-
"vec_length",
|
|
1018
|
-
"vec_contains_bool",
|
|
1019
|
-
"vec_contains_address",
|
|
1020
|
-
"vec_contains_string",
|
|
1021
|
-
"vec_contains_string_nocase",
|
|
1022
|
-
"vec_contains_number",
|
|
1023
|
-
"vec_indexof_bool",
|
|
1024
|
-
"vec_indexof_address",
|
|
1025
|
-
"vec_indexof_string",
|
|
1026
|
-
"vec_indexof_string_nocase",
|
|
1027
|
-
"vec_indexof_number",
|
|
1028
|
-
];
|
|
1029
|
-
if (!validTypes.includes(n.type)) {
|
|
1030
|
-
errors.push({
|
|
1031
|
-
message: `Invalid GuardNode type: ${n.type}`,
|
|
1032
|
-
path: "/type",
|
|
1033
|
-
});
|
|
1034
|
-
}
|
|
1035
|
-
return { success: errors.length === 0, errors };
|
|
1036
|
-
}
|
|
1037
|
-
export function formatGuardParseErrors(errors) {
|
|
1038
|
-
return errors
|
|
1039
|
-
.map((e) => {
|
|
1040
|
-
let msg = `Path: ${e.path}`;
|
|
1041
|
-
if (e.line !== undefined && e.column !== undefined) {
|
|
1042
|
-
msg += ` (line ${e.line}, column ${e.column})`;
|
|
1043
|
-
}
|
|
1044
|
-
msg += `\n Error: ${e.message}`;
|
|
1045
|
-
return msg;
|
|
1046
|
-
})
|
|
1047
|
-
.join("\n\n");
|
|
1048
|
-
}
|
|
1
|
+
import{toTxObject,toTxString,isValidDescription,MAX_DESCRIPTION_LENGTH,isValidU8,isValidU64,isValidName,ValueType,parseValueType,OperatorType,ContextType,isWitnessType,PackageAddress,ObjectType,MAX_INPUT_SIZE,MAX_DEPENDED_COUNT,MAX_MULTI_OPERANDS}from'../common.js';import a151a from'lodash';import{W_ERROR,WErrors}from'../exception.js';import{CallBase}from'./base.js';import{isValidAddress,LocalMark}from'../local/local.js';import{GetAccountOrMark_Address}from'../local/index.js';import{WitnessSourceType,WitnessTargetType,query_objects}from'../query/object.js';import{bcs}from'../../bcs/index.js';import{valueToBcsBytes}from'../util.js';import{getGuardQueryInfo,GUARDQUERY}from'./guard-ins.js';import{checkType,resolveCallEnv}from'./util.js';import{isValidWowAddress}from'../../utils/sui-types.js';import{get_guardSubmissions,verify_guard}from'./passport.js';import{writeFileSync}from'fs';import{resolve}from'path';export function guardFn(a){return PackageAddress+'::guard::'+a;}export class CallGuard extends CallBase{['data'];constructor(a){super(),this['data']=a;}async['call'](a){return await this['prepare'](a),await this['exec'](a);}async['operate'](a,b,c,d){(!this['data']['table']||this['data']['table']['length']===0x0)&&W_ERROR(WErrors['InvalidParam'],'table\x20is\x20empty');!this['data']['root']&&W_ERROR(WErrors['InvalidParam'],'root\x20is\x20empty');const e=await newGuard(b,this['data']?.['description']||'',this['data']?.['table'],this['data']?.['root']);if(this['data']?.['rely']!=null){const f=await LocalMark['Instance']()['get_many_address'](this['data']['rely']['guards']),g=f['findIndex'](h=>h===undefined);g!==-0x1&&W_ERROR(WErrors['InvalidParam'],'rely.guards\x20invalid:\x20guard\x20at\x20index\x20'+g+'\x20not\x20found'),reliesAdd(b,e,f['filter'](h=>h!==undefined));}await this['new_with_mark'](a,b,ObjectType['Guard'],create(b,e),this['data']?.['namedNew']);}}export const newGuard=async(a,b,c,d)=>{!isValidDescription(b)&&W_ERROR(WErrors['IsValidDescription'],'Description\x20exceeds\x20maximum\x20length\x20'+MAX_DESCRIPTION_LENGTH);for(let m=0x0;m<c['length'];m++){const n=c[m];if(!isValidU8(n['identifier']))W_ERROR(WErrors['InvalidParam'],'table.identifier\x20'+n['identifier']+'\x20invalid');if(!n['b_submission']&&(n['value']===undefined||n['value']===null))W_ERROR(WErrors['InvalidParam'],'table.value\x20'+n['value']+'\x20with\x20identifier\x20'+n['identifier']+'\x20invalid');if(!isValidName(n['name']))W_ERROR(WErrors['InvalidParam'],'table.name');}const e=a151a['groupBy'](c,'identifier'),f=Object['keys'](e)['filter'](o=>e[o]['length']>0x1);f['length']>0x0&&W_ERROR(WErrors['InvalidParam'],'table.identifier\x20duplicates:\x20'+f['join'](',\x20'));var g=[];await buildNode(d,ValueType['Bool'],c,g);const h=g['reduce']((o,p)=>o+p['length'],0x0),j=new Uint8Array(h);let k=0x0;for(const o of g){j['set'](o,k),k+=o['length'];}j['length']>MAX_INPUT_SIZE&&W_ERROR(WErrors['NewGuardCheckFailed'],'Input\x20size\x20exceeds\x20maximum\x20limit\x20'+MAX_INPUT_SIZE);j['length']===0x0&&W_ERROR(WErrors['NewGuardCheckFailed'],'Input\x20cannot\x20be\x20empty');const l=[];for(let p=0x0;p<c['length'];p++){const q=c[p],r=parseValueType(q['value_type']);let s;q['b_submission']?(s=new Uint8Array(0x1),s[0x0]=r):((q['value']===undefined||q['value']===null)&&W_ERROR(WErrors['NewGuardCheckFailed'],'Table\x20item\x20value\x20is\x20required\x20when\x20b_submission\x20is\x20false'),s=await valueToBcsBytes(r,q['value'])),l['push'](a['moveCall']({'target':guardFn('table_item'),'arguments':[a['pure']['u8'](q['identifier']),a['pure']['bool'](q['b_submission']),a['pure']['vector']('u8',Array['from'](s)),toTxString(a,q['name'])]}));}return a['moveCall']({'target':guardFn('new'),'arguments':[toTxString(a,b),a['makeMoveVec']({'elements':l,'type':PackageAddress+'::guard::TableItem'}),a['pure']['vector']('u8',Array['from'](j))]});};export function create(a,b){return a['moveCall']({'target':guardFn('create'),'arguments':[toTxObject(a,b),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function reliesAdd(a,b,c){const d=a151a['uniq'](c);d['length']>MAX_DEPENDED_COUNT&&W_ERROR(WErrors['NewGuardCheckFailed'],'Relies\x20count\x20exceeds\x20maximum\x20limit\x20'+MAX_DEPENDED_COUNT),d['forEach'](e=>{e===b&&W_ERROR(WErrors['NewGuardCheckFailed'],'Guard\x20cannot\x20rely\x20on\x20itself'),a['moveCall']({'target':guardFn('relies_add'),'arguments':[toTxObject(a,b),toTxObject(a,e),a['object']['mutRegistrar'](),a['object']['clock']()]});});}export function reliesRemove(a,b,c){const d=a151a['uniq'](c);d['length']>MAX_DEPENDED_COUNT&&W_ERROR(WErrors['NewGuardCheckFailed'],'Relies\x20count\x20exceeds\x20maximum\x20limit\x20'+MAX_DEPENDED_COUNT),d['forEach'](e=>{a['moveCall']({'target':guardFn('relies_remove'),'arguments':[toTxObject(a,b),toTxObject(a,e),a['object']['mutRegistrar']()]});});}export function reliesClear(a,b){a['moveCall']({'target':guardFn('relies_clear'),'arguments':[toTxObject(a,b),a['object']['mutRegistrar']()]});}export function reliesLogic(a,b,c){a['moveCall']({'target':guardFn('relies_logic_and'),'arguments':[toTxObject(a,b),a['pure']['bool'](c)]});}const buildNode=async(a,b,c,d)=>{const e=a;switch(e['type']){case'identifier':{const g=c['find'](h=>h['identifier']===e['identifier']);if(g){const h=parseValueType(g['value_type']);checkType(h,b,e),d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](e['identifier'])['toBytes']());}else W_ERROR(WErrors['InvalidParam'],'node\x20identifier\x20-\x20'+JSON['stringify'](e));break;}case'query':{const j=getGuardQueryInfo(e['query']);!j&&W_ERROR(WErrors['InvalidParam'],'query\x20not\x20found:\x20'+e['query']);checkType(j['return'],b,e);if(j['parameters']['length']===e['parameters']['length'])for(let m=e['parameters']['length']-0x1;m>=0x0;--m){await buildNode(e['parameters'][m],j['parameters'][m],c,d);}else W_ERROR(WErrors['InvalidParam'],'node\x20query\x20parameters\x20length\x20not\x20match\x20-\x20'+JSON['stringify'](e));const k=c['find'](n=>n['identifier']===e['object']['identifier']);!k&&W_ERROR(WErrors['InvalidParam'],'node\x20object\x20from\x20identifier\x20-\x20'+JSON['stringify'](e));const l=parseValueType(k['value_type']);l!==ValueType['Address']&&W_ERROR(WErrors['InvalidParam'],'object\x20to\x20query\x20must\x20be\x20address\x20in\x20table\x20'+k+'.\x20'+e['object']);d['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']());if(isWitnessType(e['object']['convert_witness'])){const n=WitnessTargetType(e['object']['convert_witness']);n!==j['objectType']&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+n+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+j['objectType']+')');const o=WitnessSourceType(e['object']['convert_witness']);k['object_type']?k['object_type']!==o&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+o+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+k['object_type']+')'):k['object_type']=o,d['push'](bcs['U8']['serialize'](e['object']['convert_witness'])['toBytes']());}else k?.['object_type']?k['object_type']!==j['objectType']&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+j['objectType']+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+k['object_type']+')'):k['object_type']=j['objectType'],d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']());d['push'](bcs['U8']['serialize'](e['object']['identifier'])['toBytes']()),d['push'](bcs['U16']['serialize'](j['id'])['toBytes']());break;}case'logic_as_u256_greater_or_equal':case'logic_as_u256_lesser_or_equal':case'logic_as_u256_equal':case'logic_as_u256_greater':case'logic_as_u256_lesser':case'logic_equal':case'logic_and':case'logic_or':case'logic_string_contains':case'logic_string_nocase_contains':case'logic_string_nocase_equal':case'calc_number_add':case'calc_number_subtract':case'calc_number_multiply':case'calc_number_divide':case'calc_number_mod':case'calc_string_nocase_contains':case'calc_string_nocase_equal':case'calc_string_contains':{const p={'logic_as_u256_greater_or_equal':OperatorType['TypeLogicAsU256GreaterEqual'],'logic_as_u256_lesser_or_equal':OperatorType['TypeLogicAsU256LesserEqual'],'logic_as_u256_equal':OperatorType['TypeLogicAsU256Equal'],'logic_as_u256_greater':OperatorType['TypeLogicAsU256Greater'],'logic_as_u256_lesser':OperatorType['TypeLogicAsU256Lesser'],'logic_equal':OperatorType['TypeLogicEqual'],'logic_and':OperatorType['TypeLogicAnd'],'logic_or':OperatorType['TypeLogicOr'],'logic_string_contains':OperatorType['TypeStringContains'],'logic_string_nocase_contains':OperatorType['TypeStringNocaseContains'],'logic_string_nocase_equal':OperatorType['TypeStringNocaseEqual'],'calc_number_add':OperatorType['TypeNumberAdd'],'calc_number_subtract':OperatorType['TypeNumberSubtract'],'calc_number_multiply':OperatorType['TypeNumberMultiply'],'calc_number_divide':OperatorType['TypeNumberDivide'],'calc_number_mod':OperatorType['TypeNumberMod'],'calc_string_nocase_contains':OperatorType['TypeStringNocaseContains'],'calc_string_nocase_equal':OperatorType['TypeStringNocaseEqual'],'calc_string_contains':OperatorType['TypeStringContains']},r={'logic_as_u256_greater_or_equal':'number','logic_as_u256_lesser_or_equal':'number','logic_as_u256_equal':'number','logic_as_u256_greater':'number','logic_as_u256_lesser':'number','logic_equal':'variable','logic_and':ValueType['Bool'],'logic_or':ValueType['Bool'],'logic_string_contains':ValueType['String'],'logic_string_nocase_contains':ValueType['String'],'logic_string_nocase_equal':ValueType['String'],'calc_number_add':'number','calc_number_subtract':'number','calc_number_multiply':'number','calc_number_divide':'number','calc_number_mod':'number','calc_string_nocase_contains':ValueType['String'],'calc_string_nocase_equal':ValueType['String'],'calc_string_contains':ValueType['String']},s={'logic_as_u256_greater_or_equal':ValueType['Bool'],'logic_as_u256_lesser_or_equal':ValueType['Bool'],'logic_as_u256_equal':ValueType['Bool'],'logic_as_u256_greater':ValueType['Bool'],'logic_as_u256_lesser':ValueType['Bool'],'logic_equal':ValueType['Bool'],'logic_and':ValueType['Bool'],'logic_or':ValueType['Bool'],'logic_string_contains':ValueType['Bool'],'logic_string_nocase_contains':ValueType['Bool'],'logic_string_nocase_equal':ValueType['Bool'],'calc_number_add':ValueType['U256'],'calc_number_subtract':ValueType['U256'],'calc_number_multiply':ValueType['U256'],'calc_number_divide':ValueType['U256'],'calc_number_mod':ValueType['U256'],'calc_string_nocase_contains':ValueType['Bool'],'calc_string_nocase_equal':ValueType['Bool'],'calc_string_contains':ValueType['Bool']};checkType(s[e['type']],b,e),await multi_operand_op(p[e['type']],e['nodes'],r[e['type']],c,d);break;}case'vec_contains_bool':case'vec_contains_address':case'vec_contains_string':case'vec_contains_string_nocase':case'vec_contains_number':{const t={'vec_contains_bool':OperatorType['TypedValueVecContains_Bool'],'vec_contains_address':OperatorType['TypedValueVecContains_Address'],'vec_contains_string':OperatorType['TypedValueVecContains_String'],'vec_contains_string_nocase':OperatorType['TypedValueVecContains_StringNoCase'],'vec_contains_number':OperatorType['TypedValueVecContains_Number']},u={'vec_contains_bool':ValueType['VecBool'],'vec_contains_address':ValueType['VecAddress'],'vec_contains_string':ValueType['VecString'],'vec_contains_string_nocase':ValueType['VecString'],'vec_contains_number':'vec_number'},v={'vec_contains_bool':ValueType['Bool'],'vec_contains_address':ValueType['Address'],'vec_contains_string':ValueType['String'],'vec_contains_string_nocase':ValueType['String'],'vec_contains_number':'number'};checkType(ValueType['Bool'],b,e);for(let w=e['nodes']['length']-0x1;w>=0x0;--w){const x=w===0x0?u[e['type']]:v[e['type']];await buildNode(e['nodes'][w],x,c,d);}d['push'](bcs['U8']['serialize'](t[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['nodes']['length'])['toBytes']());break;}case'logic_not':case'calc_string_length':case'convert_number_address':case'convert_address_number':case'convert_number_string':case'convert_string_number':case'convert_safe_u8':case'convert_safe_u16':case'convert_safe_u32':case'convert_safe_u64':case'convert_safe_u128':case'convert_safe_u256':case'value_type':case'vec_length':{const y={'logic_not':OperatorType['TypeLogicNot'],'calc_string_length':OperatorType['TypeStringLength'],'convert_number_address':OperatorType['TypeNumberAddress'],'convert_address_number':OperatorType['TypeAddressNumber'],'convert_number_string':OperatorType['TypeNumberString'],'convert_string_number':OperatorType['TypeStringNumber'],'convert_safe_u8':OperatorType['TypeSafeU8'],'convert_safe_u16':OperatorType['TypeSafeU16'],'convert_safe_u32':OperatorType['TypeSafeU32'],'convert_safe_u64':OperatorType['TypeSafeU64'],'convert_safe_u128':OperatorType['TypeSafeU128'],'convert_safe_u256':OperatorType['TypeSafeU256'],'value_type':OperatorType['TypedValueType'],'vec_length':OperatorType['TypedValueVecLength']},z={'logic_not':ValueType['Bool'],'calc_string_length':ValueType['String'],'convert_number_address':'number','convert_address_number':ValueType['Address'],'convert_number_string':'number','convert_string_number':ValueType['String'],'convert_safe_u8':'number','convert_safe_u16':'number','convert_safe_u32':'number','convert_safe_u64':'number','convert_safe_u128':'number','convert_safe_u256':'number','value_type':'variable','vec_length':'vec'},A={'logic_not':ValueType['Bool'],'calc_string_length':ValueType['U64'],'convert_number_address':ValueType['Address'],'convert_address_number':ValueType['U256'],'convert_number_string':ValueType['String'],'convert_string_number':ValueType['U256'],'convert_safe_u8':ValueType['U8'],'convert_safe_u16':ValueType['U16'],'convert_safe_u32':ValueType['U32'],'convert_safe_u64':ValueType['U64'],'convert_safe_u128':ValueType['U128'],'convert_safe_u256':ValueType['U256'],'value_type':ValueType['U8'],'vec_length':ValueType['U64']};checkType(A[e['type']],b,e),await single_operand_op(y[e['type']],e['node'],z[e['type']],c,d);break;}case'calc_string_indexof':case'calc_string_nocase_indexof':{const B={'calc_string_indexof':OperatorType['TypeStringIndexof'],'calc_string_nocase_indexof':OperatorType['TypeStringNocaseIndexof']};checkType(ValueType['U64'],b,e),await buildNode(e['nodeRight'],ValueType['String'],c,d),await buildNode(e['nodeLeft'],ValueType['String'],c,d),d['push'](bcs['U8']['serialize'](B[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['order']==='forward'?0x0:0x1)['toBytes']());break;}case'vec_indexof_bool':case'vec_indexof_address':case'vec_indexof_string':case'vec_indexof_string_nocase':case'vec_indexof_number':{const C={'vec_indexof_bool':OperatorType['TypedValueVecIndexOf_Bool'],'vec_indexof_address':OperatorType['TypedValueVecIndexOf_Address'],'vec_indexof_string':OperatorType['TypedValueVecIndexOf_String'],'vec_indexof_string_nocase':OperatorType['TypedValueVecIndexOf_StringNoCase'],'vec_indexof_number':OperatorType['TypedValueVecIndexOf_Number']},D={'vec_indexof_bool':ValueType['Bool'],'vec_indexof_address':ValueType['Address'],'vec_indexof_string':ValueType['String'],'vec_indexof_string_nocase':ValueType['String'],'vec_indexof_number':'number'},E={'vec_indexof_bool':ValueType['VecBool'],'vec_indexof_address':ValueType['VecAddress'],'vec_indexof_string':ValueType['VecString'],'vec_indexof_string_nocase':ValueType['VecString'],'vec_indexof_number':'vec_number'};checkType(ValueType['U64'],b,e),await buildNode(e['nodeRight'],D[e['type']],c,d),await buildNode(e['nodeLeft'],E[e['type']],c,d),d['push'](bcs['U8']['serialize'](C[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['order']==='forward'?0x0:0x1)['toBytes']());break;}case'query_reward_record_find':case'query_reward_record_count':case'query_reward_record_exists':{!isValidU8(e['object']['identifier'])&&W_ERROR(WErrors['IsValidU8'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20is\x20not\x20a\x20valid\x20U8\x20(0-255)');const F=c['find'](H=>H['identifier']===e['object']['identifier']);!F&&W_ERROR(WErrors['IsValidIdentifier'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20not\x20found\x20in\x20table');const G=await buildRewardRecordQuery(e,c,b);d['push'](...G['output']);break;}case'query_progress_history_find':case'query_progress_history_session_find':case'query_progress_history_session_forward_find':case'query_progress_history_session_count':case'query_progress_history_session_forward_count':case'query_progress_history_session_forward_retained_submission_count':{!isValidU8(e['object']['identifier'])&&W_ERROR(WErrors['IsValidU8'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20is\x20not\x20a\x20valid\x20U8\x20(0-255)');const H=c['find'](J=>J['identifier']===e['object']['identifier']);!H&&W_ERROR(WErrors['IsValidIdentifier'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20not\x20found\x20in\x20table');const I=await buildProgressQuery(e,c,b);d['push'](...I['output']);break;}case'context':{let J;switch(e['context']){case'Signer':J=ContextType['TypeSigner'];break;case'Clock':J=ContextType['TypeClock'];break;case'Guard':J=ContextType['TypeGuard'];break;default:W_ERROR(WErrors['InvalidParam'],'Invalid\x20context\x20type:\x20'+e['context']);}d['push'](bcs['U8']['serialize'](J)['toBytes']());e['context']==='Clock'?checkType(ContextType['TypeClock'],b,e):checkType(ValueType['Address'],b,e);break;}default:W_ERROR(WErrors['InvalidParam'],'node:'+JSON['stringify'](e));}},multi_operand_op=async(a,b,c,d,e)=>{(b['length']<0x2||b['length']>MAX_MULTI_OPERANDS)&&W_ERROR(WErrors['InvalidParam'],'op\x20'+a+'\x20parameters\x20length\x20must\x20>=\x202\x20and\x20<=\x20\x20\x0a\x09\x09\x09\x09'+MAX_MULTI_OPERANDS+'.\x20\x09parameters:\x0a\x09\x09\x09\x09'+JSON['stringify'](b));for(let f=b['length']-0x1;f>=0x0;--f){await buildNode(b[f],c,d,e);}e['push'](bcs['U8']['serialize'](a)['toBytes']()),e['push'](bcs['U8']['serialize'](b['length'])['toBytes']());},getNewIdentifier=(a,b)=>{let c=0x0;while(c<0x100&&a['find'](d=>d['identifier']===c)){c++;}return c>=0x100&&W_ERROR(WErrors['InvalidParam'],b+'\x20cannot\x20find\x20available\x20identifier\x20in\x20table\x20(all\x20256\x20identifiers\x20are\x20used)'),c;},StoreFromIdFilter=bcs['struct']('StoreFromIdFilter',{'mode':bcs['U8'],'value':bcs['option'](bcs['Address'])}),RecordQueryConditionsBCS=bcs['struct']('RecordQueryConditions',{'recipient':bcs['Address'],'guard':bcs['option'](bcs['Address']),'time_min':bcs['option'](bcs['U64']),'time_max':bcs['option'](bcs['U64']),'amount_min':bcs['option'](bcs['U64']),'amount_max':bcs['option'](bcs['U64']),'store_from_id':bcs['option'](StoreFromIdFilter)}),buildRecordQueryConditionsFromConst=a=>{const b={'recipient':a['recipient'],'guard':a['guard']??null,'time_min':a['timeMin']??null,'time_max':a['timeMax']??null,'amount_min':a['amountMin']??null,'amount_max':a['amountMax']??null,'store_from_id':a['storeFromId']?{'mode':a['storeFromId']==='not_exists'?0x0:a['storeFromId']==='exists'?0x1:0x2,'value':typeof a['storeFromId']==='object'?a['storeFromId']['eq']:null}:null};return RecordQueryConditionsBCS['serialize'](b)['toBytes']();},buildRewardRecordQuery=async(a,b,c)=>{const d=a['recipient'];d['type']!=='identifier'&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20must\x20be\x20an\x20identifier');const e=d,f=b[e['identifier']];!f&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20identifier\x20'+e['identifier']+'\x20not\x20found\x20in\x20table');f['value_type']!==ValueType['Address']&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20must\x20be\x20Address\x20type,\x20got\x20'+f['value_type']);a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['amountMin']!==undefined&&!isValidU64(a['where']['amountMin'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20amountMin\x20\x22'+a['where']['amountMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['amountMax']!==undefined&&!isValidU64(a['where']['amountMax'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20amountMax\x20\x22'+a['where']['amountMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');const g={'recipient':f['value']};if(a['where']['guard']){const o=await LocalMark['Instance']()['get_address'](a['where']['guard']);!o&&W_ERROR(WErrors['AddressNotFound'],'Reward\x20record\x20query\x20guard\x20\x22'+a['where']['guard']+'\x22\x20not\x20found\x20in\x20LocalMark'),g['guard']=o;}if(a['where']['timeMin']!==undefined)g['timeMin']=a['where']['timeMin'];if(a['where']['timeMax']!==undefined)g['timeMax']=a['where']['timeMax'];if(a['where']['amountMin']!==undefined)g['amountMin']=a['where']['amountMin'];if(a['where']['amountMax']!==undefined)g['amountMax']=a['where']['amountMax'];if(a['where']['storeFromId']!==undefined){if(typeof a['where']['storeFromId']==='object'&&'eq'in a['where']['storeFromId']){const p=await LocalMark['Instance']()['get_address'](a['where']['storeFromId']['eq']);!p&&W_ERROR(WErrors['AddressNotFound'],'Reward\x20record\x20query\x20storeFromId\x20\x22'+a['where']['storeFromId']['eq']+'\x22\x20not\x20found\x20in\x20LocalMark'),g['storeFromId']={'eq':p};}else g['storeFromId']=a['where']['storeFromId'];}const h=buildRecordQueryConditionsFromConst(g);let i,j;switch(a['type']){case'query_reward_record_find':i=a['find']==='first'?0x65a:0x65b,j=ValueType['U64'];break;case'query_reward_record_count':i=0x65c,j=ValueType['U64'];break;case'query_reward_record_exists':i=0x65d,j=ValueType['Bool'];break;}const k=a['object']['identifier'],l=getNewIdentifier(b,a['type']);b['push']({'identifier':l,'value_type':ValueType['VecU8'],'value':Array['from'](h),'b_submission':![],'name':'query_conditions_'+l});const m=b['find'](q=>q['identifier']===k);m&&(m['object_type']=ObjectType['Reward']);const n=[];return n['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),n['push'](bcs['U8']['serialize'](l)['toBytes']()),n['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']()),n['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),n['push'](bcs['U8']['serialize'](k)['toBytes']()),n['push'](bcs['U16']['serialize'](i)['toBytes']()),checkType(j,c,a),{'output':n,'returnType':j};},ProgressHistoryFindConditionsBCS=bcs['struct']('ProgressHistoryFindConditions',{'node':bcs['option'](bcs['String']),'next_node':bcs['option'](bcs['String']),'time_min':bcs['option'](bcs['U64']),'time_max':bcs['option'](bcs['U64']),'find':bcs['U8']}),ProgressSessionFindConditionsBCS=bcs['struct']('ProgressSessionFindConditions',{'next_node':bcs['option'](bcs['String']),'find':bcs['U8']}),ProgressForwardFindConditionsBCS=bcs['struct']('ProgressForwardFindConditions',{'who':bcs['option'](bcs['Address']),'operation':bcs['option'](bcs['String']),'accomplished':bcs['option'](bcs['Bool']),'time_min':bcs['option'](bcs['U64']),'time_max':bcs['option'](bcs['U64']),'find':bcs['U8']}),buildProgressHistoryFindConditions=a=>{a['where']['node']!==undefined&&!isValidName(a['where']['node'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20history\x20find\x20node\x20\x22'+a['where']['node']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['nextNode']!==undefined&&!isValidName(a['where']['nextNode'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20history\x20find\x20nextNode\x20\x22'+a['where']['nextNode']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['indexMin']!==undefined&&!isValidU64(a['where']['indexMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20indexMin\x20\x22'+a['where']['indexMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['indexMax']!==undefined&&!isValidU64(a['where']['indexMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20indexMax\x20\x22'+a['where']['indexMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');const b={'node':a['where']['node']??null,'next_node':a['where']['nextNode']??null,'time_min':a['where']['timeMin']??null,'time_max':a['where']['timeMax']??null,'index_min':a['where']['indexMin']??null,'index_max':a['where']['indexMax']??null,'find':a['find']==='first'?0x0:0x1};return ProgressHistoryFindConditionsBCS['serialize'](b)['toBytes']();},buildProgressSessionFindConditions=a=>{a['where']['nextNode']!==undefined&&!isValidName(a['where']['nextNode'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20session\x20find\x20nextNode\x20\x22'+a['where']['nextNode']+'\x22\x20is\x20not\x20a\x20valid\x20name');const b={'next_node':a['where']['nextNode']??null,'find':a['find']==='first'?0x0:0x1};return ProgressSessionFindConditionsBCS['serialize'](b)['toBytes']();},buildProgressForwardFindConditions=async a=>{a['where']['operation']!==undefined&&!isValidName(a['where']['operation'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20forward\x20find\x20operation\x20\x22'+a['where']['operation']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20forward\x20find\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20forward\x20find\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');let b=null;if(a['where']['who']!==undefined){const d=await GetAccountOrMark_Address({'name_or_address':a['where']['who']});!d&&W_ERROR(WErrors['AddressNotFound'],'Progress\x20forward\x20find\x20who\x20\x22'+a['where']['who']+'\x22\x20not\x20found\x20in\x20LocalMark\x20or\x20accounts'),b=d;}const c={'who':b,'operation':a['where']['operation']??null,'accomplished':a['where']['accomplished']??null,'time_min':a['where']['timeMin']??null,'time_max':a['where']['timeMax']??null,'find':a['find']==='first'?0x0:0x1};return ProgressForwardFindConditionsBCS['serialize'](c)['toBytes']();},buildProgressQuery=async(a,b,c)=>{const d=[];let e;const f=ValueType['U64'];let g;switch(a['type']){case'query_progress_history_find':{e=0x4fa,g=buildProgressHistoryFindConditions(a);break;}case'query_progress_history_session_find':{e=0x4fb,g=buildProgressSessionFindConditions(a);break;}case'query_progress_history_session_forward_find':{e=0x4fc,g=await buildProgressForwardFindConditions(a);break;}case'query_progress_history_session_count':{e=0x4fd,g=new Uint8Array(0x0);break;}case'query_progress_history_session_forward_count':{e=0x4fe,g=new Uint8Array(0x0);break;}case'query_progress_history_session_forward_retained_submission_count':{e=0x4ff,g=new Uint8Array(0x0);break;}}const h=a['object']['identifier'],i=getNewIdentifier(b,a['type']);b['push']({'identifier':i,'value_type':ValueType['VecU8'],'value':Array['from'](g),'b_submission':![],'name':'query_conditions_'+i});if(a['type']==='query_progress_history_find'||a['type']==='query_progress_history_session_find'||a['type']==='query_progress_history_session_forward_find'||a['type']==='query_progress_history_session_count'||a['type']==='query_progress_history_session_forward_count'||a['type']==='query_progress_history_session_forward_retained_submission_count'){const j=b['find'](k=>k['identifier']===h);j&&(j['object_type']=ObjectType['Progress']);}(a['type']==='query_progress_history_find'||a['type']==='query_progress_history_session_find'||a['type']==='query_progress_history_session_forward_find')&&(d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](i)['toBytes']()));switch(a['type']){case'query_progress_history_session_forward_retained_submission_count':{await buildNode(a['forwardIdx'],ValueType['U64'],b,d),await buildNode(a['sessionIdx'],ValueType['U64'],b,d),await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_forward_find':case'query_progress_history_session_forward_count':{await buildNode(a['sessionIdx'],ValueType['U64'],b,d),await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_find':case'query_progress_history_session_count':{await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_find':{break;}}return d['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']()),d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](h)['toBytes']()),d['push'](bcs['U16']['serialize'](e)['toBytes']()),checkType(f,c,a),{'output':d,'returnType':f};},single_operand_op=async(a,b,c,d,e)=>{await buildNode(b,c,d,e),e['push'](bcs['U8']['serialize'](a)['toBytes']());};export const guard2file=async(a,b,c='json',d)=>{const f=await query_objects({'objects':[a],'network':d}),g=f['objects'];if(!g||g['length']===0x0||g[0x0]['type']!=='Guard'){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Guard\x20object\x20not\x20found:\x20'+a);return;}const h=g[0x0];if(!h){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Failed\x20to\x20get\x20Guard\x20object\x20data:\x20'+a);return;}let i;c==='json'?i=generateGuardJson(h):i=generateGuardMarkdown(h);try{const j=resolve(b);writeFileSync(j,i,'utf-8');}catch(k){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Failed\x20to\x20write\x20file\x20\x27'+b+'\x27:\x20'+k['message']);}};const generateGuardJson=a=>{const b={};return a['description']&&(b['description']=a['description']),a['table']&&a['table']['length']>0x0&&(b['table']=a['table']['map'](c=>({'identifier':c['identifier'],'b_submission':c['b_submission'],'value_type':c['value_type'],'value':c['value'],'name':c['name']}))),a['root']&&(b['root']=a['root']),a['relies']&&a['relies']['length']>0x0&&(b['rely']={'guards':a['relies'],'logic_or':!a['relies_logic_and']}),JSON['stringify'](b,null,0x2);},generateGuardMarkdown=a=>{const b=[];b['push']('#\x20Guard\x20Definition'),b['push'](''),b['push']('**Object\x20ID:**\x20'+a['object']),b['push'](''),b['push']('##\x20Summary'),b['push']('');const c=a['description']||'',d=a['table']?a['table']['length']:0x0;let e=''+(c['length']>0x64?c['substring'](0x0,0x61)+'...':c);e+='\x20['+d+'\x20tables]',b['push'](e),b['push'](''),b['push']('##\x20Description'),b['push'](''),b['push'](a['description']||''),b['push'](''),b['push']('##\x20Table\x20(Data\x20Definitions)'),b['push'](''),b['push']('|\x20Identifier\x20|\x20b_submission\x20|\x20value_type\x20|\x20value\x20|\x20name\x20|'),b['push']('|------------|--------------|------------|-------|------|');if(a['table']&&a['table']['length']>0x0)for(const f of a['table']){const g=parseValueType(f['value_type']),h=valueTypeToString(g),i=formatValueForMarkdown(f['value']);b['push']('|\x20'+f['identifier']+'\x20|\x20'+f['b_submission']+'\x20|\x20'+h+'\x20('+f['value_type']+')\x20|\x20'+i+'\x20|\x20'+f['name']+'\x20|');}else b['push']('|\x20-\x20|\x20-\x20|\x20-\x20|\x20-\x20|\x20-\x20|');b['push'](''),b['push']('##\x20Root\x20(Computational\x20Tree)'),b['push'](''),b['push']('The\x20root\x20node\x20MUST\x20return\x20a\x20Bool\x20value\x20(pass/fail).'),b['push']('');if(a['root']){b['push']('```json'),b['push'](JSON['stringify'](a['root'],null,0x2)),b['push']('```'),b['push']('');const j=generateNodeComments(a['root']);if(j['length']>0x0){b['push']('###\x20Node\x20Comments'),b['push']('');for(const k of j){b['push']('-\x20**'+k['type']+'**:\x20'+k['description']);}b['push']('');}}else b['push']('*No\x20root\x20node\x20data\x20available*'),b['push']('');if(a['relies']&&a['relies']['length']>0x0){b['push']('##\x20Rely\x20(Dependencies)'),b['push'](''),b['push']('**Logic:**\x20'+(a['relies_logic_and']?'AND':'OR')),b['push'](''),b['push']('**Dependent\x20Guards:**');for(const l of a['relies']){b['push']('-\x20'+l);}b['push']('');}return b['join']('\x0a');},formatValueForMarkdown=a=>{if(a===undefined||a===null)return'-';if(typeof a==='boolean')return a?'true':'false';if(typeof a==='string')return a['startsWith']('0x')&&a['length']===0x42&&(!isValidAddress(a)&&W_ERROR(WErrors['IsValidAddress'],'Invalid\x20address:\x20'+a)),a;if(typeof a==='number')return a['toString']();if(Array['isArray'](a)){if(a['length']===0x0)return'[]';if(a['length']>0x3)return'['+a['slice'](0x0,0x3)['join'](',\x20')+',\x20...\x20('+a['length']+'\x20items)]';return'['+a['join'](',\x20')+']';}if(typeof a==='object')return'{...}';return String(a);};export const generateNodeComments=(a,b=[])=>{if(!a)return b;if(a['type']==='query'){const c=typeof a['query']==='number'?a['query']:undefined;if(c!==undefined){const d=GUARDQUERY['find'](e=>e['id']===c);d&&b['push']({'type':'query('+a['query']+')','description':d['name']+':\x20'+d['description']});}}else{if(a['type']['startsWith']('query_reward_record_')){const e=a['type']['replace']('query_','')['replace'](/_/g,'.'),f=GUARDQUERY['find'](g=>g['name']===e);f?b['push']({'type':a['type'],'description':f['name']+':\x20'+f['description']}):b['push']({'type':a['type'],'description':'Reward\x20Record\x20query:\x20'+a['type']['replace'](/_/g,'\x20')});}else{if(a['type']['startsWith']('query_progress_history_')){const g=a['type']['replace']('query_','')['replace'](/_/g,'.'),h=GUARDQUERY['find'](i=>i['name']===g);h?b['push']({'type':a['type'],'description':h['name']+':\x20'+h['description']}):b['push']({'type':a['type'],'description':'Progress\x20History\x20query:\x20'+a['type']['replace'](/_/g,'\x20')});}else{if(a['type']['startsWith']('logic_'))b['push']({'type':a['type'],'description':'Logic\x20operation:\x20'+a['type']['replace'](/_/g,'\x20')});else{if(a['type']['startsWith']('calc_'))b['push']({'type':a['type'],'description':'Calculation:\x20'+a['type']['replace'](/_/g,'\x20')});else a['type']['startsWith']('convert_')&&b['push']({'type':a['type'],'description':'Type\x20conversion:\x20'+a['type']['replace'](/_/g,'\x20')});}}}}if('nodes'in a&&Array['isArray'](a['nodes']))for(const i of a['nodes']){generateNodeComments(i,b);}'node'in a&&a['node']&&generateNodeComments(a['node'],b);if('parameters'in a&&Array['isArray'](a['parameters']))for(const j of a['parameters']){generateNodeComments(j,b);}return'nodeLeft'in a&&a['nodeLeft']&&generateNodeComments(a['nodeLeft'],b),'nodeRight'in a&&a['nodeRight']&&generateNodeComments(a['nodeRight'],b),'recipient'in a&&a['recipient']&&generateNodeComments(a['recipient'],b),'historyIdx'in a&&a['historyIdx']&&generateNodeComments(a['historyIdx'],b),'sessionIdx'in a&&a['sessionIdx']&&generateNodeComments(a['sessionIdx'],b),'forwardIdx'in a&&a['forwardIdx']&&generateNodeComments(a['forwardIdx'],b),b;};const valueTypeToString=a=>{const b={[ValueType['Bool']]:'Bool',[ValueType['Address']]:'Address',[ValueType['String']]:'String',[ValueType['U8']]:'U8',[ValueType['U16']]:'U16',[ValueType['U32']]:'U32',[ValueType['U64']]:'U64',[ValueType['U128']]:'U128',[ValueType['U256']]:'U256',[ValueType['VecBool']]:'VecBool',[ValueType['VecAddress']]:'VecAddress',[ValueType['VecString']]:'VecString',[ValueType['VecU8']]:'VecU8',[ValueType['VecU16']]:'VecU16',[ValueType['VecU32']]:'VecU32',[ValueType['VecU64']]:'VecU64',[ValueType['VecU128']]:'VecU128',[ValueType['VecU256']]:'VecU256',[ValueType['VecVecU8']]:'VecVecU8',[ValueType['Value']]:'Value'};return b[a]||'Unknown('+a+')';};export const gen_passport=async(a,b,c)=>{!isValidWowAddress(b)&&W_ERROR(WErrors['InvalidParam'],'guard\x20invalid:\x20guard\x20empty');await resolveCallEnv(a);const d=await get_guardSubmissions(a,[b]);return d['submission']['length']>0x0?!c?{'type':'submission','guard':d['guard'],'submission':d['submission']}:await verify_guard(a,c):await verify_guard(a,{'type':'submission','guard':[{'object':b,'impack':!![]}],'submission':[]});};function detectFileFormatFromContent(a){const b=a['trim']();if(b['startsWith']('{')||b['startsWith']('['))return'json';return'markdown';}function extractJsonFromMarkdown(a){const b=/```(?:json)?\s*\n([\s\S]*?)```/g;let c,d=null;while((c=b['exec'](a))!==null){const e=c[0x1]['trim']();if(e['startsWith']('{')||e['startsWith']('[')){const f=a['substring'](0x0,c['index']),g=(f['match'](/\n/g)||[])['length']+0x1;d={'json':e,'lineOffset':g};}}return d;}function parseTableFromMarkdown(a){const b=a['match'](/```(?:json)?\s*\n([\s\S]*?)```/);if(b)try{const d=JSON['parse'](b[0x1]);if(Array['isArray'](d))return d;}catch{}const c=a['match'](/\|[^\n]+\|/g);if(c&&c['length']>0x2)return c['slice'](0x2)['map'](e=>{const f=e['split']('|')['filter'](j=>j['trim']())['map'](j=>j['trim']()),g=f[0x2];let h;const i=g['match'](/\((\d+)\)/);if(i)h=parseInt(i[0x1],0xa);else{const j=g['match'](/^\s*(\d+)\s*$/);if(j)h=parseInt(j[0x1],0xa);else{const k=g['match'](/^([A-Za-z]+)/);if(k)h=k[0x1];else throw new Error('Invalid\x20value_type\x20in\x20table\x20row:\x20\x22'+g+'\x22.\x20Expected\x20a\x20number\x20(0-19)\x20or\x20type\x20name\x20(e.g.,\x20\x22U64\x22,\x20\x22Address\x22)');}}return{'identifier':parseInt(f[0x0],0xa),'b_submission':f[0x1]['toLowerCase']()==='true','value_type':h,'value':f[0x3]==='-'?undefined:f[0x3],'name':f[0x4]==='-'?undefined:f[0x4]};});return undefined;}function parseRelyFromMarkdown(a){const b=a['match'](/\*\*Logic:\*\*\s*(AND|OR)/i),c=a['match'](/^\s*[-*]\s*(\S+)$/gm);if(b||c)return{'logic_or':b?b[0x1]['toUpperCase']()==='OR':![],'guards':c?c['map'](d=>d['replace'](/^\s*[-*]\s*/,'')['trim']()):[]};return undefined;}export function parseGuardFromMarkdown(a){const b=[],c={},d=extractJsonFromMarkdown(a);if(d)try{const f=JSON['parse'](d['json']);Object['assign'](c,f);}catch(g){b['push']({'message':'Failed\x20to\x20parse\x20JSON\x20from\x20code\x20block:\x20'+g['message'],'path':'/','line':d['lineOffset']});}if(!c['description']){const h=a['match'](/(?:^|\n)#+\s*(?:Description|Description|Description)[^\n]*\n+([^\n#]+)/i);h&&(c['description']=h[0x1]['trim']());}if(!c['table']){const i=a['match'](/(?:^|\n)#+\s*(?:Table|Data Table|数据表)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(i){const j=parseTableFromMarkdown(i[0x1]);j&&(c['table']=j);}}if(!c['root']){const k=a['match'](/(?:^|\n)#+\s*(?:Root|根节点)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(k){const l=k[0x1],m=l['match'](/```(?:json)?\s*\n([\s\S]*?)```/);if(m)try{c['root']=JSON['parse'](m[0x1]);}catch(n){b['push']({'message':'Failed\x20to\x20parse\x20root\x20JSON:\x20'+n['message'],'path':'/root'});}}}if(!c['rely']){const o=a['match'](/(?:^|\n)#+\s*(?:Rely|Dependencies|依赖)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(o){const p=parseRelyFromMarkdown(o[0x1]);p&&(c['rely']=p);}}if(!c['root'])return b['push']({'message':'Guard\x20root\x20node\x20not\x20found\x20in\x20markdown\x20file','path':'/root'}),{'success':![],'errors':b};return{'success':!![],'data':c,'errors':b};}export function parseGuardFile(a,b){const c=b??detectFileFormatFromContent(a);if(c==='json')try{const d=JSON['parse'](a);if(!d['root'])return{'success':![],'errors':[{'message':'Missing\x20required\x20field:\x20root','path':'/root'}]};return{'success':!![],'data':d,'errors':[]};}catch(f){return{'success':![],'errors':[{'message':'JSON\x20parse\x20error:\x20'+f['message'],'path':'/'}]};}return parseGuardFromMarkdown(a);}export function validateGuardNode(a){const b=[];if(!a||typeof a!=='object')return b['push']({'message':'GuardNode\x20must\x20be\x20an\x20object','path':'/'}),{'success':![],'errors':b};const c=a;if(!c['type']||typeof c['type']!=='string')return b['push']({'message':'GuardNode\x20must\x20have\x20a\x20\x27type\x27\x20property','path':'/type'}),{'success':![],'errors':b};const d=['identifier','query','context','logic_not','logic_and','logic_or','logic_equal','logic_as_u256_greater_or_equal','logic_as_u256_lesser_or_equal','logic_as_u256_greater','logic_as_u256_lesser','logic_as_u256_equal','logic_string_contains','logic_string_nocase_contains','logic_string_nocase_equal','calc_number_add','calc_number_subtract','calc_number_multiply','calc_number_divide','calc_number_mod','calc_string_length','calc_string_nocase_contains','calc_string_nocase_equal','calc_string_contains','calc_string_indexof','calc_string_nocase_indexof','convert_number_address','convert_address_number','convert_number_string','convert_string_number','convert_safe_u8','convert_safe_u16','convert_safe_u32','convert_safe_u64','convert_safe_u128','convert_safe_u256','value_type','vec_length','vec_contains_bool','vec_contains_address','vec_contains_string','vec_contains_string_nocase','vec_contains_number','vec_indexof_bool','vec_indexof_address','vec_indexof_string','vec_indexof_string_nocase','vec_indexof_number','query_reward_record_find','query_reward_record_count','query_reward_record_exists','query_progress_history_find','query_progress_history_session_find','query_progress_history_session_forward_find','query_progress_history_session_count','query_progress_history_session_forward_count','query_progress_history_session_forward_retained_submission_count'];return!d['includes'](c['type'])&&b['push']({'message':'Invalid\x20GuardNode\x20type:\x20'+c['type'],'path':'/type'}),{'success':b['length']===0x0,'errors':b};}export function formatGuardParseErrors(a){return a['map'](b=>{let c='Path:\x20'+b['path'];return b['line']!==undefined&&b['column']!==undefined&&(c+='\x20(line\x20'+b['line']+',\x20column\x20'+b['column']+')'),c+='\x0a\x20\x20Error:\x20'+b['message'],c;})['join']('\x0a\x0a');}
|