wowok 2.1.10 → 2.1.12
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.d.ts +199 -199
- package/dist/cjs/bcs/bcs.js +273 -318
- package/dist/cjs/bcs/bcs.js.map +1 -0
- package/dist/cjs/bcs/effects.d.ts +109 -109
- package/dist/cjs/bcs/effects.js +205 -230
- package/dist/cjs/bcs/effects.js.map +1 -0
- package/dist/cjs/bcs/index.d.ts +1 -2584
- package/dist/cjs/bcs/index.js +61 -76
- package/dist/cjs/bcs/index.js.map +1 -0
- package/dist/cjs/bcs/pure.js +38 -58
- package/dist/cjs/bcs/pure.js.map +1 -0
- package/dist/cjs/bcs/type-tag-serializer.js +102 -114
- package/dist/cjs/bcs/type-tag-serializer.js.map +1 -0
- package/dist/cjs/bcs/types.js +6 -23
- package/dist/cjs/bcs/types.js.map +1 -0
- package/dist/cjs/client/index.js +17 -33
- package/dist/cjs/client/index.js.map +1 -0
- package/dist/cjs/client/network.js +25 -40
- package/dist/cjs/client/network.js.map +1 -0
- package/dist/cjs/cryptography/index.js +29 -45
- package/dist/cjs/cryptography/index.js.map +1 -0
- package/dist/cjs/cryptography/intent.d.ts +1 -1
- package/dist/cjs/cryptography/intent.js +20 -31
- package/dist/cjs/cryptography/intent.js.map +1 -0
- package/dist/cjs/cryptography/keypair.js +102 -116
- package/dist/cjs/cryptography/keypair.js.map +1 -0
- package/dist/cjs/cryptography/mnemonics.js +43 -41
- package/dist/cjs/cryptography/mnemonics.js.map +1 -0
- package/dist/cjs/cryptography/publickey.js +112 -134
- package/dist/cjs/cryptography/publickey.js.map +1 -0
- package/dist/cjs/cryptography/signature-scheme.js +24 -43
- package/dist/cjs/cryptography/signature-scheme.js.map +1 -0
- package/dist/cjs/cryptography/signature.d.ts +2 -24
- package/dist/cjs/cryptography/signature.js +50 -67
- package/dist/cjs/cryptography/signature.js.map +1 -0
- package/dist/cjs/experimental/cache.js +65 -0
- package/dist/cjs/experimental/cache.js.map +1 -0
- package/dist/cjs/experimental/client.js +27 -0
- package/dist/cjs/experimental/client.js.map +1 -0
- package/dist/cjs/experimental/core.js +89 -0
- package/dist/cjs/experimental/core.js.map +1 -0
- package/dist/cjs/experimental/errors.js +32 -0
- package/dist/cjs/experimental/errors.js.map +1 -0
- package/dist/cjs/experimental/index.js +15 -0
- package/dist/cjs/experimental/index.js.map +1 -0
- package/dist/cjs/experimental/persistent-storage.js +343 -0
- package/dist/cjs/experimental/persistent-storage.js.map +1 -0
- package/dist/cjs/experimental/persistent-storage.test.js +200 -0
- package/dist/cjs/experimental/persistent-storage.test.js.map +1 -0
- package/dist/cjs/experimental/transports/utils.js +104 -0
- package/dist/cjs/experimental/transports/utils.js.map +1 -0
- package/dist/cjs/experimental/types.js +6 -0
- package/dist/cjs/experimental/types.js.map +1 -0
- package/dist/cjs/faucet/faucet.js +106 -124
- package/dist/cjs/faucet/faucet.js.map +1 -0
- package/dist/cjs/faucet/index.js +12 -28
- package/dist/cjs/faucet/index.js.map +1 -0
- package/dist/cjs/grpc/client.js +47 -62
- package/dist/cjs/grpc/client.js.map +1 -0
- package/dist/cjs/grpc/core.js +580 -617
- package/dist/cjs/grpc/core.js.map +1 -0
- package/dist/cjs/grpc/index.js +9 -25
- package/dist/cjs/grpc/index.js.map +1 -0
- package/dist/cjs/grpc/proto/google/protobuf/any.js +168 -135
- package/dist/cjs/grpc/proto/google/protobuf/any.js.map +1 -0
- package/dist/cjs/grpc/proto/google/protobuf/duration.js +105 -90
- package/dist/cjs/grpc/proto/google/protobuf/duration.js.map +1 -0
- package/dist/cjs/grpc/proto/google/protobuf/empty.js +50 -28
- package/dist/cjs/grpc/proto/google/protobuf/empty.js.map +1 -0
- package/dist/cjs/grpc/proto/google/protobuf/field_mask.js +96 -75
- package/dist/cjs/grpc/proto/google/protobuf/field_mask.js.map +1 -0
- package/dist/cjs/grpc/proto/google/protobuf/struct.js +266 -215
- package/dist/cjs/grpc/proto/google/protobuf/struct.js.map +1 -0
- package/dist/cjs/grpc/proto/google/protobuf/timestamp.js +150 -131
- package/dist/cjs/grpc/proto/google/protobuf/timestamp.js.map +1 -0
- package/dist/cjs/grpc/proto/google/rpc/error_details.js +331 -302
- package/dist/cjs/grpc/proto/google/rpc/error_details.js.map +1 -0
- package/dist/cjs/grpc/proto/google/rpc/status.js +50 -50
- package/dist/cjs/grpc/proto/google/rpc/status.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/argument.js +84 -68
- package/dist/cjs/grpc/proto/sui/rpc/v2/argument.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/balance_change.js +45 -50
- package/dist/cjs/grpc/proto/sui/rpc/v2/balance_change.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/bcs.js +38 -43
- package/dist/cjs/grpc/proto/sui/rpc/v2/bcs.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint.js +70 -75
- package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_contents.js +79 -81
- package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_contents.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_summary.js +183 -166
- package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_summary.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/effects.js +369 -296
- package/dist/cjs/grpc/proto/sui/rpc/v2/effects.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/epoch.js +80 -85
- package/dist/cjs/grpc/proto/sui/rpc/v2/epoch.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/error_reason.js +31 -28
- package/dist/cjs/grpc/proto/sui/rpc/v2/error_reason.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/event.js +81 -83
- package/dist/cjs/grpc/proto/sui/rpc/v2/event.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/executed_transaction.js +80 -85
- package/dist/cjs/grpc/proto/sui/rpc/v2/executed_transaction.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/execution_status.js +876 -506
- package/dist/cjs/grpc/proto/sui/rpc/v2/execution_status.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/gas_cost_summary.js +56 -61
- package/dist/cjs/grpc/proto/sui/rpc/v2/gas_cost_summary.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/input.js +103 -83
- package/dist/cjs/grpc/proto/sui/rpc/v2/input.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/jwk.js +76 -78
- package/dist/cjs/grpc/proto/sui/rpc/v2/jwk.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.client.js +69 -119
- package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.client.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.js +392 -350
- package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/move_package.js +599 -473
- package/dist/cjs/grpc/proto/sui/rpc/v2/move_package.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.client.js +46 -78
- package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.client.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.js +242 -224
- package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.client.js +32 -52
- package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.client.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.js +139 -134
- package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/object.js +109 -111
- package/dist/cjs/grpc/proto/sui/rpc/v2/object.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/object_reference.js +46 -51
- package/dist/cjs/grpc/proto/sui/rpc/v2/object_reference.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/owner.js +76 -61
- package/dist/cjs/grpc/proto/sui/rpc/v2/owner.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/protocol_config.js +46 -59
- package/dist/cjs/grpc/proto/sui/rpc/v2/protocol_config.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/signature.js +568 -522
- package/dist/cjs/grpc/proto/sui/rpc/v2/signature.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/signature_scheme.js +54 -32
- package/dist/cjs/grpc/proto/sui/rpc/v2/signature_scheme.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.client.js +27 -47
- package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.client.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.js +83 -86
- package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.client.js +53 -85
- package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.client.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.js +645 -529
- package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.client.js +37 -51
- package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.client.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.js +58 -61
- package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/system_state.js +749 -730
- package/dist/cjs/grpc/proto/sui/rpc/v2/system_state.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/transaction.js +1218 -975
- package/dist/cjs/grpc/proto/sui/rpc/v2/transaction.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js +32 -46
- package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js.map +1 -0
- package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.js +186 -167
- package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.js.map +1 -0
- package/dist/cjs/index.js +96 -91
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/jsonRpc/client.js +654 -743
- package/dist/cjs/jsonRpc/client.js.map +1 -0
- package/dist/cjs/jsonRpc/core.d.ts +7 -7
- package/dist/cjs/jsonRpc/core.js +562 -606
- package/dist/cjs/jsonRpc/core.js.map +1 -0
- package/dist/cjs/jsonRpc/errors.js +38 -56
- package/dist/cjs/jsonRpc/errors.js.map +1 -0
- package/dist/cjs/jsonRpc/http-transport.js +70 -114
- package/dist/cjs/jsonRpc/http-transport.js.map +1 -0
- package/dist/cjs/jsonRpc/index.js +14 -30
- package/dist/cjs/jsonRpc/index.js.map +1 -0
- package/dist/cjs/jsonRpc/json-rpc-resolver.js +286 -290
- package/dist/cjs/jsonRpc/json-rpc-resolver.js.map +1 -0
- package/dist/cjs/jsonRpc/rpc-websocket-client.js +150 -207
- package/dist/cjs/jsonRpc/rpc-websocket-client.js.map +1 -0
- package/dist/cjs/jsonRpc/types/chain.js +4 -15
- package/dist/cjs/jsonRpc/types/chain.js.map +1 -0
- package/dist/cjs/jsonRpc/types/changes.js +4 -15
- package/dist/cjs/jsonRpc/types/changes.js.map +1 -0
- package/dist/cjs/jsonRpc/types/coins.js +4 -15
- package/dist/cjs/jsonRpc/types/coins.js.map +1 -0
- package/dist/cjs/jsonRpc/types/common.js +4 -15
- package/dist/cjs/jsonRpc/types/common.js.map +1 -0
- package/dist/cjs/jsonRpc/types/generated.d.ts +1 -1
- package/dist/cjs/jsonRpc/types/generated.js +4 -15
- package/dist/cjs/jsonRpc/types/generated.js.map +1 -0
- package/dist/cjs/jsonRpc/types/index.js +4 -15
- package/dist/cjs/jsonRpc/types/index.js.map +1 -0
- package/dist/cjs/jsonRpc/types/params.js +4 -15
- package/dist/cjs/jsonRpc/types/params.js.map +1 -0
- package/dist/cjs/keypairs/ed25519/ed25519-hd-key.js +54 -69
- package/dist/cjs/keypairs/ed25519/ed25519-hd-key.js.map +1 -0
- package/dist/cjs/keypairs/ed25519/index.js +10 -26
- package/dist/cjs/keypairs/ed25519/index.js.map +1 -0
- package/dist/cjs/keypairs/ed25519/keypair.js +134 -159
- package/dist/cjs/keypairs/ed25519/keypair.js.map +1 -0
- package/dist/cjs/keypairs/ed25519/publickey.js +70 -84
- package/dist/cjs/keypairs/ed25519/publickey.js.map +1 -0
- package/dist/cjs/keypairs/index.js +21 -19
- package/dist/cjs/keypairs/index.js.map +1 -0
- package/dist/cjs/keypairs/passkey/index.js +11 -27
- package/dist/cjs/keypairs/passkey/index.js.map +1 -0
- package/dist/cjs/keypairs/passkey/keypair.js +245 -256
- package/dist/cjs/keypairs/passkey/keypair.js.map +1 -0
- package/dist/cjs/keypairs/passkey/publickey.js +163 -162
- package/dist/cjs/keypairs/passkey/publickey.js.map +1 -0
- package/dist/cjs/keypairs/passkey/types.js +4 -15
- package/dist/cjs/keypairs/passkey/types.js.map +1 -0
- package/dist/cjs/keypairs/secp256k1/index.js +10 -26
- package/dist/cjs/keypairs/secp256k1/index.js.map +1 -0
- package/dist/cjs/keypairs/secp256k1/keypair.js +129 -151
- package/dist/cjs/keypairs/secp256k1/keypair.js.map +1 -0
- package/dist/cjs/keypairs/secp256k1/publickey.js +71 -89
- package/dist/cjs/keypairs/secp256k1/publickey.js.map +1 -0
- package/dist/cjs/keypairs/secp256r1/index.js +10 -26
- package/dist/cjs/keypairs/secp256r1/index.js.map +1 -0
- package/dist/cjs/keypairs/secp256r1/keypair.js +127 -148
- package/dist/cjs/keypairs/secp256r1/keypair.js.map +1 -0
- package/dist/cjs/keypairs/secp256r1/publickey.js +72 -90
- package/dist/cjs/keypairs/secp256r1/publickey.js.map +1 -0
- package/dist/cjs/multisig/index.js +10 -26
- package/dist/cjs/multisig/index.js.map +1 -0
- package/dist/cjs/multisig/publickey.d.ts +1 -1
- package/dist/cjs/multisig/publickey.js +228 -276
- package/dist/cjs/multisig/publickey.js.map +1 -0
- package/dist/cjs/multisig/signer.js +62 -110
- package/dist/cjs/multisig/signer.js.map +1 -0
- package/dist/cjs/transactions/Arguments.d.ts +4 -4
- package/dist/cjs/transactions/Arguments.js +13 -34
- package/dist/cjs/transactions/Arguments.js.map +1 -0
- package/dist/cjs/transactions/Commands.js +111 -141
- package/dist/cjs/transactions/Commands.js.map +1 -0
- package/dist/cjs/transactions/Inputs.js +53 -82
- package/dist/cjs/transactions/Inputs.js.map +1 -0
- package/dist/cjs/transactions/ObjectCache.d.ts +8 -8
- package/dist/cjs/transactions/ObjectCache.js +204 -241
- package/dist/cjs/transactions/ObjectCache.js.map +1 -0
- package/dist/cjs/transactions/Transaction.d.ts +31 -31
- package/dist/cjs/transactions/Transaction.js +628 -719
- package/dist/cjs/transactions/Transaction.js.map +1 -0
- package/dist/cjs/transactions/TransactionData.d.ts +9 -9
- package/dist/cjs/transactions/TransactionData.js +396 -440
- package/dist/cjs/transactions/TransactionData.js.map +1 -0
- package/dist/cjs/transactions/__tests__/Transaction.test.js +169 -0
- package/dist/cjs/transactions/__tests__/Transaction.test.js.map +1 -0
- package/dist/cjs/transactions/__tests__/bcs.test.js +202 -0
- package/dist/cjs/transactions/__tests__/bcs.test.js.map +1 -0
- package/dist/cjs/transactions/data/internal.js +166 -207
- package/dist/cjs/transactions/data/internal.js.map +1 -0
- package/dist/cjs/transactions/data/v1.js +436 -495
- package/dist/cjs/transactions/data/v1.js.map +1 -0
- package/dist/cjs/transactions/data/v2.d.ts +5 -5
- package/dist/cjs/transactions/data/v2.js +94 -107
- package/dist/cjs/transactions/data/v2.js.map +1 -0
- package/dist/cjs/transactions/executor/caching.js +71 -113
- package/dist/cjs/transactions/executor/caching.js.map +1 -0
- package/dist/cjs/transactions/executor/parallel.js +339 -378
- package/dist/cjs/transactions/executor/parallel.js.map +1 -0
- package/dist/cjs/transactions/executor/queue.js +60 -80
- package/dist/cjs/transactions/executor/queue.js.map +1 -0
- package/dist/cjs/transactions/executor/serial.d.ts +4 -4
- package/dist/cjs/transactions/executor/serial.js +102 -131
- package/dist/cjs/transactions/executor/serial.js.map +1 -0
- package/dist/cjs/transactions/hash.js +17 -28
- package/dist/cjs/transactions/hash.js.map +1 -0
- package/dist/cjs/transactions/index.js +33 -49
- package/dist/cjs/transactions/index.js.map +1 -0
- package/dist/cjs/transactions/intents/CoinWithBalance.js +137 -191
- package/dist/cjs/transactions/intents/CoinWithBalance.js.map +1 -0
- package/dist/cjs/transactions/object.js +88 -111
- package/dist/cjs/transactions/object.js.map +1 -0
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js +20 -32
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js.map +1 -0
- package/dist/cjs/transactions/pure.js +38 -60
- package/dist/cjs/transactions/pure.js.map +1 -0
- package/dist/cjs/transactions/resolve.js +62 -88
- package/dist/cjs/transactions/resolve.js.map +1 -0
- package/dist/cjs/transactions/serializer.js +150 -163
- package/dist/cjs/transactions/serializer.js.map +1 -0
- package/dist/cjs/transactions/utils.d.ts +1 -1
- package/dist/cjs/transactions/utils.js +114 -125
- package/dist/cjs/transactions/utils.js.map +1 -0
- package/dist/cjs/utils/constants.js +29 -56
- package/dist/cjs/utils/constants.js.map +1 -0
- package/dist/cjs/utils/derived-objects.js +14 -30
- package/dist/cjs/utils/derived-objects.js.map +1 -0
- package/dist/cjs/utils/dynamic-fields.js +20 -37
- package/dist/cjs/utils/dynamic-fields.js.map +1 -0
- package/dist/cjs/utils/format.js +14 -30
- package/dist/cjs/utils/format.js.map +1 -0
- package/dist/cjs/utils/index.js +50 -64
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/move-registry.js +37 -35
- package/dist/cjs/utils/move-registry.js.map +1 -0
- package/dist/cjs/utils/sui-types.js +74 -68
- package/dist/cjs/utils/sui-types.js.map +1 -0
- package/dist/cjs/utils/suins.js +30 -46
- package/dist/cjs/utils/suins.js.map +1 -0
- package/dist/cjs/verify/index.js +12 -27
- package/dist/cjs/verify/index.js.map +1 -0
- package/dist/cjs/verify/verify.js +83 -110
- package/dist/cjs/verify/verify.js.map +1 -0
- package/dist/cjs/version.js +8 -25
- package/dist/cjs/version.js.map +1 -0
- package/dist/cjs/w/call/allocation.js +323 -413
- package/dist/cjs/w/call/allocation.js.map +1 -0
- package/dist/cjs/w/call/arb.js +105 -136
- package/dist/cjs/w/call/arb.js.map +1 -0
- package/dist/cjs/w/call/arbitration.js +1206 -1581
- package/dist/cjs/w/call/arbitration.js.map +1 -0
- package/dist/cjs/w/call/base.js +303 -333
- package/dist/cjs/w/call/base.js.map +1 -0
- package/dist/cjs/w/call/contact.js +335 -452
- package/dist/cjs/w/call/contact.js.map +1 -0
- package/dist/cjs/w/call/demand.js +690 -844
- package/dist/cjs/w/call/demand.js.map +1 -0
- package/dist/cjs/w/call/entity.js +167 -201
- package/dist/cjs/w/call/entity.js.map +1 -0
- package/dist/cjs/w/call/guard-ins.js +4376 -4389
- package/dist/cjs/w/call/guard-ins.js.map +1 -0
- package/dist/cjs/w/call/guard.js +1078 -1112
- package/dist/cjs/w/call/guard.js.map +1 -0
- package/dist/cjs/w/call/index.js +69 -70
- package/dist/cjs/w/call/index.js.map +1 -0
- package/dist/cjs/w/call/machine.js +1105 -1419
- package/dist/cjs/w/call/machine.js.map +1 -0
- package/dist/cjs/w/call/order.js +314 -454
- package/dist/cjs/w/call/order.js.map +1 -0
- package/dist/cjs/w/call/passport.js +214 -253
- package/dist/cjs/w/call/passport.js.map +1 -0
- package/dist/cjs/w/call/payment.js +187 -224
- package/dist/cjs/w/call/payment.js.map +1 -0
- package/dist/cjs/w/call/permission.js +1183 -1294
- package/dist/cjs/w/call/permission.js.map +1 -0
- package/dist/cjs/w/call/personal.js +132 -170
- package/dist/cjs/w/call/personal.js.map +1 -0
- package/dist/cjs/w/call/progress.js +634 -794
- package/dist/cjs/w/call/progress.js.map +1 -0
- package/dist/cjs/w/call/proof.js +67 -116
- package/dist/cjs/w/call/proof.js.map +1 -0
- package/dist/cjs/w/call/repository.js +1037 -1251
- package/dist/cjs/w/call/repository.js.map +1 -0
- package/dist/cjs/w/call/resource.js +111 -131
- package/dist/cjs/w/call/resource.js.map +1 -0
- package/dist/cjs/w/call/reward.js +675 -853
- package/dist/cjs/w/call/reward.js.map +1 -0
- package/dist/cjs/w/call/service.js +1879 -2385
- package/dist/cjs/w/call/service.js.map +1 -0
- package/dist/cjs/w/call/treasury.js +841 -1138
- package/dist/cjs/w/call/treasury.js.map +1 -0
- package/dist/cjs/w/call/util.js +593 -624
- package/dist/cjs/w/call/util.js.map +1 -0
- package/dist/cjs/w/common.d.ts +1 -1
- package/dist/cjs/w/common.js +548 -518
- package/dist/cjs/w/common.js.map +1 -0
- package/dist/cjs/w/exception.js +574 -584
- package/dist/cjs/w/exception.js.map +1 -0
- package/dist/cjs/w/index.js +26 -23
- package/dist/cjs/w/index.js.map +1 -0
- package/dist/cjs/w/local/account.js +664 -741
- package/dist/cjs/w/local/account.js.map +1 -0
- package/dist/cjs/w/local/cache.js +180 -166
- package/dist/cjs/w/local/cache.js.map +1 -0
- package/dist/cjs/w/local/config.js +51 -80
- package/dist/cjs/w/local/config.js.map +1 -0
- package/dist/cjs/w/local/index.js +225 -290
- package/dist/cjs/w/local/index.js.map +1 -0
- package/dist/cjs/w/local/local.d.ts +2 -2
- package/dist/cjs/w/local/local.js +638 -646
- package/dist/cjs/w/local/local.js.map +1 -0
- package/dist/cjs/w/local/storage.js +210 -164
- package/dist/cjs/w/local/storage.js.map +1 -0
- package/dist/cjs/w/local/token.js +158 -175
- package/dist/cjs/w/local/token.js.map +1 -0
- package/dist/cjs/w/local/util.js +80 -51
- package/dist/cjs/w/local/util.js.map +1 -0
- package/dist/cjs/w/local/wip.js +1078 -802
- package/dist/cjs/w/local/wip.js.map +1 -0
- package/dist/cjs/w/messenger/crypto.js +496 -389
- package/dist/cjs/w/messenger/crypto.js.map +1 -0
- package/dist/cjs/w/messenger/index.js +53 -35
- package/dist/cjs/w/messenger/index.js.map +1 -0
- package/dist/cjs/w/messenger/messenger-api.js +1159 -1035
- package/dist/cjs/w/messenger/messenger-api.js.map +1 -0
- package/dist/cjs/w/messenger/messenger-manager.js +954 -1083
- package/dist/cjs/w/messenger/messenger-manager.js.map +1 -0
- package/dist/cjs/w/messenger/messenger.d.ts +1 -1
- package/dist/cjs/w/messenger/messenger.js +1304 -1450
- package/dist/cjs/w/messenger/messenger.js.map +1 -0
- package/dist/cjs/w/messenger/server.js +390 -512
- package/dist/cjs/w/messenger/server.js.map +1 -0
- package/dist/cjs/w/messenger/session.js +399 -403
- package/dist/cjs/w/messenger/session.js.map +1 -0
- package/dist/cjs/w/messenger/storage.js +881 -777
- package/dist/cjs/w/messenger/storage.js.map +1 -0
- package/dist/cjs/w/messenger/types.d.ts +2 -2
- package/dist/cjs/w/messenger/types.js +83 -103
- package/dist/cjs/w/messenger/types.js.map +1 -0
- package/dist/cjs/w/messenger/utils.js +29 -34
- package/dist/cjs/w/messenger/utils.js.map +1 -0
- package/dist/cjs/w/query/bult-in.js +101 -110
- package/dist/cjs/w/query/bult-in.js.map +1 -0
- package/dist/cjs/w/query/event.js +134 -146
- package/dist/cjs/w/query/event.js.map +1 -0
- package/dist/cjs/w/query/index.js +22 -20
- package/dist/cjs/w/query/index.js.map +1 -0
- package/dist/cjs/w/query/object.js +1576 -1576
- package/dist/cjs/w/query/object.js.map +1 -0
- package/dist/cjs/w/query/received.js +66 -88
- package/dist/cjs/w/query/received.js.map +1 -0
- package/dist/cjs/w/query/util.js +53 -77
- package/dist/cjs/w/query/util.js.map +1 -0
- package/dist/cjs/w/util.js +589 -675
- package/dist/cjs/w/util.js.map +1 -0
- package/dist/esm/bcs/bcs.d.ts +199 -199
- package/dist/esm/bcs/bcs.js +269 -310
- package/dist/esm/bcs/bcs.js.map +1 -0
- package/dist/esm/bcs/effects.d.ts +109 -109
- package/dist/esm/bcs/effects.js +171 -179
- package/dist/esm/bcs/effects.js.map +1 -0
- package/dist/esm/bcs/index.d.ts +1 -2584
- package/dist/esm/bcs/index.js +51 -94
- package/dist/esm/bcs/index.js.map +1 -0
- package/dist/esm/bcs/pure.js +35 -38
- package/dist/esm/bcs/pure.js.map +1 -0
- package/dist/esm/bcs/type-tag-serializer.js +98 -95
- package/dist/esm/bcs/type-tag-serializer.js.map +1 -0
- package/dist/esm/bcs/types.js +5 -5
- package/dist/esm/bcs/types.js.map +1 -0
- package/dist/esm/client/index.js +7 -23
- package/dist/esm/client/index.js.map +1 -0
- package/dist/esm/client/network.js +23 -22
- package/dist/esm/client/network.js.map +1 -0
- package/dist/esm/cryptography/index.js +9 -46
- package/dist/esm/cryptography/index.js.map +1 -0
- package/dist/esm/cryptography/intent.d.ts +1 -1
- package/dist/esm/cryptography/intent.js +18 -12
- package/dist/esm/cryptography/intent.js.map +1 -0
- package/dist/esm/cryptography/keypair.js +95 -99
- package/dist/esm/cryptography/keypair.js.map +1 -0
- package/dist/esm/cryptography/mnemonics.js +40 -24
- package/dist/esm/cryptography/mnemonics.js.map +1 -0
- package/dist/esm/cryptography/publickey.js +104 -115
- package/dist/esm/cryptography/publickey.js.map +1 -0
- package/dist/esm/cryptography/signature-scheme.js +22 -24
- package/dist/esm/cryptography/signature-scheme.js.map +1 -0
- package/dist/esm/cryptography/signature.d.ts +2 -24
- package/dist/esm/cryptography/signature.js +44 -48
- package/dist/esm/cryptography/signature.js.map +1 -0
- package/dist/esm/experimental/cache.js +61 -0
- package/dist/esm/experimental/cache.js.map +1 -0
- package/dist/esm/experimental/client.js +23 -0
- package/dist/esm/experimental/client.js.map +1 -0
- package/dist/esm/experimental/core.js +85 -0
- package/dist/esm/experimental/core.js.map +1 -0
- package/dist/esm/experimental/errors.js +27 -0
- package/dist/esm/experimental/errors.js.map +1 -0
- package/dist/esm/experimental/index.js +8 -0
- package/dist/esm/experimental/index.js.map +1 -0
- package/dist/esm/experimental/persistent-storage.js +337 -0
- package/dist/esm/experimental/persistent-storage.js.map +1 -0
- package/dist/esm/experimental/persistent-storage.test.js +198 -0
- package/dist/esm/experimental/persistent-storage.test.js.map +1 -0
- package/dist/esm/experimental/transports/utils.js +100 -0
- package/dist/esm/experimental/transports/utils.js.map +1 -0
- package/dist/esm/experimental/types.js +5 -0
- package/dist/esm/experimental/types.js.map +1 -0
- package/dist/esm/faucet/faucet.js +104 -111
- package/dist/esm/faucet/faucet.js.map +1 -0
- package/dist/esm/faucet/index.js +4 -16
- package/dist/esm/faucet/index.js.map +1 -0
- package/dist/esm/grpc/client.js +34 -34
- package/dist/esm/grpc/client.js.map +1 -0
- package/dist/esm/grpc/core.js +570 -601
- package/dist/esm/grpc/core.js.map +1 -0
- package/dist/esm/grpc/index.js +5 -6
- package/dist/esm/grpc/index.js.map +1 -0
- package/dist/esm/grpc/proto/google/protobuf/any.js +161 -111
- package/dist/esm/grpc/proto/google/protobuf/any.js.map +1 -0
- package/dist/esm/grpc/proto/google/protobuf/duration.js +99 -67
- package/dist/esm/grpc/proto/google/protobuf/duration.js.map +1 -0
- package/dist/esm/grpc/proto/google/protobuf/empty.js +46 -7
- package/dist/esm/grpc/proto/google/protobuf/empty.js.map +1 -0
- package/dist/esm/grpc/proto/google/protobuf/field_mask.js +90 -52
- package/dist/esm/grpc/proto/google/protobuf/field_mask.js.map +1 -0
- package/dist/esm/grpc/proto/google/protobuf/struct.js +258 -190
- package/dist/esm/grpc/proto/google/protobuf/struct.js.map +1 -0
- package/dist/esm/grpc/proto/google/protobuf/timestamp.js +144 -108
- package/dist/esm/grpc/proto/google/protobuf/timestamp.js.map +1 -0
- package/dist/esm/grpc/proto/google/rpc/error_details.js +313 -267
- package/dist/esm/grpc/proto/google/rpc/error_details.js.map +1 -0
- package/dist/esm/grpc/proto/google/rpc/status.js +45 -28
- package/dist/esm/grpc/proto/google/rpc/status.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/argument.js +80 -47
- package/dist/esm/grpc/proto/sui/rpc/v2/argument.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/balance_change.js +41 -29
- package/dist/esm/grpc/proto/sui/rpc/v2/balance_change.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/bcs.js +34 -22
- package/dist/esm/grpc/proto/sui/rpc/v2/bcs.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint.js +61 -49
- package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_contents.js +72 -57
- package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_contents.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_summary.js +173 -139
- package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_summary.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/effects.js +358 -268
- package/dist/esm/grpc/proto/sui/rpc/v2/effects.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/epoch.js +72 -60
- package/dist/esm/grpc/proto/sui/rpc/v2/epoch.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/error_reason.js +29 -9
- package/dist/esm/grpc/proto/sui/rpc/v2/error_reason.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/event.js +74 -59
- package/dist/esm/grpc/proto/sui/rpc/v2/event.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/executed_transaction.js +69 -57
- package/dist/esm/grpc/proto/sui/rpc/v2/executed_transaction.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/execution_status.js +861 -474
- package/dist/esm/grpc/proto/sui/rpc/v2/execution_status.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/gas_cost_summary.js +52 -40
- package/dist/esm/grpc/proto/sui/rpc/v2/gas_cost_summary.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/input.js +98 -61
- package/dist/esm/grpc/proto/sui/rpc/v2/input.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/jwk.js +71 -56
- package/dist/esm/grpc/proto/sui/rpc/v2/jwk.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.client.js +65 -100
- package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.client.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.js +365 -306
- package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/move_package.js +585 -442
- package/dist/esm/grpc/proto/sui/rpc/v2/move_package.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.client.js +42 -59
- package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.client.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.js +226 -191
- package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/name_service.client.js +28 -33
- package/dist/esm/grpc/proto/sui/rpc/v2/name_service.client.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/name_service.js +129 -107
- package/dist/esm/grpc/proto/sui/rpc/v2/name_service.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/object.js +100 -85
- package/dist/esm/grpc/proto/sui/rpc/v2/object.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/object_reference.js +42 -30
- package/dist/esm/grpc/proto/sui/rpc/v2/object_reference.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/owner.js +72 -40
- package/dist/esm/grpc/proto/sui/rpc/v2/owner.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/protocol_config.js +42 -38
- package/dist/esm/grpc/proto/sui/rpc/v2/protocol_config.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/signature.js +544 -481
- package/dist/esm/grpc/proto/sui/rpc/v2/signature.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/signature_scheme.js +52 -13
- package/dist/esm/grpc/proto/sui/rpc/v2/signature_scheme.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.client.js +23 -28
- package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.client.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.js +74 -60
- package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/state_service.client.js +49 -66
- package/dist/esm/grpc/proto/sui/rpc/v2/state_service.client.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/state_service.js +623 -490
- package/dist/esm/grpc/proto/sui/rpc/v2/state_service.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.client.js +33 -32
- package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.client.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.js +50 -36
- package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/system_state.js +737 -701
- package/dist/esm/grpc/proto/sui/rpc/v2/system_state.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/transaction.js +1177 -917
- package/dist/esm/grpc/proto/sui/rpc/v2/transaction.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js +28 -27
- package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js.map +1 -0
- package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.js +169 -133
- package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.js.map +1 -0
- package/dist/esm/index.js +21 -107
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/jsonRpc/client.js +646 -727
- package/dist/esm/jsonRpc/client.js.map +1 -0
- package/dist/esm/jsonRpc/core.d.ts +7 -7
- package/dist/esm/jsonRpc/core.js +550 -581
- package/dist/esm/jsonRpc/core.js.map +1 -0
- package/dist/esm/jsonRpc/errors.js +36 -41
- package/dist/esm/jsonRpc/errors.js.map +1 -0
- package/dist/esm/jsonRpc/http-transport.js +65 -93
- package/dist/esm/jsonRpc/http-transport.js.map +1 -0
- package/dist/esm/jsonRpc/index.js +6 -20
- package/dist/esm/jsonRpc/index.js.map +1 -0
- package/dist/esm/jsonRpc/json-rpc-resolver.js +281 -276
- package/dist/esm/jsonRpc/json-rpc-resolver.js.map +1 -0
- package/dist/esm/jsonRpc/rpc-websocket-client.js +147 -189
- package/dist/esm/jsonRpc/rpc-websocket-client.js.map +1 -0
- package/dist/esm/jsonRpc/types/chain.js +4 -0
- package/dist/esm/jsonRpc/types/chain.js.map +1 -0
- package/dist/esm/jsonRpc/types/changes.js +4 -0
- package/dist/esm/jsonRpc/types/changes.js.map +1 -0
- package/dist/esm/jsonRpc/types/coins.js +4 -0
- package/dist/esm/jsonRpc/types/coins.js.map +1 -0
- package/dist/esm/jsonRpc/types/common.js +4 -0
- package/dist/esm/jsonRpc/types/common.js.map +1 -0
- package/dist/esm/jsonRpc/types/generated.d.ts +1 -1
- package/dist/esm/jsonRpc/types/generated.js +4 -0
- package/dist/esm/jsonRpc/types/generated.js.map +1 -0
- package/dist/esm/jsonRpc/types/index.js +4 -0
- package/dist/esm/jsonRpc/types/index.js.map +1 -0
- package/dist/esm/jsonRpc/types/params.js +4 -0
- package/dist/esm/jsonRpc/types/params.js.map +1 -0
- package/dist/esm/keypairs/ed25519/ed25519-hd-key.js +49 -48
- package/dist/esm/keypairs/ed25519/ed25519-hd-key.js.map +1 -0
- package/dist/esm/keypairs/ed25519/index.js +5 -10
- package/dist/esm/keypairs/ed25519/index.js.map +1 -0
- package/dist/esm/keypairs/ed25519/keypair.js +128 -146
- package/dist/esm/keypairs/ed25519/keypair.js.map +1 -0
- package/dist/esm/keypairs/ed25519/publickey.js +64 -67
- package/dist/esm/keypairs/ed25519/publickey.js.map +1 -0
- package/dist/esm/keypairs/index.js +3 -0
- package/dist/esm/keypairs/index.js.map +1 -0
- package/dist/esm/keypairs/passkey/index.js +5 -12
- package/dist/esm/keypairs/passkey/index.js.map +1 -0
- package/dist/esm/keypairs/passkey/keypair.js +236 -243
- package/dist/esm/keypairs/passkey/keypair.js.map +1 -0
- package/dist/esm/keypairs/passkey/publickey.js +154 -140
- package/dist/esm/keypairs/passkey/publickey.js.map +1 -0
- package/dist/esm/keypairs/passkey/types.js +4 -0
- package/dist/esm/keypairs/passkey/types.js.map +1 -0
- package/dist/esm/keypairs/secp256k1/index.js +5 -10
- package/dist/esm/keypairs/secp256k1/index.js.map +1 -0
- package/dist/esm/keypairs/secp256k1/keypair.js +120 -134
- package/dist/esm/keypairs/secp256k1/keypair.js.map +1 -0
- package/dist/esm/keypairs/secp256k1/publickey.js +64 -71
- package/dist/esm/keypairs/secp256k1/publickey.js.map +1 -0
- package/dist/esm/keypairs/secp256r1/index.js +5 -10
- package/dist/esm/keypairs/secp256r1/index.js.map +1 -0
- package/dist/esm/keypairs/secp256r1/keypair.js +118 -131
- package/dist/esm/keypairs/secp256r1/keypair.js.map +1 -0
- package/dist/esm/keypairs/secp256r1/publickey.js +63 -66
- package/dist/esm/keypairs/secp256r1/publickey.js.map +1 -0
- package/dist/esm/multisig/index.js +5 -10
- package/dist/esm/multisig/index.js.map +1 -0
- package/dist/esm/multisig/publickey.d.ts +1 -1
- package/dist/esm/multisig/publickey.js +216 -253
- package/dist/esm/multisig/publickey.js.map +1 -0
- package/dist/esm/multisig/signer.js +57 -89
- package/dist/esm/multisig/signer.js.map +1 -0
- package/dist/esm/transactions/Arguments.d.ts +4 -4
- package/dist/esm/transactions/Arguments.js +9 -13
- package/dist/esm/transactions/Arguments.js.map +1 -0
- package/dist/esm/transactions/Commands.js +105 -118
- package/dist/esm/transactions/Commands.js.map +1 -0
- package/dist/esm/transactions/Inputs.js +49 -61
- package/dist/esm/transactions/Inputs.js.map +1 -0
- package/dist/esm/transactions/ObjectCache.d.ts +8 -8
- package/dist/esm/transactions/ObjectCache.js +200 -223
- package/dist/esm/transactions/ObjectCache.js.map +1 -0
- package/dist/esm/transactions/Transaction.d.ts +32 -32
- package/dist/esm/transactions/Transaction.js +611 -696
- package/dist/esm/transactions/Transaction.js.map +1 -0
- package/dist/esm/transactions/TransactionData.d.ts +9 -9
- package/dist/esm/transactions/TransactionData.js +386 -415
- package/dist/esm/transactions/TransactionData.js.map +1 -0
- package/dist/esm/transactions/__tests__/Transaction.test.js +167 -0
- package/dist/esm/transactions/__tests__/Transaction.test.js.map +1 -0
- package/dist/esm/transactions/__tests__/bcs.test.js +200 -0
- package/dist/esm/transactions/__tests__/bcs.test.js.map +1 -0
- package/dist/esm/transactions/data/internal.js +158 -205
- package/dist/esm/transactions/data/internal.js.map +1 -0
- package/dist/esm/transactions/data/v1.js +419 -487
- package/dist/esm/transactions/data/v1.js.map +1 -0
- package/dist/esm/transactions/data/v2.d.ts +5 -5
- package/dist/esm/transactions/data/v2.js +89 -107
- package/dist/esm/transactions/data/v2.js.map +1 -0
- package/dist/esm/transactions/executor/caching.d.ts +2 -2
- package/dist/esm/transactions/executor/caching.js +66 -93
- package/dist/esm/transactions/executor/caching.js.map +1 -0
- package/dist/esm/transactions/executor/parallel.js +329 -352
- package/dist/esm/transactions/executor/parallel.js.map +1 -0
- package/dist/esm/transactions/executor/queue.js +58 -64
- package/dist/esm/transactions/executor/queue.js.map +1 -0
- package/dist/esm/transactions/executor/serial.d.ts +5 -5
- package/dist/esm/transactions/executor/serial.js +96 -110
- package/dist/esm/transactions/executor/serial.js.map +1 -0
- package/dist/esm/transactions/hash.js +15 -9
- package/dist/esm/transactions/hash.js.map +1 -0
- package/dist/esm/transactions/index.js +15 -41
- package/dist/esm/transactions/index.js.map +1 -0
- package/dist/esm/transactions/intents/CoinWithBalance.js +127 -165
- package/dist/esm/transactions/intents/CoinWithBalance.js.map +1 -0
- package/dist/esm/transactions/object.js +86 -92
- package/dist/esm/transactions/object.js.map +1 -0
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.js +18 -15
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.js.map +1 -0
- package/dist/esm/transactions/pure.js +34 -39
- package/dist/esm/transactions/pure.js.map +1 -0
- package/dist/esm/transactions/resolve.js +58 -69
- package/dist/esm/transactions/resolve.js.map +1 -0
- package/dist/esm/transactions/serializer.js +145 -144
- package/dist/esm/transactions/serializer.js.map +1 -0
- package/dist/esm/transactions/utils.d.ts +1 -1
- package/dist/esm/transactions/utils.js +110 -109
- package/dist/esm/transactions/utils.js.map +1 -0
- package/dist/esm/utils/constants.js +26 -36
- package/dist/esm/utils/constants.js.map +1 -0
- package/dist/esm/utils/derived-objects.js +11 -10
- package/dist/esm/utils/derived-objects.js.map +1 -0
- package/dist/esm/utils/dynamic-fields.js +16 -16
- package/dist/esm/utils/dynamic-fields.js.map +1 -0
- package/dist/esm/utils/format.js +13 -13
- package/dist/esm/utils/format.js.map +1 -0
- package/dist/esm/utils/index.js +15 -76
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/move-registry.js +34 -17
- package/dist/esm/utils/move-registry.js.map +1 -0
- package/dist/esm/utils/sui-types.js +70 -54
- package/dist/esm/utils/sui-types.js.map +1 -0
- package/dist/esm/utils/suins.js +29 -29
- package/dist/esm/utils/suins.js.map +1 -0
- package/dist/esm/verify/index.js +5 -14
- package/dist/esm/verify/index.js.map +1 -0
- package/dist/esm/verify/verify.js +76 -93
- package/dist/esm/verify/verify.js.map +1 -0
- package/dist/esm/version.js +6 -6
- package/dist/esm/version.js.map +1 -0
- package/dist/esm/w/call/allocation.js +307 -402
- package/dist/esm/w/call/allocation.js.map +1 -0
- package/dist/esm/w/call/arb.js +100 -129
- package/dist/esm/w/call/arb.js.map +1 -0
- package/dist/esm/w/call/arbitration.js +1170 -1568
- package/dist/esm/w/call/arbitration.js.map +1 -0
- package/dist/esm/w/call/base.js +288 -315
- package/dist/esm/w/call/base.js.map +1 -0
- package/dist/esm/w/call/contact.js +318 -442
- package/dist/esm/w/call/contact.js.map +1 -0
- package/dist/esm/w/call/demand.js +673 -841
- package/dist/esm/w/call/demand.js.map +1 -0
- package/dist/esm/w/call/entity.js +162 -203
- package/dist/esm/w/call/entity.js.map +1 -0
- package/dist/esm/w/call/guard-ins.js +4373 -4371
- package/dist/esm/w/call/guard-ins.js.map +1 -0
- package/dist/esm/w/call/guard.js +1061 -1108
- package/dist/esm/w/call/guard.js.map +1 -0
- package/dist/esm/w/call/index.js +24 -56
- package/dist/esm/w/call/index.js.map +1 -0
- package/dist/esm/w/call/machine.js +1086 -1433
- package/dist/esm/w/call/machine.js.map +1 -0
- package/dist/esm/w/call/order.js +301 -448
- package/dist/esm/w/call/order.js.map +1 -0
- package/dist/esm/w/call/passport.js +204 -240
- package/dist/esm/w/call/passport.js.map +1 -0
- package/dist/esm/w/call/payment.js +177 -215
- package/dist/esm/w/call/payment.js.map +1 -0
- package/dist/esm/w/call/permission.js +1172 -1320
- package/dist/esm/w/call/permission.js.map +1 -0
- package/dist/esm/w/call/personal.js +121 -156
- package/dist/esm/w/call/personal.js.map +1 -0
- package/dist/esm/w/call/progress.js +625 -797
- package/dist/esm/w/call/progress.js.map +1 -0
- package/dist/esm/w/call/proof.js +61 -103
- package/dist/esm/w/call/proof.js.map +1 -0
- package/dist/esm/w/call/repository.js +1017 -1251
- package/dist/esm/w/call/repository.js.map +1 -0
- package/dist/esm/w/call/resource.js +108 -124
- package/dist/esm/w/call/resource.js.map +1 -0
- package/dist/esm/w/call/reward.js +660 -847
- package/dist/esm/w/call/reward.js.map +1 -0
- package/dist/esm/w/call/service.js +1849 -2400
- package/dist/esm/w/call/service.js.map +1 -0
- package/dist/esm/w/call/treasury.js +815 -1125
- package/dist/esm/w/call/treasury.js.map +1 -0
- package/dist/esm/w/call/util.js +553 -576
- package/dist/esm/w/call/util.js.map +1 -0
- package/dist/esm/w/common.d.ts +1 -1
- package/dist/esm/w/common.js +579 -580
- package/dist/esm/w/common.js.map +1 -0
- package/dist/esm/w/exception.js +570 -573
- package/dist/esm/w/exception.js.map +1 -0
- package/dist/esm/w/index.js +4 -0
- package/dist/esm/w/index.js.map +1 -0
- package/dist/esm/w/local/account.js +652 -709
- package/dist/esm/w/local/account.js.map +1 -0
- package/dist/esm/w/local/cache.js +176 -147
- package/dist/esm/w/local/cache.js.map +1 -0
- package/dist/esm/w/local/config.js +46 -60
- package/dist/esm/w/local/config.js.map +1 -0
- package/dist/esm/w/local/index.js +196 -273
- package/dist/esm/w/local/index.js.map +1 -0
- package/dist/esm/w/local/local.d.ts +2 -2
- package/dist/esm/w/local/local.js +631 -626
- package/dist/esm/w/local/local.js.map +1 -0
- package/dist/esm/w/local/storage.js +168 -136
- package/dist/esm/w/local/storage.js.map +1 -0
- package/dist/esm/w/local/token.js +149 -151
- package/dist/esm/w/local/token.js.map +1 -0
- package/dist/esm/w/local/util.js +45 -22
- package/dist/esm/w/local/util.js.map +1 -0
- package/dist/esm/w/local/wip.js +1038 -781
- package/dist/esm/w/local/wip.js.map +1 -0
- package/dist/esm/w/messenger/crypto.js +491 -387
- package/dist/esm/w/messenger/crypto.js.map +1 -0
- package/dist/esm/w/messenger/index.js +27 -24
- package/dist/esm/w/messenger/index.js.map +1 -0
- package/dist/esm/w/messenger/messenger-api.js +1111 -1017
- package/dist/esm/w/messenger/messenger-api.js.map +1 -0
- package/dist/esm/w/messenger/messenger-manager.js +944 -1052
- package/dist/esm/w/messenger/messenger-manager.js.map +1 -0
- package/dist/esm/w/messenger/messenger.d.ts +1 -1
- package/dist/esm/w/messenger/messenger.js +1258 -1421
- package/dist/esm/w/messenger/messenger.js.map +1 -0
- package/dist/esm/w/messenger/server.js +388 -499
- package/dist/esm/w/messenger/server.js.map +1 -0
- package/dist/esm/w/messenger/session.js +394 -399
- package/dist/esm/w/messenger/session.js.map +1 -0
- package/dist/esm/w/messenger/storage.js +840 -751
- package/dist/esm/w/messenger/storage.js.map +1 -0
- package/dist/esm/w/messenger/types.d.ts +2 -2
- package/dist/esm/w/messenger/types.js +80 -85
- package/dist/esm/w/messenger/types.js.map +1 -0
- package/dist/esm/w/messenger/utils.js +28 -16
- package/dist/esm/w/messenger/utils.js.map +1 -0
- package/dist/esm/w/query/bult-in.js +95 -100
- package/dist/esm/w/query/bult-in.js.map +1 -0
- package/dist/esm/w/query/event.js +128 -125
- package/dist/esm/w/query/event.js.map +1 -0
- package/dist/esm/w/query/index.js +3 -0
- package/dist/esm/w/query/index.js.map +1 -0
- package/dist/esm/w/query/object.js +1560 -1574
- package/dist/esm/w/query/object.js.map +1 -0
- package/dist/esm/w/query/received.js +57 -63
- package/dist/esm/w/query/received.js.map +1 -0
- package/dist/esm/w/query/util.js +48 -56
- package/dist/esm/w/query/util.js.map +1 -0
- package/dist/esm/w/util.js +578 -673
- package/dist/esm/w/util.js.map +1 -0
- package/package.json +10 -7
- package/dist/cjs/graphql/client.js +0 -98
- package/dist/cjs/graphql/core.js +0 -506
- package/dist/cjs/graphql/generated/2024.1/tada-env.js +0 -13141
- package/dist/cjs/graphql/generated/2024.1/tsconfig.tada.js +0 -11
- package/dist/cjs/graphql/generated/2024.4/tada-env.js +0 -13287
- package/dist/cjs/graphql/generated/2024.4/tsconfig.tada.js +0 -11
- package/dist/cjs/graphql/generated/latest/tada-env.js +0 -12925
- package/dist/cjs/graphql/generated/latest/tsconfig.tada.js +0 -11
- package/dist/cjs/graphql/generated/queries.js +0 -807
- package/dist/cjs/graphql/index.js +0 -25
- package/dist/cjs/graphql/schemas/2024.1/index.js +0 -28
- package/dist/cjs/graphql/schemas/2024.4/index.js +0 -28
- package/dist/cjs/graphql/schemas/latest/index.js +0 -28
- package/dist/cjs/graphql/types.js +0 -16
- package/dist/cjs/package.json +0 -5
- package/dist/cjs/w/local/.eslintrc.js +0 -15
- package/dist/cjs/w/messenger/.eslintrc.js +0 -15
- package/dist/cjs/zklogin/address.js +0 -93
- package/dist/cjs/zklogin/bcs.js +0 -41
- package/dist/cjs/zklogin/index.js +0 -45
- package/dist/cjs/zklogin/jwt-decode.js +0 -88
- package/dist/cjs/zklogin/jwt-utils.js +0 -128
- package/dist/cjs/zklogin/nonce.js +0 -60
- package/dist/cjs/zklogin/poseidon.js +0 -64
- package/dist/cjs/zklogin/publickey.js +0 -281
- package/dist/cjs/zklogin/signature.js +0 -57
- package/dist/cjs/zklogin/utils.js +0 -98
- package/dist/esm/graphql/client.js +0 -79
- package/dist/esm/graphql/core.js +0 -505
- package/dist/esm/graphql/generated/2024.1/tada-env.js +0 -13121
- package/dist/esm/graphql/generated/2024.1/tsconfig.tada.js +0 -16
- package/dist/esm/graphql/generated/2024.4/tada-env.js +0 -13267
- package/dist/esm/graphql/generated/2024.4/tsconfig.tada.js +0 -16
- package/dist/esm/graphql/generated/latest/tada-env.js +0 -12905
- package/dist/esm/graphql/generated/latest/tsconfig.tada.js +0 -16
- package/dist/esm/graphql/generated/queries.js +0 -788
- package/dist/esm/graphql/index.js +0 -8
- package/dist/esm/graphql/schemas/2024.1/index.js +0 -8
- package/dist/esm/graphql/schemas/2024.4/index.js +0 -8
- package/dist/esm/graphql/schemas/latest/index.js +0 -8
- package/dist/esm/graphql/types.js +0 -0
- package/dist/esm/package.json +0 -5
- package/dist/esm/w/local/.eslintrc.js +0 -23
- package/dist/esm/w/messenger/.eslintrc.js +0 -23
- package/dist/esm/zklogin/address.js +0 -78
- package/dist/esm/zklogin/bcs.js +0 -21
- package/dist/esm/zklogin/index.js +0 -38
- package/dist/esm/zklogin/jwt-decode.js +0 -68
- package/dist/esm/zklogin/jwt-utils.js +0 -108
- package/dist/esm/zklogin/nonce.js +0 -40
- package/dist/esm/zklogin/poseidon.js +0 -61
- package/dist/esm/zklogin/publickey.js +0 -265
- package/dist/esm/zklogin/signature.js +0 -37
- package/dist/esm/zklogin/utils.js +0 -78
- package/dist/tsconfig.esm.tsbuildinfo +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/cjs/w/local/wip.js
CHANGED
|
@@ -1,487 +1,682 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
31
|
-
var wip_exports = {};
|
|
32
|
-
__export(wip_exports, {
|
|
33
|
-
DEFAULT_LIMITS: () => DEFAULT_LIMITS,
|
|
34
|
-
WIP: () => WIP,
|
|
35
|
-
WipError: () => WipError,
|
|
36
|
-
WipSizeError: () => WipSizeError,
|
|
37
|
-
WipValidationError: () => WipValidationError,
|
|
38
|
-
createWip: () => createWip,
|
|
39
|
-
default: () => wip_default,
|
|
40
|
-
generate_wip: () => generate_wip,
|
|
41
|
-
loadWip: () => loadWip,
|
|
42
|
-
sign_wip: () => sign_wip,
|
|
43
|
-
verifyWip: () => verifyWip,
|
|
44
|
-
verify_wip: () => verify_wip,
|
|
45
|
-
wip2html: () => wip2html,
|
|
46
|
-
wipToHtml: () => wipToHtml
|
|
2
|
+
// Copyright (c) Wowok.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
47
19
|
});
|
|
48
|
-
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
var
|
|
52
|
-
var
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.WIP = exports.WipSizeError = exports.WipValidationError = exports.WipError = exports.DEFAULT_LIMITS = void 0;
|
|
39
|
+
exports.createWip = createWip;
|
|
40
|
+
exports.verifyWip = verifyWip;
|
|
41
|
+
exports.wipToHtml = wipToHtml;
|
|
42
|
+
exports.loadWip = loadWip;
|
|
43
|
+
exports.generate_wip = generate_wip;
|
|
44
|
+
exports.verify_wip = verify_wip;
|
|
45
|
+
exports.sign_wip = sign_wip;
|
|
46
|
+
exports.wip2html = wip2html;
|
|
47
|
+
/**
|
|
48
|
+
* WIP (Witness Immutable Promise) - 见证不可篡改承诺
|
|
49
|
+
*
|
|
50
|
+
* WIP 是一种用于通过网络向 AI 传递不可篡改承诺信息的 JSON 文件格式。
|
|
51
|
+
* 该格式设计用于确保内容完整性,支持文字和多图片的组合,并通过哈希值防止篡改。
|
|
52
|
+
*
|
|
53
|
+
* === 完整示例 ===
|
|
54
|
+
*
|
|
55
|
+
* 基础示例(无签名):
|
|
56
|
+
* ```json
|
|
57
|
+
* {
|
|
58
|
+
* "wip": "https://schema.wip/v1",
|
|
59
|
+
* "payload": {
|
|
60
|
+
* "content": {
|
|
61
|
+
* "text": "我承诺在2024年12月31日前完成项目交付。",
|
|
62
|
+
* "format": "plain"
|
|
63
|
+
* },
|
|
64
|
+
* "media": [
|
|
65
|
+
* {
|
|
66
|
+
* "id": "img-001",
|
|
67
|
+
* "type": "image/png",
|
|
68
|
+
* "data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==",
|
|
69
|
+
* "filename": "contract-signature.png"
|
|
70
|
+
* }
|
|
71
|
+
* ]
|
|
72
|
+
* },
|
|
73
|
+
* "meta": {
|
|
74
|
+
* "type": "wip",
|
|
75
|
+
* "version": "1.0.0",
|
|
76
|
+
* "created": "2024-03-15T08:30:00Z",
|
|
77
|
+
* "hash": "sha256:3a6eb0790f39ac87c94f3856b2dd2c5d110e6811602261a9a923d3bb23adc8b7",
|
|
78
|
+
* "algorithm": "sha256"
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* 带数字签名的示例:
|
|
84
|
+
* ```json
|
|
85
|
+
* {
|
|
86
|
+
* "wip": "https://schema.wip/v1",
|
|
87
|
+
* "payload": {
|
|
88
|
+
* "content": {
|
|
89
|
+
* "text": "我承诺在2024年12月31日前完成项目交付。",
|
|
90
|
+
* "format": "plain"
|
|
91
|
+
* },
|
|
92
|
+
* "media": [
|
|
93
|
+
* {
|
|
94
|
+
* "id": "img-001",
|
|
95
|
+
* "type": "image/png",
|
|
96
|
+
* "data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
|
|
97
|
+
* }
|
|
98
|
+
* ]
|
|
99
|
+
* },
|
|
100
|
+
* "meta": {
|
|
101
|
+
* "type": "wip",
|
|
102
|
+
* "version": "1.0.0",
|
|
103
|
+
* "created": "2024-03-15T08:30:00Z",
|
|
104
|
+
* "hash": "sha256:3a6eb0790f39ac87c94f3856b2dd2c5d110e6811602261a9a923d3bb23adc8b7",
|
|
105
|
+
* "algorithm": "sha256",
|
|
106
|
+
* "signature": {
|
|
107
|
+
* "value": "base64EncodedSignatureValue",
|
|
108
|
+
* "publicKey": "did:web:example.com#keys-1",
|
|
109
|
+
* "algorithm": "Ed25519"
|
|
110
|
+
* }
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* === 字段说明 ===
|
|
116
|
+
*
|
|
117
|
+
* - wip: 根级标识,值为 schema URL
|
|
118
|
+
* - payload: 内容载荷
|
|
119
|
+
* - content: 文字内容
|
|
120
|
+
* - text: 文字内容
|
|
121
|
+
* - format: 格式 (plain | markdown | html)
|
|
122
|
+
* - media: 媒体文件数组
|
|
123
|
+
* - id: 唯一标识
|
|
124
|
+
* - type: MIME 类型 (image/png, image/jpeg, image/gif, image/webp)
|
|
125
|
+
* - data: Base64 编码的文件数据
|
|
126
|
+
* - filename: 可选文件名
|
|
127
|
+
* - meta: 元数据
|
|
128
|
+
* - type: 文件类型标识,固定为 "wip"
|
|
129
|
+
* - 全称: Witness Immutable Promise (见证不可篡改承诺)
|
|
130
|
+
* - 用途: 用于通过网络向 AI 传递不可篡改的承诺信息,确保内容完整性
|
|
131
|
+
* - version: 格式版本号
|
|
132
|
+
* - created: 创建时间 (ISO 8601)
|
|
133
|
+
* - hash: payload 的 SHA-256 哈希值,格式为 "sha256:hexString"
|
|
134
|
+
* - algorithm: 哈希算法标识
|
|
135
|
+
* - signature: 可选的数字签名
|
|
136
|
+
* - value: Base64 编码的签名值
|
|
137
|
+
* - publicKey: 验证公钥或 DID
|
|
138
|
+
* - algorithm: 签名算法
|
|
139
|
+
*
|
|
140
|
+
* === 缓存目录建议 ===
|
|
141
|
+
*
|
|
142
|
+
* 对于频繁使用的 WIP 文件,建议配置本地缓存目录:
|
|
143
|
+
*
|
|
144
|
+
* 1. 缓存目录位置:
|
|
145
|
+
* - Windows: %LOCALAPPDATA%\wip\cache\ (如 C:\Users\<user>\AppData\Local\wip\cache\)
|
|
146
|
+
* - macOS: ~/Library/Caches/wip/
|
|
147
|
+
* - Linux: ~/.cache/wip/
|
|
148
|
+
*
|
|
149
|
+
* 2. 缓存结构:
|
|
150
|
+
* ```
|
|
151
|
+
* wip-cache/
|
|
152
|
+
* ├── files/ # 缓存的 WIP JSON 文件
|
|
153
|
+
* │ ├── <hash1>.json
|
|
154
|
+
* │ └── <hash2>.json
|
|
155
|
+
* ├── images/ # 缓存的图片文件
|
|
156
|
+
* │ └── <hash>.png
|
|
157
|
+
* └── index.json # 缓存索引,记录元数据
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* 3. 缓存策略:
|
|
161
|
+
* - 使用 content hash 作为文件名,天然去重
|
|
162
|
+
* - 设置最大缓存大小 (如 100MB),LRU 淘汰
|
|
163
|
+
* - 缓存过期时间 (如 30 天)
|
|
164
|
+
*
|
|
165
|
+
* 4. 使用示例:
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const wip = new WIP();
|
|
168
|
+
* const cache = new WipCache("~/.cache/wip");
|
|
169
|
+
*
|
|
170
|
+
* // 检查缓存
|
|
171
|
+
* const cached = cache.get(hash);
|
|
172
|
+
* if (cached) return cached;
|
|
173
|
+
*
|
|
174
|
+
* // 从网络加载并缓存
|
|
175
|
+
* const wipFile = await wip.loadFromUrl(url);
|
|
176
|
+
* cache.set(hash, wipFile);
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
180
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
181
|
+
const fs = __importStar(require("fs"));
|
|
182
|
+
const path = __importStar(require("path"));
|
|
183
|
+
// ========== 常量定义 ==========
|
|
53
184
|
const WIP_SCHEMA_URL = "https://schema.wip/v1";
|
|
54
185
|
const WIP_VERSION = "1.0.0";
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
186
|
+
/**
|
|
187
|
+
* 默认限制配置
|
|
188
|
+
*
|
|
189
|
+
* 设计考虑:
|
|
190
|
+
* - maxImageSize: 2MB - 单张图片限制,确保 Base64 编码后不会过大
|
|
191
|
+
* - maxTotalSize: 10MB - 整个 WIP 文件大小限制,适合网络传输
|
|
192
|
+
* - maxImageCount: 10 - 最多10张图片,满足大多数承诺场景
|
|
193
|
+
* - maxTextLength: 10000 - 文字内容长度限制,约5000个汉字
|
|
194
|
+
*/
|
|
195
|
+
exports.DEFAULT_LIMITS = {
|
|
196
|
+
maxImageSize: 2 * 1024 * 1024, // 2MB
|
|
197
|
+
maxTotalSize: 10 * 1024 * 1024, // 10MB
|
|
198
|
+
maxImageCount: 10,
|
|
199
|
+
maxTextLength: 10000,
|
|
62
200
|
};
|
|
201
|
+
// ========== 错误类 ==========
|
|
63
202
|
class WipError extends Error {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
203
|
+
constructor(message) {
|
|
204
|
+
super(message);
|
|
205
|
+
this.name = "WipError";
|
|
206
|
+
}
|
|
68
207
|
}
|
|
208
|
+
exports.WipError = WipError;
|
|
69
209
|
class WipValidationError extends WipError {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
210
|
+
constructor(message) {
|
|
211
|
+
super(message);
|
|
212
|
+
this.name = "WipValidationError";
|
|
213
|
+
}
|
|
74
214
|
}
|
|
215
|
+
exports.WipValidationError = WipValidationError;
|
|
75
216
|
class WipSizeError extends WipError {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
217
|
+
constructor(message) {
|
|
218
|
+
super(message);
|
|
219
|
+
this.name = "WipSizeError";
|
|
220
|
+
}
|
|
80
221
|
}
|
|
222
|
+
exports.WipSizeError = WipSizeError;
|
|
223
|
+
// ========== 工具函数 ==========
|
|
224
|
+
/**
|
|
225
|
+
* 检测 MIME 类型从文件数据
|
|
226
|
+
*/
|
|
81
227
|
function detectMimeType(buffer) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
228
|
+
// PNG: 89 50 4E 47
|
|
229
|
+
if (buffer.length >= 4 &&
|
|
230
|
+
buffer[0] === 0x89 &&
|
|
231
|
+
buffer[1] === 0x50 &&
|
|
232
|
+
buffer[2] === 0x4e &&
|
|
233
|
+
buffer[3] === 0x47) {
|
|
234
|
+
return "image/png";
|
|
235
|
+
}
|
|
236
|
+
// JPEG: FF D8 FF
|
|
237
|
+
if (buffer.length >= 3 &&
|
|
238
|
+
buffer[0] === 0xff &&
|
|
239
|
+
buffer[1] === 0xd8 &&
|
|
240
|
+
buffer[2] === 0xff) {
|
|
241
|
+
return "image/jpeg";
|
|
242
|
+
}
|
|
243
|
+
// GIF: GIF87a 或 GIF89a
|
|
244
|
+
if (buffer.length >= 6 &&
|
|
245
|
+
buffer[0] === 0x47 &&
|
|
246
|
+
buffer[1] === 0x49 &&
|
|
247
|
+
buffer[2] === 0x46) {
|
|
248
|
+
return "image/gif";
|
|
249
|
+
}
|
|
250
|
+
// WebP: RIFF....WEBP
|
|
251
|
+
if (buffer.length >= 12 &&
|
|
252
|
+
buffer[0] === 0x52 &&
|
|
253
|
+
buffer[1] === 0x49 &&
|
|
254
|
+
buffer[2] === 0x46 &&
|
|
255
|
+
buffer[3] === 0x46 &&
|
|
256
|
+
buffer[8] === 0x57 &&
|
|
257
|
+
buffer[9] === 0x45 &&
|
|
258
|
+
buffer[10] === 0x42 &&
|
|
259
|
+
buffer[11] === 0x50) {
|
|
260
|
+
return "image/webp";
|
|
261
|
+
}
|
|
262
|
+
return null;
|
|
95
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* 将 Uint8Array 转换为 Base64 字符串
|
|
266
|
+
*/
|
|
96
267
|
function uint8ArrayToBase64(array) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
268
|
+
let binary = "";
|
|
269
|
+
const len = array.length;
|
|
270
|
+
for (let i = 0; i < len; i++) {
|
|
271
|
+
binary += String.fromCharCode(array[i]);
|
|
272
|
+
}
|
|
273
|
+
return btoa(binary);
|
|
103
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* 将 Base64 字符串转换为 Uint8Array
|
|
277
|
+
*/
|
|
104
278
|
function base64ToUint8Array(base64) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
279
|
+
const binary = atob(base64);
|
|
280
|
+
const len = binary.length;
|
|
281
|
+
const array = new Uint8Array(len);
|
|
282
|
+
for (let i = 0; i < len; i++) {
|
|
283
|
+
array[i] = binary.charCodeAt(i);
|
|
284
|
+
}
|
|
285
|
+
return array;
|
|
112
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* 规范化 JSON 对象(按键名排序)
|
|
289
|
+
*/
|
|
113
290
|
function canonicalizeJson(obj) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
(
|
|
124
|
-
);
|
|
125
|
-
return "{" + pairs.join(",") + "}";
|
|
291
|
+
if (obj === null || typeof obj !== "object") {
|
|
292
|
+
return JSON.stringify(obj);
|
|
293
|
+
}
|
|
294
|
+
if (Array.isArray(obj)) {
|
|
295
|
+
return "[" + obj.map(canonicalizeJson).join(",") + "]";
|
|
296
|
+
}
|
|
297
|
+
const sortedObj = obj;
|
|
298
|
+
const keys = Object.keys(sortedObj).sort();
|
|
299
|
+
const pairs = keys.map((key) => `"${key}":${canonicalizeJson(sortedObj[key])}`);
|
|
300
|
+
return "{" + pairs.join(",") + "}";
|
|
126
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* 计算 SHA-256 哈希
|
|
304
|
+
*/
|
|
127
305
|
function computeHash(data) {
|
|
128
|
-
|
|
129
|
-
|
|
306
|
+
const hash = (0, sha256_1.sha256)(new TextEncoder().encode(data));
|
|
307
|
+
return "sha256:" + (0, utils_1.bytesToHex)(hash);
|
|
130
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* 生成唯一 ID
|
|
311
|
+
*/
|
|
131
312
|
function generateId(prefix) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
313
|
+
const timestamp = Date.now().toString(36);
|
|
314
|
+
const random = Math.random().toString(36).substring(2, 8);
|
|
315
|
+
return `${prefix}-${timestamp}-${random}`;
|
|
135
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* 获取 MIME 类型对应的文件扩展名
|
|
319
|
+
*/
|
|
136
320
|
function getExtensionFromMimeType(mimeType) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
321
|
+
const map = {
|
|
322
|
+
"image/png": "png",
|
|
323
|
+
"image/jpeg": "jpg",
|
|
324
|
+
"image/gif": "gif",
|
|
325
|
+
"image/webp": "webp",
|
|
326
|
+
};
|
|
327
|
+
return map[mimeType] || "bin";
|
|
144
328
|
}
|
|
329
|
+
// ========== 文件加载器类(复用代码) ==========
|
|
330
|
+
/**
|
|
331
|
+
* 统一的资源加载器
|
|
332
|
+
* 支持本地文件、网络 URL、Data URL
|
|
333
|
+
*/
|
|
145
334
|
class ResourceLoader {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
const buffer = fs.readFileSync(resolvedPath);
|
|
244
|
-
return new Uint8Array(buffer);
|
|
245
|
-
}
|
|
335
|
+
maxSize;
|
|
336
|
+
constructor(maxSize) {
|
|
337
|
+
this.maxSize = maxSize;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* 加载资源
|
|
341
|
+
*/
|
|
342
|
+
async load(source) {
|
|
343
|
+
// 处理 Data URL
|
|
344
|
+
if (source.startsWith("data:")) {
|
|
345
|
+
return this.loadFromDataUrl(source);
|
|
346
|
+
}
|
|
347
|
+
// 处理 HTTP/HTTPS 网络 URL
|
|
348
|
+
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
349
|
+
return this.loadFromNetwork(source);
|
|
350
|
+
}
|
|
351
|
+
// 处理本地文件
|
|
352
|
+
return this.loadFromFile(source);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* 从 Data URL 加载
|
|
356
|
+
*/
|
|
357
|
+
loadFromDataUrl(dataUrl) {
|
|
358
|
+
const match = dataUrl.match(/^data:image\/(\w+);base64,(.+)$/);
|
|
359
|
+
if (!match) {
|
|
360
|
+
throw new WipValidationError(`Invalid data URL format: ${dataUrl.substring(0, 50)}...`);
|
|
361
|
+
}
|
|
362
|
+
const base64Data = match[2];
|
|
363
|
+
try {
|
|
364
|
+
return base64ToUint8Array(base64Data);
|
|
365
|
+
}
|
|
366
|
+
catch (error) {
|
|
367
|
+
throw new WipError(`Failed to decode data URL: ${error}`);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* 从网络加载
|
|
372
|
+
*/
|
|
373
|
+
async loadFromNetwork(url) {
|
|
374
|
+
try {
|
|
375
|
+
// 使用 AbortController 实现超时控制
|
|
376
|
+
const controller = new AbortController();
|
|
377
|
+
const timeoutId = setTimeout(() => controller.abort(), 30000);
|
|
378
|
+
const response = await fetch(url, {
|
|
379
|
+
signal: controller.signal,
|
|
380
|
+
headers: {
|
|
381
|
+
Accept: "image/png,image/jpeg,image/gif,image/webp,image/*",
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
clearTimeout(timeoutId);
|
|
385
|
+
if (!response.ok) {
|
|
386
|
+
throw new WipError(`Failed to fetch: ${response.status} ${response.statusText}`);
|
|
387
|
+
}
|
|
388
|
+
// 检查 Content-Length
|
|
389
|
+
const contentLength = response.headers.get("content-length");
|
|
390
|
+
if (contentLength && parseInt(contentLength) > this.maxSize) {
|
|
391
|
+
throw new WipSizeError(`Resource from ${url} size (${contentLength} bytes) exceeds limit (${this.maxSize} bytes)`);
|
|
392
|
+
}
|
|
393
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
394
|
+
if (arrayBuffer.byteLength > this.maxSize) {
|
|
395
|
+
throw new WipSizeError(`Resource from ${url} size (${arrayBuffer.byteLength} bytes) exceeds limit (${this.maxSize} bytes)`);
|
|
396
|
+
}
|
|
397
|
+
return new Uint8Array(arrayBuffer);
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
if (error instanceof WipError) {
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
if (error instanceof Error) {
|
|
404
|
+
if (error.name === "AbortError") {
|
|
405
|
+
throw new WipError(`Network timeout while fetching: ${url}`);
|
|
406
|
+
}
|
|
407
|
+
throw new WipError(`Network error: ${error.message}`);
|
|
408
|
+
}
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* 从本地文件加载
|
|
414
|
+
*/
|
|
415
|
+
loadFromFile(filePath) {
|
|
416
|
+
const resolvedPath = path.resolve(filePath);
|
|
417
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
418
|
+
throw new WipError(`File not found: ${resolvedPath}`);
|
|
419
|
+
}
|
|
420
|
+
const stats = fs.statSync(resolvedPath);
|
|
421
|
+
if (!stats.isFile()) {
|
|
422
|
+
throw new WipError(`Path is not a file: ${resolvedPath}`);
|
|
423
|
+
}
|
|
424
|
+
if (stats.size > this.maxSize) {
|
|
425
|
+
throw new WipSizeError(`File ${resolvedPath} size (${stats.size} bytes) exceeds limit (${this.maxSize} bytes)`);
|
|
426
|
+
}
|
|
427
|
+
const buffer = fs.readFileSync(resolvedPath);
|
|
428
|
+
return new Uint8Array(buffer);
|
|
429
|
+
}
|
|
246
430
|
}
|
|
431
|
+
// ========== WIP 类 ==========
|
|
247
432
|
class WIP {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* 创建 WIP 文件
|
|
256
|
-
*/
|
|
257
|
-
async create(options) {
|
|
258
|
-
if (options.text.length > this.limits.maxTextLength) {
|
|
259
|
-
throw new WipSizeError(
|
|
260
|
-
`Text length (${options.text.length}) exceeds limit (${this.limits.maxTextLength})`
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
const media = [];
|
|
264
|
-
if (options.images && options.images.length > 0) {
|
|
265
|
-
if (options.images.length > this.limits.maxImageCount) {
|
|
266
|
-
throw new WipSizeError(
|
|
267
|
-
`Image count (${options.images.length}) exceeds limit (${this.limits.maxImageCount})`
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
for (let i = 0; i < options.images.length; i++) {
|
|
271
|
-
const wipMedia = await this.processImage(options.images[i], i);
|
|
272
|
-
media.push(wipMedia);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
const payload = {
|
|
276
|
-
content: {
|
|
277
|
-
text: options.text,
|
|
278
|
-
format: options.textFormat || "plain"
|
|
279
|
-
},
|
|
280
|
-
media
|
|
281
|
-
};
|
|
282
|
-
const canonicalPayload = canonicalizeJson(payload);
|
|
283
|
-
const hash = computeHash(canonicalPayload);
|
|
284
|
-
const meta = {
|
|
285
|
-
type: "wip",
|
|
286
|
-
version: WIP_VERSION,
|
|
287
|
-
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
288
|
-
hash,
|
|
289
|
-
algorithm: "sha256"
|
|
290
|
-
};
|
|
291
|
-
if (options.signKeyPair) {
|
|
292
|
-
const signatureValue = await this.sign(
|
|
293
|
-
hash,
|
|
294
|
-
options.signKeyPair.privateKey,
|
|
295
|
-
options.signAlgorithm || "Ed25519"
|
|
296
|
-
);
|
|
297
|
-
meta.signature = {
|
|
298
|
-
value: signatureValue,
|
|
299
|
-
publicKey: options.signKeyPair.publicKey,
|
|
300
|
-
algorithm: options.signAlgorithm || "Ed25519"
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
const wipFile = {
|
|
304
|
-
wip: WIP_SCHEMA_URL,
|
|
305
|
-
payload,
|
|
306
|
-
meta
|
|
307
|
-
};
|
|
308
|
-
const jsonString = JSON.stringify(wipFile);
|
|
309
|
-
if (jsonString.length > this.limits.maxTotalSize) {
|
|
310
|
-
throw new WipSizeError(
|
|
311
|
-
`Total WIP file size (${jsonString.length} bytes) exceeds limit (${this.limits.maxTotalSize} bytes)`
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
return wipFile;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* 处理图片源
|
|
318
|
-
*/
|
|
319
|
-
async processImage(source, index) {
|
|
320
|
-
const data = await this.resourceLoader.load(source.source);
|
|
321
|
-
const mimeType = detectMimeType(data);
|
|
322
|
-
if (!mimeType) {
|
|
323
|
-
throw new WipValidationError(
|
|
324
|
-
`Unsupported image format: ${source.source}`
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
let filename = source.filename;
|
|
328
|
-
if (!filename) {
|
|
329
|
-
if (source.source.startsWith("http")) {
|
|
330
|
-
const url = new URL(source.source);
|
|
331
|
-
const pathname = url.pathname;
|
|
332
|
-
filename = pathname.substring(pathname.lastIndexOf("/") + 1) || `image-${index}`;
|
|
333
|
-
} else {
|
|
334
|
-
filename = source.source.substring(
|
|
335
|
-
source.source.lastIndexOf("/") + 1
|
|
336
|
-
) || `image-${index}`;
|
|
337
|
-
}
|
|
433
|
+
limits;
|
|
434
|
+
resourceLoader;
|
|
435
|
+
constructor(limits = {}) {
|
|
436
|
+
this.limits = { ...exports.DEFAULT_LIMITS, ...limits };
|
|
437
|
+
this.resourceLoader = new ResourceLoader(this.limits.maxImageSize);
|
|
338
438
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
if (wipFile.meta.type !== "wip") {
|
|
367
|
-
return {
|
|
368
|
-
valid: false,
|
|
369
|
-
error: `Invalid meta.type: ${wipFile.meta.type}`
|
|
439
|
+
/**
|
|
440
|
+
* 创建 WIP 文件
|
|
441
|
+
*/
|
|
442
|
+
async create(options) {
|
|
443
|
+
// 验证文字长度
|
|
444
|
+
if (options.text.length > this.limits.maxTextLength) {
|
|
445
|
+
throw new WipSizeError(`Text length (${options.text.length}) exceeds limit (${this.limits.maxTextLength})`);
|
|
446
|
+
}
|
|
447
|
+
// 处理图片
|
|
448
|
+
const media = [];
|
|
449
|
+
if (options.images && options.images.length > 0) {
|
|
450
|
+
if (options.images.length > this.limits.maxImageCount) {
|
|
451
|
+
throw new WipSizeError(`Image count (${options.images.length}) exceeds limit (${this.limits.maxImageCount})`);
|
|
452
|
+
}
|
|
453
|
+
for (let i = 0; i < options.images.length; i++) {
|
|
454
|
+
const wipMedia = await this.processImage(options.images[i], i);
|
|
455
|
+
media.push(wipMedia);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
// 构建 payload
|
|
459
|
+
const payload = {
|
|
460
|
+
content: {
|
|
461
|
+
text: options.text,
|
|
462
|
+
format: options.textFormat || "plain",
|
|
463
|
+
},
|
|
464
|
+
media,
|
|
370
465
|
};
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
466
|
+
// 计算哈希
|
|
467
|
+
const canonicalPayload = canonicalizeJson(payload);
|
|
468
|
+
const hash = computeHash(canonicalPayload);
|
|
469
|
+
// 构建 meta
|
|
470
|
+
const meta = {
|
|
471
|
+
type: "wip",
|
|
472
|
+
version: WIP_VERSION,
|
|
473
|
+
created: new Date().toISOString(),
|
|
474
|
+
hash,
|
|
475
|
+
algorithm: "sha256",
|
|
378
476
|
};
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
sig.value,
|
|
387
|
-
sig.publicKey,
|
|
388
|
-
sig.algorithm
|
|
389
|
-
);
|
|
390
|
-
signatures.push({
|
|
391
|
-
address: sig.address,
|
|
392
|
-
valid: signValid
|
|
393
|
-
});
|
|
394
|
-
if (!signValid) {
|
|
395
|
-
return {
|
|
396
|
-
valid: false,
|
|
397
|
-
error: "Invalid signature",
|
|
398
|
-
signatures
|
|
477
|
+
// 添加签名
|
|
478
|
+
if (options.signKeyPair) {
|
|
479
|
+
const signatureValue = await this.sign(hash, options.signKeyPair.privateKey, options.signAlgorithm || "Ed25519");
|
|
480
|
+
meta.signature = {
|
|
481
|
+
value: signatureValue,
|
|
482
|
+
publicKey: options.signKeyPair.publicKey,
|
|
483
|
+
algorithm: options.signAlgorithm || "Ed25519",
|
|
399
484
|
};
|
|
400
|
-
}
|
|
401
485
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
486
|
+
const wipFile = {
|
|
487
|
+
wip: WIP_SCHEMA_URL,
|
|
488
|
+
payload,
|
|
489
|
+
meta,
|
|
490
|
+
};
|
|
491
|
+
// 验证总大小
|
|
492
|
+
const jsonString = JSON.stringify(wipFile);
|
|
493
|
+
if (jsonString.length > this.limits.maxTotalSize) {
|
|
494
|
+
throw new WipSizeError(`Total WIP file size (${jsonString.length} bytes) exceeds limit (${this.limits.maxTotalSize} bytes)`);
|
|
495
|
+
}
|
|
496
|
+
return wipFile;
|
|
406
497
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
498
|
+
/**
|
|
499
|
+
* 处理图片源
|
|
500
|
+
*/
|
|
501
|
+
async processImage(source, index) {
|
|
502
|
+
const data = await this.resourceLoader.load(source.source);
|
|
503
|
+
const mimeType = detectMimeType(data);
|
|
504
|
+
if (!mimeType) {
|
|
505
|
+
throw new WipValidationError(`Unsupported image format: ${source.source}`);
|
|
506
|
+
}
|
|
507
|
+
let filename = source.filename;
|
|
508
|
+
if (!filename) {
|
|
509
|
+
if (source.source.startsWith("http")) {
|
|
510
|
+
const url = new URL(source.source);
|
|
511
|
+
const pathname = url.pathname;
|
|
512
|
+
filename =
|
|
513
|
+
pathname.substring(pathname.lastIndexOf("/") + 1) ||
|
|
514
|
+
`image-${index}`;
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
filename =
|
|
518
|
+
source.source.substring(source.source.lastIndexOf("/") + 1) || `image-${index}`;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return {
|
|
522
|
+
id: source.id || generateId("img"),
|
|
523
|
+
type: mimeType,
|
|
524
|
+
data: uint8ArrayToBase64(data),
|
|
525
|
+
filename,
|
|
526
|
+
};
|
|
414
527
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
pkToUse = buffer.slice(1).toString("base64");
|
|
422
|
-
} else if (buffer.length === 32) {
|
|
423
|
-
pkToUse = buffer.toString("base64");
|
|
528
|
+
/**
|
|
529
|
+
* 签名(真实实现)
|
|
530
|
+
*/
|
|
531
|
+
async sign(data, privateKey, algorithm) {
|
|
532
|
+
if (algorithm !== "Ed25519") {
|
|
533
|
+
throw new WipError(`Unsupported signature algorithm: ${algorithm}`);
|
|
424
534
|
}
|
|
425
|
-
|
|
535
|
+
const { Ed25519Keypair } = await import("../../keypairs/ed25519/index.js");
|
|
536
|
+
const keypair = Ed25519Keypair.fromSecretKey(privateKey);
|
|
537
|
+
const signature = await keypair.sign(new TextEncoder().encode(data));
|
|
538
|
+
return uint8ArrayToBase64(signature);
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* 验证 WIP 文件
|
|
542
|
+
*/
|
|
543
|
+
async verify(wipFile) {
|
|
426
544
|
try {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
545
|
+
if (!wipFile.wip || !wipFile.payload || !wipFile.meta) {
|
|
546
|
+
return { valid: false, error: "Invalid WIP file structure" };
|
|
547
|
+
}
|
|
548
|
+
if (wipFile.meta.type !== "wip") {
|
|
549
|
+
return {
|
|
550
|
+
valid: false,
|
|
551
|
+
error: `Invalid meta.type: ${wipFile.meta.type}`,
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
const canonicalPayload = canonicalizeJson(wipFile.payload);
|
|
555
|
+
const computedHash = computeHash(canonicalPayload);
|
|
556
|
+
if (computedHash !== wipFile.meta.hash) {
|
|
557
|
+
return {
|
|
558
|
+
valid: false,
|
|
559
|
+
error: "Hash mismatch - content has been tampered",
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
const signatures = [];
|
|
563
|
+
if (wipFile.meta.signature) {
|
|
564
|
+
// 支持多签名验证
|
|
565
|
+
const sigArray = Array.isArray(wipFile.meta.signature)
|
|
566
|
+
? wipFile.meta.signature
|
|
567
|
+
: [wipFile.meta.signature];
|
|
568
|
+
for (const sig of sigArray) {
|
|
569
|
+
const signValid = await this.verifySignature(wipFile.meta.hash, sig.value, sig.publicKey, sig.algorithm);
|
|
570
|
+
signatures.push({
|
|
571
|
+
address: sig.address,
|
|
572
|
+
valid: signValid,
|
|
573
|
+
});
|
|
574
|
+
if (!signValid) {
|
|
575
|
+
return {
|
|
576
|
+
valid: false,
|
|
577
|
+
error: "Invalid signature",
|
|
578
|
+
signatures,
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return { valid: true, signatures };
|
|
584
|
+
}
|
|
585
|
+
catch (error) {
|
|
586
|
+
return { valid: false, error: `Verification error: ${error}` };
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* 验证签名
|
|
591
|
+
*/
|
|
592
|
+
async verifySignature(data, signature, publicKey, algorithm) {
|
|
593
|
+
if (algorithm !== "Ed25519") {
|
|
594
|
+
throw new WipError(`Unsupported signature algorithm: ${algorithm}`);
|
|
595
|
+
}
|
|
596
|
+
try {
|
|
597
|
+
const { Ed25519PublicKey } = await import("../../keypairs/ed25519/publickey.js");
|
|
598
|
+
let pkToUse = publicKey;
|
|
599
|
+
if (publicKey.startsWith("0x")) {
|
|
600
|
+
const buffer = Buffer.from(publicKey.slice(2), "hex");
|
|
601
|
+
if (buffer.length === 33) {
|
|
602
|
+
pkToUse = buffer.slice(1).toString("base64");
|
|
603
|
+
}
|
|
604
|
+
else if (buffer.length === 32) {
|
|
605
|
+
pkToUse = buffer.toString("base64");
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
// 处理 base64 公钥(可能是 33 字节带 flag 或 32 字节原始公钥)
|
|
610
|
+
try {
|
|
611
|
+
const buffer = Buffer.from(publicKey, "base64");
|
|
612
|
+
if (buffer.length === 33) {
|
|
613
|
+
// 33 字节:包含 flag,取后 32 字节
|
|
614
|
+
pkToUse = buffer.slice(1).toString("base64");
|
|
615
|
+
}
|
|
616
|
+
// 32 字节:直接使用
|
|
617
|
+
}
|
|
618
|
+
catch {
|
|
619
|
+
// 解码失败,使用原始值
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
const pubKey = new Ed25519PublicKey(pkToUse);
|
|
623
|
+
const signatureBytes = Uint8Array.from(Buffer.from(signature, "base64"));
|
|
624
|
+
return await pubKey.verify(new TextEncoder().encode(data), signatureBytes);
|
|
625
|
+
}
|
|
626
|
+
catch (error) {
|
|
627
|
+
console.error("Signature verification error:", error);
|
|
628
|
+
return false;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* 转换为 HTML
|
|
633
|
+
*/
|
|
634
|
+
async toHtml(wipFile, options = {}) {
|
|
635
|
+
const { title = "WIP Document", theme = "light" } = options;
|
|
636
|
+
const { payload, meta } = wipFile;
|
|
637
|
+
const escapeHtml = (text) => {
|
|
638
|
+
return text
|
|
639
|
+
.replace(/&/g, "&")
|
|
640
|
+
.replace(/</g, "<")
|
|
641
|
+
.replace(/>/g, ">")
|
|
642
|
+
.replace(/"/g, """)
|
|
643
|
+
.replace(/'/g, "'");
|
|
644
|
+
};
|
|
645
|
+
const formatText = (text, format) => {
|
|
646
|
+
switch (format) {
|
|
647
|
+
case "html":
|
|
648
|
+
return text;
|
|
649
|
+
case "markdown":
|
|
650
|
+
return text
|
|
651
|
+
.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>")
|
|
652
|
+
.replace(/\*(.+?)\*/g, "<em>$1</em>")
|
|
653
|
+
.replace(/\n/g, "<br>");
|
|
654
|
+
case "plain":
|
|
655
|
+
default:
|
|
656
|
+
return escapeHtml(text).replace(/\n/g, "<br>");
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
const bgColor = theme === "dark" ? "#1a1a1a" : "#ffffff";
|
|
660
|
+
const textColor = theme === "dark" ? "#e0e0e0" : "#333333";
|
|
661
|
+
const borderColor = theme === "dark" ? "#444444" : "#e0e0e0";
|
|
662
|
+
const verifiedColor = "#4caf50";
|
|
663
|
+
const warningColor = "#ff9800";
|
|
664
|
+
const verifyResult = await this.verify(wipFile);
|
|
665
|
+
const statusBadge = verifyResult.valid
|
|
666
|
+
? `<span style="background: ${verifiedColor}; color: white; padding: 4px 8px; border-radius: 4px; font-size: 12px;">✓ Verified</span>`
|
|
667
|
+
: `<span style="background: ${warningColor}; color: white; padding: 4px 8px; border-radius: 4px; font-size: 12px;">⚠ Tampered</span>`;
|
|
668
|
+
const imagesHtml = payload.media
|
|
669
|
+
.map((media) => `
|
|
476
670
|
<div style="margin: 16px 0; border: 1px solid ${borderColor}; border-radius: 8px; overflow: hidden;">
|
|
477
671
|
<img src="data:${media.type};base64,${media.data}"
|
|
478
672
|
style="max-width: 100%; height: auto; display: block;"
|
|
479
673
|
alt="${escapeHtml(media.filename || media.id)}" />
|
|
480
674
|
${media.filename ? `<div style="padding: 8px; font-size: 12px; color: #666; background: ${theme === "dark" ? "#2a2a2a" : "#f5f5f5"}; border-top: 1px solid ${borderColor};">${escapeHtml(media.filename)}</div>` : ""}
|
|
481
675
|
</div>
|
|
482
|
-
`
|
|
483
|
-
|
|
484
|
-
|
|
676
|
+
`)
|
|
677
|
+
.join("");
|
|
678
|
+
// 签名详情不在 HTML 中显示,只显示验证结果
|
|
679
|
+
return `<!DOCTYPE html>
|
|
485
680
|
<html lang="en">
|
|
486
681
|
<head>
|
|
487
682
|
<meta charset="UTF-8">
|
|
@@ -495,7 +690,7 @@ class WIP {
|
|
|
495
690
|
<div>
|
|
496
691
|
<h1 style="margin: 0; font-size: 20px; font-weight: 600;">${escapeHtml(title)}</h1>
|
|
497
692
|
<div style="font-size: 12px; color: #666; margin-top: 4px;">
|
|
498
|
-
WIP v${meta.version}
|
|
693
|
+
WIP v${meta.version} • ${new Date(meta.created).toLocaleString()}
|
|
499
694
|
</div>
|
|
500
695
|
</div>
|
|
501
696
|
${statusBadge}
|
|
@@ -503,18 +698,20 @@ class WIP {
|
|
|
503
698
|
<div style="font-size: 11px; color: #999; margin-top: 12px; padding: 8px; background: ${theme === "dark" ? "#2a2a2a" : "#f5f5f5"}; border-radius: 4px; font-style: italic;">
|
|
504
699
|
Important Note: This page is for document browsing and verification reference only. Please verify the document integrity through the API using the WIP file.
|
|
505
700
|
</div>
|
|
506
|
-
${verifyResult.signatures && verifyResult.signatures.length > 0
|
|
701
|
+
${verifyResult.signatures && verifyResult.signatures.length > 0
|
|
702
|
+
? `
|
|
507
703
|
<div style="margin-top: 12px; padding: 8px; background: ${theme === "dark" ? "#2a3f2a" : "#e8f5e9"}; border-radius: 4px;">
|
|
508
|
-
<div style="font-size: 11px; color: ${theme === "dark" ? "#81c784" : "#2e7d32"}; margin-bottom: 4px;"
|
|
509
|
-
${verifyResult.signatures
|
|
510
|
-
|
|
704
|
+
<div style="font-size: 11px; color: ${theme === "dark" ? "#81c784" : "#2e7d32"}; margin-bottom: 4px;">✓ Signature Verification (${verifyResult.signatures.length} signature${verifyResult.signatures.length > 1 ? "s" : ""})</div>
|
|
705
|
+
${verifyResult.signatures
|
|
706
|
+
.map((s, idx) => `
|
|
511
707
|
<div style="font-size: 10px; color: ${textColor}; margin-left: 8px;">
|
|
512
|
-
${idx + 1}. ${s.address ? escapeHtml(s.address.slice(0, 20)) + "..." : "Unknown"}: ${s.valid ? '<span style="color: #4caf50;"
|
|
708
|
+
${idx + 1}. ${s.address ? escapeHtml(s.address.slice(0, 20)) + "..." : "Unknown"}: ${s.valid ? '<span style="color: #4caf50;">✓ Valid</span>' : '<span style="color: #f44336;">✗ Invalid</span>'}
|
|
513
709
|
</div>
|
|
514
|
-
`
|
|
515
|
-
|
|
710
|
+
`)
|
|
711
|
+
.join("")}
|
|
516
712
|
</div>
|
|
517
|
-
`
|
|
713
|
+
`
|
|
714
|
+
: ""}
|
|
518
715
|
</div>
|
|
519
716
|
<div style="padding: 24px;">
|
|
520
717
|
<div style="font-size: 16px; line-height: 1.8; margin-bottom: 24px;">
|
|
@@ -535,377 +732,456 @@ class WIP {
|
|
|
535
732
|
</div>
|
|
536
733
|
</body>
|
|
537
734
|
</html>`;
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* 序列化为 JSON
|
|
738
|
+
*/
|
|
739
|
+
stringify(wipFile, pretty = true) {
|
|
740
|
+
return pretty
|
|
741
|
+
? JSON.stringify(wipFile, null, 2)
|
|
742
|
+
: JSON.stringify(wipFile);
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* 从 JSON 解析
|
|
746
|
+
*/
|
|
747
|
+
parse(jsonString) {
|
|
748
|
+
try {
|
|
749
|
+
const obj = JSON.parse(jsonString);
|
|
750
|
+
if (!obj.wip || !obj.payload || !obj.meta) {
|
|
751
|
+
throw new WipValidationError("Invalid WIP file structure");
|
|
752
|
+
}
|
|
753
|
+
return obj;
|
|
754
|
+
}
|
|
755
|
+
catch (error) {
|
|
756
|
+
if (error instanceof WipError) {
|
|
757
|
+
throw error;
|
|
758
|
+
}
|
|
759
|
+
throw new WipValidationError(`Failed to parse WIP file: ${error}`);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* 从 URL 或本地路径加载 WIP 文件
|
|
764
|
+
*/
|
|
765
|
+
async load(source) {
|
|
766
|
+
const data = await this.resourceLoader.load(source);
|
|
767
|
+
const content = new TextDecoder().decode(data);
|
|
768
|
+
return this.parse(content);
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* 提取图片
|
|
772
|
+
*/
|
|
773
|
+
extractImages(wipFile, outputDir) {
|
|
774
|
+
if (!fs.existsSync(outputDir)) {
|
|
775
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
776
|
+
}
|
|
777
|
+
const savedPaths = [];
|
|
778
|
+
for (const media of wipFile.payload.media) {
|
|
779
|
+
const ext = getExtensionFromMimeType(media.type);
|
|
780
|
+
const filename = media.filename || `${media.id}.${ext}`;
|
|
781
|
+
const outputPath = path.join(outputDir, filename);
|
|
782
|
+
const buffer = Buffer.from(base64ToUint8Array(media.data));
|
|
783
|
+
fs.writeFileSync(outputPath, buffer);
|
|
784
|
+
savedPaths.push(outputPath);
|
|
785
|
+
}
|
|
786
|
+
return savedPaths;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* 保存到文件
|
|
790
|
+
*/
|
|
791
|
+
save(wipFile, filePath, pretty = true) {
|
|
792
|
+
const dir = path.dirname(filePath);
|
|
793
|
+
if (!fs.existsSync(dir)) {
|
|
794
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
795
|
+
}
|
|
796
|
+
fs.writeFileSync(filePath, this.stringify(wipFile, pretty), "utf-8");
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* 获取限制配置
|
|
800
|
+
*/
|
|
801
|
+
getLimits() {
|
|
802
|
+
return { ...this.limits };
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* 更新限制配置
|
|
806
|
+
*/
|
|
807
|
+
setLimits(limits) {
|
|
808
|
+
this.limits = { ...this.limits, ...limits };
|
|
809
|
+
this.resourceLoader = new ResourceLoader(this.limits.maxImageSize);
|
|
810
|
+
}
|
|
611
811
|
}
|
|
812
|
+
exports.WIP = WIP;
|
|
813
|
+
// ========== 便捷函数 ==========
|
|
612
814
|
async function createWip(options, limits) {
|
|
613
|
-
|
|
614
|
-
|
|
815
|
+
const wip = new WIP(limits);
|
|
816
|
+
return wip.create(options);
|
|
615
817
|
}
|
|
616
818
|
async function verifyWip(wipFile, hash_equal) {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
819
|
+
if (hash_equal !== undefined &&
|
|
820
|
+
wipFile.meta.hash.toLowerCase() !== hash_equal.toLowerCase()) {
|
|
821
|
+
return { valid: false, error: "Hash mismatch" };
|
|
822
|
+
}
|
|
823
|
+
const wip = new WIP();
|
|
824
|
+
return wip.verify(wipFile);
|
|
622
825
|
}
|
|
623
826
|
async function wipToHtml(wipFile, options) {
|
|
624
|
-
|
|
625
|
-
|
|
827
|
+
const wip = new WIP();
|
|
828
|
+
return wip.toHtml(wipFile, options);
|
|
626
829
|
}
|
|
627
830
|
async function loadWip(source, limits) {
|
|
628
|
-
|
|
629
|
-
|
|
831
|
+
const wip = new WIP(limits);
|
|
832
|
+
return wip.load(source);
|
|
630
833
|
}
|
|
834
|
+
/**
|
|
835
|
+
* 生成 WIP 文件并保存到指定路径
|
|
836
|
+
*
|
|
837
|
+
* @param options 生成选项
|
|
838
|
+
* @param outputPath 输出文件路径
|
|
839
|
+
* @param limits 可选的限制配置
|
|
840
|
+
* @returns 生成的 WIP 文件路径
|
|
841
|
+
*/
|
|
631
842
|
async function generate_wip(options, outputPath) {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
843
|
+
const wip = new WIP(exports.DEFAULT_LIMITS);
|
|
844
|
+
// 1. 创建 WIP 文件(无签名)
|
|
845
|
+
let wipFile = await wip.create({
|
|
846
|
+
text: options.markdown_text,
|
|
847
|
+
textFormat: "markdown",
|
|
848
|
+
images: options.images,
|
|
849
|
+
});
|
|
850
|
+
// 2. 如果指定了 account,使用 Account 模块进行签名
|
|
851
|
+
if (options.account) {
|
|
852
|
+
const { Account } = await import("./account.js");
|
|
853
|
+
const address = await Account.Instance().get_address(options.account);
|
|
854
|
+
if (!address) {
|
|
855
|
+
throw new WipValidationError(`Account not found: ${options.account}`);
|
|
856
|
+
}
|
|
857
|
+
// 使用 Account 签名
|
|
858
|
+
const signature = await Account.Instance().sign(address, wipFile.meta.hash);
|
|
859
|
+
// 获取公钥
|
|
860
|
+
const accountData = await Account.Instance().get(address);
|
|
861
|
+
if (!accountData || !accountData.pubkey) {
|
|
862
|
+
throw new WipValidationError(`Cannot get public key for account: ${address}`);
|
|
863
|
+
}
|
|
864
|
+
// 转换公钥格式为 base64 (32字节)
|
|
865
|
+
let publicKeyBase64;
|
|
866
|
+
if (accountData.pubkey.startsWith("0x")) {
|
|
867
|
+
const buffer = Buffer.from(accountData.pubkey.slice(2), "hex");
|
|
868
|
+
if (buffer.length === 33) {
|
|
869
|
+
publicKeyBase64 = buffer.slice(1).toString("base64");
|
|
870
|
+
}
|
|
871
|
+
else if (buffer.length === 32) {
|
|
872
|
+
publicKeyBase64 = buffer.toString("base64");
|
|
873
|
+
}
|
|
874
|
+
else {
|
|
875
|
+
throw new WipValidationError(`Invalid public key length: ${buffer.length}, expected 32 or 33 bytes`);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
else {
|
|
879
|
+
publicKeyBase64 = accountData.pubkey;
|
|
880
|
+
}
|
|
881
|
+
// 转换签名为 base64
|
|
882
|
+
const signatureBase64 = Buffer.from(signature.slice(2), "hex").toString("base64");
|
|
883
|
+
// 构建新签名
|
|
884
|
+
const newSignature = {
|
|
885
|
+
value: signatureBase64,
|
|
886
|
+
publicKey: publicKeyBase64,
|
|
887
|
+
algorithm: "Ed25519",
|
|
888
|
+
address,
|
|
889
|
+
};
|
|
890
|
+
// 处理多签名:如果已有签名,追加到数组中
|
|
891
|
+
let signatures;
|
|
892
|
+
if (wipFile.meta.signature) {
|
|
893
|
+
// 如果已有签名是数组,追加;如果是单个,转换为数组
|
|
894
|
+
signatures = Array.isArray(wipFile.meta.signature)
|
|
895
|
+
? [...wipFile.meta.signature, newSignature]
|
|
896
|
+
: [wipFile.meta.signature, newSignature];
|
|
897
|
+
}
|
|
898
|
+
else {
|
|
899
|
+
signatures = [newSignature];
|
|
900
|
+
}
|
|
901
|
+
// 添加签名到 meta
|
|
902
|
+
wipFile = {
|
|
903
|
+
...wipFile,
|
|
904
|
+
meta: {
|
|
905
|
+
...wipFile.meta,
|
|
906
|
+
signature: signatures,
|
|
907
|
+
},
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
wip.save(wipFile, outputPath, true);
|
|
911
|
+
return outputPath;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* 验证 WIP 文件
|
|
915
|
+
* 验证内容包括:
|
|
916
|
+
* 1. 基本结构验证
|
|
917
|
+
* 2. 哈希值验证(内容完整性)
|
|
918
|
+
* 3. 数字签名验证(如果存在)
|
|
919
|
+
*
|
|
920
|
+
* @param wipFilePath WIP 文件路径
|
|
921
|
+
* @returns 验证结果,包含哈希验证和签名验证状态
|
|
922
|
+
*/
|
|
923
|
+
async function verify_wip(wipFilePath, hash_equal) {
|
|
924
|
+
const wip = new WIP();
|
|
925
|
+
// 加载 WIP 文件
|
|
926
|
+
let wipFile;
|
|
927
|
+
try {
|
|
928
|
+
wipFile = await wip.load(wipFilePath);
|
|
929
|
+
}
|
|
930
|
+
catch (error) {
|
|
931
|
+
return {
|
|
932
|
+
valid: false,
|
|
933
|
+
error: `Failed to load WIP file: ${error}`,
|
|
934
|
+
hashValid: false,
|
|
935
|
+
hasSignature: false,
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
// 验证基本结构
|
|
939
|
+
if (!wipFile.wip || !wipFile.payload || !wipFile.meta) {
|
|
940
|
+
return {
|
|
941
|
+
valid: false,
|
|
942
|
+
error: "Invalid WIP file structure",
|
|
943
|
+
hashValid: false,
|
|
944
|
+
hasSignature: false,
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
if (wipFile.meta.type !== "wip") {
|
|
948
|
+
return {
|
|
949
|
+
valid: false,
|
|
950
|
+
error: `Invalid meta.type: ${wipFile.meta.type}`,
|
|
951
|
+
hashValid: false,
|
|
952
|
+
hasSignature: !!wipFile.meta.signature,
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
// 如果提供了 hash_equal,先验证文件 meta.hash 是否匹配
|
|
956
|
+
if (hash_equal !== undefined &&
|
|
957
|
+
wipFile.meta.hash.toLowerCase() !== hash_equal.toLowerCase()) {
|
|
958
|
+
return {
|
|
959
|
+
valid: false,
|
|
960
|
+
error: "Hash mismatch",
|
|
961
|
+
hashValid: false,
|
|
962
|
+
hasSignature: !!wipFile.meta.signature,
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
// 验证哈希
|
|
966
|
+
const canonicalPayload = canonicalizeJson(wipFile.payload);
|
|
967
|
+
const computedHash = computeHash(canonicalPayload);
|
|
968
|
+
const hashValid = computedHash === wipFile.meta.hash;
|
|
969
|
+
if (!hashValid) {
|
|
970
|
+
return {
|
|
971
|
+
valid: false,
|
|
972
|
+
error: "Hash mismatch - content has been tampered",
|
|
973
|
+
hashValid: false,
|
|
974
|
+
hasSignature: !!wipFile.meta.signature,
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
// 验证签名(如果存在)
|
|
978
|
+
let signatureValid;
|
|
979
|
+
const signatures = [];
|
|
980
|
+
if (wipFile.meta.signature) {
|
|
981
|
+
// 支持多签名验证
|
|
982
|
+
const sigArray = Array.isArray(wipFile.meta.signature)
|
|
983
|
+
? wipFile.meta.signature
|
|
984
|
+
: [wipFile.meta.signature];
|
|
985
|
+
let allValid = true;
|
|
986
|
+
for (const sig of sigArray) {
|
|
987
|
+
const isValid = await wip["verifySignature"](wipFile.meta.hash, sig.value, sig.publicKey, sig.algorithm);
|
|
988
|
+
// 通过公钥推导地址
|
|
989
|
+
let address;
|
|
990
|
+
try {
|
|
991
|
+
const { Ed25519PublicKey } = await import("../../keypairs/ed25519/publickey.js");
|
|
992
|
+
const pubKey = new Ed25519PublicKey(sig.publicKey);
|
|
993
|
+
address = pubKey.toWAddress();
|
|
994
|
+
}
|
|
995
|
+
catch {
|
|
996
|
+
// 推导失败不影响验证结果
|
|
997
|
+
}
|
|
998
|
+
signatures.push({
|
|
999
|
+
publicKey: sig.publicKey,
|
|
1000
|
+
address,
|
|
1001
|
+
valid: isValid,
|
|
1002
|
+
});
|
|
1003
|
+
if (!isValid) {
|
|
1004
|
+
allValid = false;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
signatureValid = allValid;
|
|
1008
|
+
if (!signatureValid) {
|
|
1009
|
+
// 收集失败的地址
|
|
1010
|
+
const failedAddresses = signatures
|
|
1011
|
+
.filter((s) => !s.valid && s.address)
|
|
1012
|
+
.map((s) => s.address);
|
|
1013
|
+
return {
|
|
1014
|
+
valid: false,
|
|
1015
|
+
error: `Signatures from the following addresses are invalid: ${failedAddresses.join(", ")}`,
|
|
1016
|
+
hashValid: true,
|
|
1017
|
+
signatureValid: false,
|
|
1018
|
+
hasSignature: true,
|
|
1019
|
+
signatures,
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
return {
|
|
1024
|
+
valid: true,
|
|
1025
|
+
hashValid: true,
|
|
1026
|
+
signatureValid,
|
|
1027
|
+
hasSignature: !!wipFile.meta.signature,
|
|
1028
|
+
signatures: signatures.length > 0 ? signatures : undefined,
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* 对 WIP 文件进行签名
|
|
1033
|
+
*
|
|
1034
|
+
* 该函数会加载 WIP 文件、验证格式、使用 Account 添加数字签名并保存。
|
|
1035
|
+
* 支持多签名,如果文件已有签名,新签名会追加到签名列表中。
|
|
1036
|
+
*
|
|
1037
|
+
* @param wipFilePath WIP 文件路径
|
|
1038
|
+
* @param account 签名账号(账户名或地址)
|
|
1039
|
+
* @param outputPath 输出文件路径(可选,默认覆盖原文件)
|
|
1040
|
+
* @returns 签名后的 WIP 文件路径
|
|
1041
|
+
*/
|
|
1042
|
+
async function sign_wip(wipFilePath, account, outputPath) {
|
|
1043
|
+
const wip = new WIP();
|
|
1044
|
+
// 1. 加载 WIP 文件
|
|
1045
|
+
const wipFile = await wip.load(wipFilePath);
|
|
1046
|
+
// 2. 验证基本结构
|
|
1047
|
+
if (!wipFile.wip || !wipFile.payload || !wipFile.meta) {
|
|
1048
|
+
throw new WipValidationError("Invalid WIP file structure");
|
|
1049
|
+
}
|
|
1050
|
+
if (wipFile.meta.type !== "wip") {
|
|
1051
|
+
throw new WipValidationError(`Invalid meta.type: ${wipFile.meta.type}`);
|
|
1052
|
+
}
|
|
1053
|
+
// 3. 获取签名者地址
|
|
639
1054
|
const { Account } = await import("./account.js");
|
|
640
|
-
const address = await Account.Instance().get_address(
|
|
1055
|
+
const address = await Account.Instance().get_address(account);
|
|
641
1056
|
if (!address) {
|
|
642
|
-
|
|
643
|
-
`Account not found: ${options.account}`
|
|
644
|
-
);
|
|
645
|
-
}
|
|
646
|
-
const signature = await Account.Instance().sign(
|
|
647
|
-
address,
|
|
648
|
-
wipFile.meta.hash
|
|
649
|
-
);
|
|
650
|
-
const accountData = await Account.Instance().get(address);
|
|
651
|
-
if (!accountData || !accountData.pubkey) {
|
|
652
|
-
throw new WipValidationError(
|
|
653
|
-
`Cannot get public key for account: ${address}`
|
|
654
|
-
);
|
|
1057
|
+
throw new WipValidationError(`Account not found: ${account}`);
|
|
655
1058
|
}
|
|
1059
|
+
// 4. 使用 Account 签名(同时获取公钥)
|
|
1060
|
+
const signResult = await Account.Instance().signData(address, wipFile.meta.hash);
|
|
1061
|
+
// 5. 转换公钥格式为 base64 (32字节)
|
|
656
1062
|
let publicKeyBase64;
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
1063
|
+
const pk = signResult.publicKey;
|
|
1064
|
+
if (pk.startsWith("0x")) {
|
|
1065
|
+
const buffer = Buffer.from(pk.slice(2), "hex");
|
|
1066
|
+
if (buffer.length === 33) {
|
|
1067
|
+
publicKeyBase64 = buffer.slice(1).toString("base64");
|
|
1068
|
+
}
|
|
1069
|
+
else if (buffer.length === 32) {
|
|
1070
|
+
publicKeyBase64 = buffer.toString("base64");
|
|
1071
|
+
}
|
|
1072
|
+
else {
|
|
1073
|
+
throw new WipValidationError(`Invalid public key length: ${buffer.length}, expected 32 or 33 bytes`);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
else {
|
|
1077
|
+
publicKeyBase64 = pk;
|
|
1078
|
+
}
|
|
1079
|
+
// 6. 构建新签名
|
|
674
1080
|
const newSignature = {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
1081
|
+
value: Buffer.from(signResult.signature.slice(2), "hex").toString("base64"),
|
|
1082
|
+
publicKey: publicKeyBase64,
|
|
1083
|
+
algorithm: "Ed25519",
|
|
1084
|
+
address: signResult.address,
|
|
679
1085
|
};
|
|
1086
|
+
// 7. 处理多签名:相同公钥只能有一个签名(替换已有签名)
|
|
680
1087
|
let signatures;
|
|
681
1088
|
if (wipFile.meta.signature) {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
if (!wipFile.wip || !wipFile.payload || !wipFile.meta) {
|
|
711
|
-
return {
|
|
712
|
-
valid: false,
|
|
713
|
-
error: "Invalid WIP file structure",
|
|
714
|
-
hashValid: false,
|
|
715
|
-
hasSignature: false
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
if (wipFile.meta.type !== "wip") {
|
|
719
|
-
return {
|
|
720
|
-
valid: false,
|
|
721
|
-
error: `Invalid meta.type: ${wipFile.meta.type}`,
|
|
722
|
-
hashValid: false,
|
|
723
|
-
hasSignature: !!wipFile.meta.signature
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
if (hash_equal !== void 0 && wipFile.meta.hash.toLowerCase() !== hash_equal.toLowerCase()) {
|
|
727
|
-
return {
|
|
728
|
-
valid: false,
|
|
729
|
-
error: "Hash mismatch",
|
|
730
|
-
hashValid: false,
|
|
731
|
-
hasSignature: !!wipFile.meta.signature
|
|
732
|
-
};
|
|
733
|
-
}
|
|
734
|
-
const canonicalPayload = canonicalizeJson(wipFile.payload);
|
|
735
|
-
const computedHash = computeHash(canonicalPayload);
|
|
736
|
-
const hashValid = computedHash === wipFile.meta.hash;
|
|
737
|
-
if (!hashValid) {
|
|
738
|
-
return {
|
|
739
|
-
valid: false,
|
|
740
|
-
error: "Hash mismatch - content has been tampered",
|
|
741
|
-
hashValid: false,
|
|
742
|
-
hasSignature: !!wipFile.meta.signature
|
|
1089
|
+
// 将已有签名转换为数组
|
|
1090
|
+
const existingSigs = Array.isArray(wipFile.meta.signature)
|
|
1091
|
+
? [...wipFile.meta.signature]
|
|
1092
|
+
: [wipFile.meta.signature];
|
|
1093
|
+
// 检查是否已存在相同公钥的签名
|
|
1094
|
+
const existingIndex = existingSigs.findIndex((sig) => sig.publicKey === publicKeyBase64);
|
|
1095
|
+
if (existingIndex >= 0) {
|
|
1096
|
+
// 替换已有签名
|
|
1097
|
+
existingSigs[existingIndex] = newSignature;
|
|
1098
|
+
signatures = existingSigs;
|
|
1099
|
+
}
|
|
1100
|
+
else {
|
|
1101
|
+
// 追加新签名
|
|
1102
|
+
signatures = [...existingSigs, newSignature];
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
else {
|
|
1106
|
+
signatures = [newSignature];
|
|
1107
|
+
}
|
|
1108
|
+
// 8. 添加签名到 meta
|
|
1109
|
+
const signedWipFile = {
|
|
1110
|
+
...wipFile,
|
|
1111
|
+
meta: {
|
|
1112
|
+
...wipFile.meta,
|
|
1113
|
+
signature: signatures,
|
|
1114
|
+
},
|
|
743
1115
|
};
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
try {
|
|
759
|
-
const { Ed25519PublicKey } = await import("../../keypairs/ed25519/publickey.js");
|
|
760
|
-
const pubKey = new Ed25519PublicKey(sig.publicKey);
|
|
761
|
-
address = pubKey.toWAddress();
|
|
762
|
-
} catch {
|
|
763
|
-
}
|
|
764
|
-
signatures.push({
|
|
765
|
-
publicKey: sig.publicKey,
|
|
766
|
-
address,
|
|
767
|
-
valid: isValid
|
|
768
|
-
});
|
|
769
|
-
if (!isValid) {
|
|
770
|
-
allValid = false;
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
signatureValid = allValid;
|
|
774
|
-
if (!signatureValid) {
|
|
775
|
-
const failedAddresses = signatures.filter((s) => !s.valid && s.address).map((s) => s.address);
|
|
776
|
-
return {
|
|
777
|
-
valid: false,
|
|
778
|
-
error: `Signatures from the following addresses are invalid: ${failedAddresses.join(", ")}`,
|
|
779
|
-
hashValid: true,
|
|
780
|
-
signatureValid: false,
|
|
781
|
-
hasSignature: true,
|
|
782
|
-
signatures
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
return {
|
|
787
|
-
valid: true,
|
|
788
|
-
hashValid: true,
|
|
789
|
-
signatureValid,
|
|
790
|
-
hasSignature: !!wipFile.meta.signature,
|
|
791
|
-
signatures: signatures.length > 0 ? signatures : void 0
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
async function sign_wip(wipFilePath, account, outputPath) {
|
|
795
|
-
const wip = new WIP();
|
|
796
|
-
const wipFile = await wip.load(wipFilePath);
|
|
797
|
-
if (!wipFile.wip || !wipFile.payload || !wipFile.meta) {
|
|
798
|
-
throw new WipValidationError("Invalid WIP file structure");
|
|
799
|
-
}
|
|
800
|
-
if (wipFile.meta.type !== "wip") {
|
|
801
|
-
throw new WipValidationError(`Invalid meta.type: ${wipFile.meta.type}`);
|
|
802
|
-
}
|
|
803
|
-
const { Account } = await import("./account.js");
|
|
804
|
-
const address = await Account.Instance().get_address(account);
|
|
805
|
-
if (!address) {
|
|
806
|
-
throw new WipValidationError(`Account not found: ${account}`);
|
|
807
|
-
}
|
|
808
|
-
const signResult = await Account.Instance().signData(
|
|
809
|
-
address,
|
|
810
|
-
wipFile.meta.hash
|
|
811
|
-
);
|
|
812
|
-
let publicKeyBase64;
|
|
813
|
-
const pk = signResult.publicKey;
|
|
814
|
-
if (pk.startsWith("0x")) {
|
|
815
|
-
const buffer = Buffer.from(pk.slice(2), "hex");
|
|
816
|
-
if (buffer.length === 33) {
|
|
817
|
-
publicKeyBase64 = buffer.slice(1).toString("base64");
|
|
818
|
-
} else if (buffer.length === 32) {
|
|
819
|
-
publicKeyBase64 = buffer.toString("base64");
|
|
820
|
-
} else {
|
|
821
|
-
throw new WipValidationError(
|
|
822
|
-
`Invalid public key length: ${buffer.length}, expected 32 or 33 bytes`
|
|
823
|
-
);
|
|
824
|
-
}
|
|
825
|
-
} else {
|
|
826
|
-
publicKeyBase64 = pk;
|
|
827
|
-
}
|
|
828
|
-
const newSignature = {
|
|
829
|
-
value: Buffer.from(signResult.signature.slice(2), "hex").toString(
|
|
830
|
-
"base64"
|
|
831
|
-
),
|
|
832
|
-
publicKey: publicKeyBase64,
|
|
833
|
-
algorithm: "Ed25519",
|
|
834
|
-
address: signResult.address
|
|
835
|
-
};
|
|
836
|
-
let signatures;
|
|
837
|
-
if (wipFile.meta.signature) {
|
|
838
|
-
const existingSigs = Array.isArray(wipFile.meta.signature) ? [...wipFile.meta.signature] : [wipFile.meta.signature];
|
|
839
|
-
const existingIndex = existingSigs.findIndex(
|
|
840
|
-
(sig) => sig.publicKey === publicKeyBase64
|
|
841
|
-
);
|
|
842
|
-
if (existingIndex >= 0) {
|
|
843
|
-
existingSigs[existingIndex] = newSignature;
|
|
844
|
-
signatures = existingSigs;
|
|
845
|
-
} else {
|
|
846
|
-
signatures = [...existingSigs, newSignature];
|
|
847
|
-
}
|
|
848
|
-
} else {
|
|
849
|
-
signatures = [newSignature];
|
|
850
|
-
}
|
|
851
|
-
const signedWipFile = {
|
|
852
|
-
...wipFile,
|
|
853
|
-
meta: {
|
|
854
|
-
...wipFile.meta,
|
|
855
|
-
signature: signatures
|
|
856
|
-
}
|
|
857
|
-
};
|
|
858
|
-
let savePath;
|
|
859
|
-
if (outputPath) {
|
|
860
|
-
savePath = outputPath;
|
|
861
|
-
} else {
|
|
862
|
-
const dir = path.dirname(wipFilePath);
|
|
863
|
-
const ext = path.extname(wipFilePath);
|
|
864
|
-
const baseName = path.basename(wipFilePath, ext);
|
|
865
|
-
savePath = path.join(dir, `signed_${baseName}${ext}`);
|
|
866
|
-
}
|
|
867
|
-
wip.save(signedWipFile, savePath, true);
|
|
868
|
-
return savePath;
|
|
1116
|
+
// 10. 确定保存路径
|
|
1117
|
+
let savePath;
|
|
1118
|
+
if (outputPath) {
|
|
1119
|
+
savePath = outputPath;
|
|
1120
|
+
}
|
|
1121
|
+
else {
|
|
1122
|
+
// 在原文件名前添加 signed_ 前缀
|
|
1123
|
+
const dir = path.dirname(wipFilePath);
|
|
1124
|
+
const ext = path.extname(wipFilePath);
|
|
1125
|
+
const baseName = path.basename(wipFilePath, ext);
|
|
1126
|
+
savePath = path.join(dir, `signed_${baseName}${ext}`);
|
|
1127
|
+
}
|
|
1128
|
+
wip.save(signedWipFile, savePath, true);
|
|
1129
|
+
return savePath;
|
|
869
1130
|
}
|
|
1131
|
+
/**
|
|
1132
|
+
* 将 WIP 文件或文件夹转换为 HTML
|
|
1133
|
+
*
|
|
1134
|
+
* @param wipPath WIP 文件路径或文件夹路径
|
|
1135
|
+
* @param options 转换选项(支持 outputPath 直接保存到文件)
|
|
1136
|
+
* @returns HTML 字符串、保存的文件路径,或转换的文件路径数组
|
|
1137
|
+
*/
|
|
870
1138
|
async function wip2html(wipPath, options = {}) {
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
if (
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1139
|
+
const fs = await import("fs");
|
|
1140
|
+
const path = await import("path");
|
|
1141
|
+
// 检查是文件还是文件夹
|
|
1142
|
+
const stats = fs.statSync(wipPath);
|
|
1143
|
+
if (stats.isFile()) {
|
|
1144
|
+
// 处理单个文件
|
|
1145
|
+
const wip = new WIP();
|
|
1146
|
+
const wipFile = await wip.load(wipPath);
|
|
1147
|
+
const html = await wip.toHtml(wipFile, options);
|
|
1148
|
+
if (options.outputPath) {
|
|
1149
|
+
fs.writeFileSync(options.outputPath, html);
|
|
1150
|
+
return options.outputPath;
|
|
1151
|
+
}
|
|
1152
|
+
return html;
|
|
1153
|
+
}
|
|
1154
|
+
else if (stats.isDirectory()) {
|
|
1155
|
+
// 处理文件夹中的所有 .wip 文件
|
|
1156
|
+
const files = fs.readdirSync(wipPath);
|
|
1157
|
+
const wipFiles = files.filter((f) => f.endsWith(".wip"));
|
|
1158
|
+
if (wipFiles.length === 0) {
|
|
1159
|
+
throw new WipValidationError(`No .wip files found in directory: ${wipPath}`);
|
|
1160
|
+
}
|
|
1161
|
+
const results = [];
|
|
1162
|
+
const wip = new WIP();
|
|
1163
|
+
for (const file of wipFiles) {
|
|
1164
|
+
const filePath = path.join(wipPath, file);
|
|
1165
|
+
const wipFile = await wip.load(filePath);
|
|
1166
|
+
const html = await wip.toHtml(wipFile, options);
|
|
1167
|
+
// 生成输出文件名
|
|
1168
|
+
const outputFileName = file.replace(".wip", ".html");
|
|
1169
|
+
const outputFilePath = options.outputPath
|
|
1170
|
+
? path.join(options.outputPath, outputFileName)
|
|
1171
|
+
: path.join(wipPath, outputFileName);
|
|
1172
|
+
// 确保输出目录存在
|
|
1173
|
+
const outputDir = path.dirname(outputFilePath);
|
|
1174
|
+
if (!fs.existsSync(outputDir)) {
|
|
1175
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
1176
|
+
}
|
|
1177
|
+
fs.writeFileSync(outputFilePath, html);
|
|
1178
|
+
results.push(outputFilePath);
|
|
1179
|
+
}
|
|
1180
|
+
return results;
|
|
1181
|
+
}
|
|
1182
|
+
else {
|
|
1183
|
+
throw new WipValidationError(`Invalid path: ${wipPath}`);
|
|
1184
|
+
}
|
|
910
1185
|
}
|
|
911
|
-
|
|
1186
|
+
exports.default = WIP;
|
|
1187
|
+
//# sourceMappingURL=wip.js.map
|