@unconfirmed/effect-sui 0.0.0-stage → 0.1.1
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/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/Address.d.ts +18 -0
- package/dist/Address.d.ts.map +1 -0
- package/dist/Address.js +33 -0
- package/dist/Address.js.map +1 -0
- package/dist/AddressAlias.d.ts +107 -0
- package/dist/AddressAlias.d.ts.map +1 -0
- package/dist/AddressAlias.js +104 -0
- package/dist/AddressAlias.js.map +1 -0
- package/dist/Bip32.d.ts +6 -0
- package/dist/Bip32.d.ts.map +1 -0
- package/dist/Bip32.js +34 -0
- package/dist/Bip32.js.map +1 -0
- package/dist/Chain.d.ts +23 -0
- package/dist/Chain.d.ts.map +1 -0
- package/dist/Chain.js +7 -0
- package/dist/Chain.js.map +1 -0
- package/dist/CheckpointData.d.ts +74 -0
- package/dist/CheckpointData.d.ts.map +1 -0
- package/dist/CheckpointData.js +48 -0
- package/dist/CheckpointData.js.map +1 -0
- package/dist/Checkpoints.d.ts +23 -0
- package/dist/Checkpoints.d.ts.map +1 -0
- package/dist/Checkpoints.js +7 -0
- package/dist/Checkpoints.js.map +1 -0
- package/dist/CoinReservation.d.ts +18 -0
- package/dist/CoinReservation.d.ts.map +1 -0
- package/dist/CoinReservation.js +58 -0
- package/dist/CoinReservation.js.map +1 -0
- package/dist/Coins.d.ts +42 -0
- package/dist/Coins.d.ts.map +1 -0
- package/dist/Coins.js +49 -0
- package/dist/Coins.js.map +1 -0
- package/dist/DynamicFields.d.ts +115 -0
- package/dist/DynamicFields.d.ts.map +1 -0
- package/dist/DynamicFields.js +101 -0
- package/dist/DynamicFields.js.map +1 -0
- package/dist/Ecdsa.d.ts +39 -0
- package/dist/Ecdsa.d.ts.map +1 -0
- package/dist/Ecdsa.js +76 -0
- package/dist/Ecdsa.js.map +1 -0
- package/dist/Ed25519.d.ts +22 -0
- package/dist/Ed25519.d.ts.map +1 -0
- package/dist/Ed25519.js +77 -0
- package/dist/Ed25519.js.map +1 -0
- package/dist/Events.d.ts +105 -0
- package/dist/Events.d.ts.map +1 -0
- package/dist/Events.js +51 -0
- package/dist/Events.js.map +1 -0
- package/dist/Hash.d.ts +16 -0
- package/dist/Hash.d.ts.map +1 -0
- package/dist/Hash.js +32 -0
- package/dist/Hash.js.map +1 -0
- package/dist/MlDsa65.d.ts +17 -0
- package/dist/MlDsa65.d.ts.map +1 -0
- package/dist/MlDsa65.js +84 -0
- package/dist/MlDsa65.js.map +1 -0
- package/dist/Mnemonic.d.ts +20 -0
- package/dist/Mnemonic.d.ts.map +1 -0
- package/dist/Mnemonic.js +71 -0
- package/dist/Mnemonic.js.map +1 -0
- package/dist/Move.d.ts +261 -0
- package/dist/Move.d.ts.map +1 -0
- package/dist/Move.js +232 -0
- package/dist/Move.js.map +1 -0
- package/dist/MultiSig.d.ts +106 -0
- package/dist/MultiSig.d.ts.map +1 -0
- package/dist/MultiSig.js +254 -0
- package/dist/MultiSig.js.map +1 -0
- package/dist/Objects.d.ts +95 -0
- package/dist/Objects.d.ts.map +1 -0
- package/dist/Objects.js +57 -0
- package/dist/Objects.js.map +1 -0
- package/dist/Packages.d.ts +49 -0
- package/dist/Packages.d.ts.map +1 -0
- package/dist/Packages.js +16 -0
- package/dist/Packages.js.map +1 -0
- package/dist/Passkey.d.ts +11 -0
- package/dist/Passkey.d.ts.map +1 -0
- package/dist/Passkey.js +11 -0
- package/dist/Passkey.js.map +1 -0
- package/dist/PrivateKey.d.ts +39 -0
- package/dist/PrivateKey.d.ts.map +1 -0
- package/dist/PrivateKey.js +118 -0
- package/dist/PrivateKey.js.map +1 -0
- package/dist/Ptb.d.ts +413 -0
- package/dist/Ptb.d.ts.map +1 -0
- package/dist/Ptb.js +338 -0
- package/dist/Ptb.js.map +1 -0
- package/dist/Resolve.d.ts +502 -0
- package/dist/Resolve.d.ts.map +1 -0
- package/dist/Resolve.js +1188 -0
- package/dist/Resolve.js.map +1 -0
- package/dist/RpcError.d.ts +19 -0
- package/dist/RpcError.d.ts.map +1 -0
- package/dist/RpcError.js +37 -0
- package/dist/RpcError.js.map +1 -0
- package/dist/Secp256k1.d.ts +11 -0
- package/dist/Secp256k1.d.ts.map +1 -0
- package/dist/Secp256k1.js +23 -0
- package/dist/Secp256k1.js.map +1 -0
- package/dist/Secp256r1.d.ts +11 -0
- package/dist/Secp256r1.d.ts.map +1 -0
- package/dist/Secp256r1.js +23 -0
- package/dist/Secp256r1.js.map +1 -0
- package/dist/SignatureScheme.d.ts +103 -0
- package/dist/SignatureScheme.d.ts.map +1 -0
- package/dist/SignatureScheme.js +93 -0
- package/dist/SignatureScheme.js.map +1 -0
- package/dist/Signer.d.ts +54 -0
- package/dist/Signer.d.ts.map +1 -0
- package/dist/Signer.js +31 -0
- package/dist/Signer.js.map +1 -0
- package/dist/Testing.d.ts +171 -0
- package/dist/Testing.d.ts.map +1 -0
- package/dist/Testing.js +531 -0
- package/dist/Testing.js.map +1 -0
- package/dist/TransactionData.d.ts +3218 -0
- package/dist/TransactionData.d.ts.map +1 -0
- package/dist/TransactionData.js +105 -0
- package/dist/TransactionData.js.map +1 -0
- package/dist/TransactionJson.d.ts +1544 -0
- package/dist/TransactionJson.d.ts.map +1 -0
- package/dist/TransactionJson.js +926 -0
- package/dist/TransactionJson.js.map +1 -0
- package/dist/Transactions.d.ts +181 -0
- package/dist/Transactions.d.ts.map +1 -0
- package/dist/Transactions.js +49 -0
- package/dist/Transactions.js.map +1 -0
- package/dist/Tx.d.ts +1419 -0
- package/dist/Tx.d.ts.map +1 -0
- package/dist/Tx.js +266 -0
- package/dist/Tx.js.map +1 -0
- package/dist/TypeTag.d.ts +42 -0
- package/dist/TypeTag.d.ts.map +1 -0
- package/dist/TypeTag.js +110 -0
- package/dist/TypeTag.js.map +1 -0
- package/dist/Verify.d.ts +23 -0
- package/dist/Verify.d.ts.map +1 -0
- package/dist/Verify.js +29 -0
- package/dist/Verify.js.map +1 -0
- package/dist/enoki/EnokiClient.d.ts +184 -0
- package/dist/enoki/EnokiClient.d.ts.map +1 -0
- package/dist/enoki/EnokiClient.js +105 -0
- package/dist/enoki/EnokiClient.js.map +1 -0
- package/dist/enoki/EnokiHttp.d.ts +33 -0
- package/dist/enoki/EnokiHttp.d.ts.map +1 -0
- package/dist/enoki/EnokiHttp.js +160 -0
- package/dist/enoki/EnokiHttp.js.map +1 -0
- package/dist/enoki/Sponsor.d.ts +119 -0
- package/dist/enoki/Sponsor.d.ts.map +1 -0
- package/dist/enoki/Sponsor.js +170 -0
- package/dist/enoki/Sponsor.js.map +1 -0
- package/dist/enoki/ZkLoginFlow.d.ts +84 -0
- package/dist/enoki/ZkLoginFlow.d.ts.map +1 -0
- package/dist/enoki/ZkLoginFlow.js +138 -0
- package/dist/enoki/ZkLoginFlow.js.map +1 -0
- package/dist/enoki/index.d.ts +9 -0
- package/dist/enoki/index.d.ts.map +1 -0
- package/dist/enoki/index.js +9 -0
- package/dist/enoki/index.js.map +1 -0
- package/dist/graphql/ChainGraphQL.d.ts +35 -0
- package/dist/graphql/ChainGraphQL.d.ts.map +1 -0
- package/dist/graphql/ChainGraphQL.js +62 -0
- package/dist/graphql/ChainGraphQL.js.map +1 -0
- package/dist/graphql/CheckpointDataGraphQL.d.ts +785 -0
- package/dist/graphql/CheckpointDataGraphQL.d.ts.map +1 -0
- package/dist/graphql/CheckpointDataGraphQL.js +157 -0
- package/dist/graphql/CheckpointDataGraphQL.js.map +1 -0
- package/dist/graphql/CheckpointsGraphQL.d.ts +91 -0
- package/dist/graphql/CheckpointsGraphQL.d.ts.map +1 -0
- package/dist/graphql/CheckpointsGraphQL.js +80 -0
- package/dist/graphql/CheckpointsGraphQL.js.map +1 -0
- package/dist/graphql/CoinsGraphQL.d.ts +81 -0
- package/dist/graphql/CoinsGraphQL.d.ts.map +1 -0
- package/dist/graphql/CoinsGraphQL.js +63 -0
- package/dist/graphql/CoinsGraphQL.js.map +1 -0
- package/dist/graphql/DynamicFieldsGraphQL.d.ts +94 -0
- package/dist/graphql/DynamicFieldsGraphQL.d.ts.map +1 -0
- package/dist/graphql/DynamicFieldsGraphQL.js +126 -0
- package/dist/graphql/DynamicFieldsGraphQL.js.map +1 -0
- package/dist/graphql/EventsGraphQL.d.ts +266 -0
- package/dist/graphql/EventsGraphQL.d.ts.map +1 -0
- package/dist/graphql/EventsGraphQL.js +249 -0
- package/dist/graphql/EventsGraphQL.js.map +1 -0
- package/dist/graphql/ObjectsGraphQL.d.ts +130 -0
- package/dist/graphql/ObjectsGraphQL.d.ts.map +1 -0
- package/dist/graphql/ObjectsGraphQL.js +79 -0
- package/dist/graphql/ObjectsGraphQL.js.map +1 -0
- package/dist/graphql/PackagesGraphQL.d.ts +82 -0
- package/dist/graphql/PackagesGraphQL.d.ts.map +1 -0
- package/dist/graphql/PackagesGraphQL.js +145 -0
- package/dist/graphql/PackagesGraphQL.js.map +1 -0
- package/dist/graphql/SuiGraphQL.d.ts +37 -0
- package/dist/graphql/SuiGraphQL.d.ts.map +1 -0
- package/dist/graphql/SuiGraphQL.js +47 -0
- package/dist/graphql/SuiGraphQL.js.map +1 -0
- package/dist/graphql/TransactionsGraphQL.d.ts +1309 -0
- package/dist/graphql/TransactionsGraphQL.d.ts.map +1 -0
- package/dist/graphql/TransactionsGraphQL.js +206 -0
- package/dist/graphql/TransactionsGraphQL.js.map +1 -0
- package/dist/graphql/convert.d.ts +505 -0
- package/dist/graphql/convert.d.ts.map +1 -0
- package/dist/graphql/convert.js +384 -0
- package/dist/graphql/convert.js.map +1 -0
- package/dist/graphql/index.d.ts +41 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/index.js +20 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/graphql/merge.d.ts +8 -0
- package/dist/graphql/merge.d.ts.map +1 -0
- package/dist/graphql/merge.js +55 -0
- package/dist/graphql/merge.js.map +1 -0
- package/dist/graphql/paging.d.ts +219 -0
- package/dist/graphql/paging.d.ts.map +1 -0
- package/dist/graphql/paging.js +74 -0
- package/dist/graphql/paging.js.map +1 -0
- package/dist/graphql/subscription.d.ts +27 -0
- package/dist/graphql/subscription.d.ts.map +1 -0
- package/dist/graphql/subscription.js +47 -0
- package/dist/graphql/subscription.js.map +1 -0
- package/dist/graphql/tip.d.ts +31 -0
- package/dist/graphql/tip.d.ts.map +1 -0
- package/dist/graphql/tip.js +29 -0
- package/dist/graphql/tip.js.map +1 -0
- package/dist/grpc/ChainGrpc.d.ts +11 -0
- package/dist/grpc/ChainGrpc.d.ts.map +1 -0
- package/dist/grpc/ChainGrpc.js +40 -0
- package/dist/grpc/ChainGrpc.js.map +1 -0
- package/dist/grpc/CheckpointDataGrpc.d.ts +6 -0
- package/dist/grpc/CheckpointDataGrpc.d.ts.map +1 -0
- package/dist/grpc/CheckpointDataGrpc.js +27 -0
- package/dist/grpc/CheckpointDataGrpc.js.map +1 -0
- package/dist/grpc/CheckpointsGrpc.d.ts +6 -0
- package/dist/grpc/CheckpointsGrpc.d.ts.map +1 -0
- package/dist/grpc/CheckpointsGrpc.js +25 -0
- package/dist/grpc/CheckpointsGrpc.js.map +1 -0
- package/dist/grpc/CoinsGrpc.d.ts +7 -0
- package/dist/grpc/CoinsGrpc.d.ts.map +1 -0
- package/dist/grpc/CoinsGrpc.js +34 -0
- package/dist/grpc/CoinsGrpc.js.map +1 -0
- package/dist/grpc/DynamicFieldsGrpc.d.ts +11 -0
- package/dist/grpc/DynamicFieldsGrpc.d.ts.map +1 -0
- package/dist/grpc/DynamicFieldsGrpc.js +91 -0
- package/dist/grpc/DynamicFieldsGrpc.js.map +1 -0
- package/dist/grpc/EventsGrpc.d.ts +13 -0
- package/dist/grpc/EventsGrpc.d.ts.map +1 -0
- package/dist/grpc/EventsGrpc.js +88 -0
- package/dist/grpc/EventsGrpc.js.map +1 -0
- package/dist/grpc/GrpcWeb.d.ts +71 -0
- package/dist/grpc/GrpcWeb.d.ts.map +1 -0
- package/dist/grpc/GrpcWeb.js +243 -0
- package/dist/grpc/GrpcWeb.js.map +1 -0
- package/dist/grpc/ObjectsGrpc.d.ts +10 -0
- package/dist/grpc/ObjectsGrpc.d.ts.map +1 -0
- package/dist/grpc/ObjectsGrpc.js +72 -0
- package/dist/grpc/ObjectsGrpc.js.map +1 -0
- package/dist/grpc/PackagesGrpc.d.ts +9 -0
- package/dist/grpc/PackagesGrpc.d.ts.map +1 -0
- package/dist/grpc/PackagesGrpc.js +78 -0
- package/dist/grpc/PackagesGrpc.js.map +1 -0
- package/dist/grpc/Rpc.d.ts +46 -0
- package/dist/grpc/Rpc.d.ts.map +1 -0
- package/dist/grpc/Rpc.js +111 -0
- package/dist/grpc/Rpc.js.map +1 -0
- package/dist/grpc/TransactionsGrpc.d.ts +6 -0
- package/dist/grpc/TransactionsGrpc.d.ts.map +1 -0
- package/dist/grpc/TransactionsGrpc.js +56 -0
- package/dist/grpc/TransactionsGrpc.js.map +1 -0
- package/dist/grpc/cache.d.ts +7 -0
- package/dist/grpc/cache.d.ts.map +1 -0
- package/dist/grpc/cache.js +55 -0
- package/dist/grpc/cache.js.map +1 -0
- package/dist/grpc/convert.d.ts +43 -0
- package/dist/grpc/convert.d.ts.map +1 -0
- package/dist/grpc/convert.js +198 -0
- package/dist/grpc/convert.js.map +1 -0
- package/dist/grpc/generated/lean.d.ts +36 -0
- package/dist/grpc/generated/lean.d.ts.map +1 -0
- package/dist/grpc/generated/lean.js +205 -0
- package/dist/grpc/generated/lean.js.map +1 -0
- package/dist/grpc/generated/proto.d.ts +2000 -0
- package/dist/grpc/generated/proto.d.ts.map +1 -0
- package/dist/grpc/generated/proto.js +356 -0
- package/dist/grpc/generated/proto.js.map +1 -0
- package/dist/grpc/generated/rpc.d.ts +62 -0
- package/dist/grpc/generated/rpc.d.ts.map +1 -0
- package/dist/grpc/generated/rpc.js +324 -0
- package/dist/grpc/generated/rpc.js.map +1 -0
- package/dist/grpc/index.d.ts +58 -0
- package/dist/grpc/index.d.ts.map +1 -0
- package/dist/grpc/index.js +43 -0
- package/dist/grpc/index.js.map +1 -0
- package/dist/grpc/scan.d.ts +79 -0
- package/dist/grpc/scan.d.ts.map +1 -0
- package/dist/grpc/scan.js +126 -0
- package/dist/grpc/scan.js.map +1 -0
- package/dist/grpc/transaction.d.ts +9 -0
- package/dist/grpc/transaction.d.ts.map +1 -0
- package/dist/grpc/transaction.js +168 -0
- package/dist/grpc/transaction.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/allowances.d.ts +18 -0
- package/dist/internal/allowances.d.ts.map +1 -0
- package/dist/internal/allowances.js +194 -0
- package/dist/internal/allowances.js.map +1 -0
- package/dist/internal/mnemonic.d.ts +53 -0
- package/dist/internal/mnemonic.d.ts.map +1 -0
- package/dist/internal/mnemonic.js +66 -0
- package/dist/internal/mnemonic.js.map +1 -0
- package/dist/internal/passkey/BrowserProvider.d.ts +10 -0
- package/dist/internal/passkey/BrowserProvider.d.ts.map +1 -0
- package/dist/internal/passkey/BrowserProvider.js +101 -0
- package/dist/internal/passkey/BrowserProvider.js.map +1 -0
- package/dist/internal/passkey/Passkey.d.ts +104 -0
- package/dist/internal/passkey/Passkey.d.ts.map +1 -0
- package/dist/internal/passkey/Passkey.js +333 -0
- package/dist/internal/passkey/Passkey.js.map +1 -0
- package/dist/internal/passkey/SoftwareProvider.d.ts +23 -0
- package/dist/internal/passkey/SoftwareProvider.d.ts.map +1 -0
- package/dist/internal/passkey/SoftwareProvider.js +61 -0
- package/dist/internal/passkey/SoftwareProvider.js.map +1 -0
- package/dist/lifecycle/Evidence.d.ts +62 -0
- package/dist/lifecycle/Evidence.d.ts.map +1 -0
- package/dist/lifecycle/Evidence.js +30 -0
- package/dist/lifecycle/Evidence.js.map +1 -0
- package/dist/lifecycle/EvidenceGraphQL.d.ts +59 -0
- package/dist/lifecycle/EvidenceGraphQL.d.ts.map +1 -0
- package/dist/lifecycle/EvidenceGraphQL.js +53 -0
- package/dist/lifecycle/EvidenceGraphQL.js.map +1 -0
- package/dist/lifecycle/EvidenceGrpc.d.ts +4 -0
- package/dist/lifecycle/EvidenceGrpc.d.ts.map +1 -0
- package/dist/lifecycle/EvidenceGrpc.js +37 -0
- package/dist/lifecycle/EvidenceGrpc.js.map +1 -0
- package/dist/lifecycle/Journal.d.ts +69 -0
- package/dist/lifecycle/Journal.d.ts.map +1 -0
- package/dist/lifecycle/Journal.js +70 -0
- package/dist/lifecycle/Journal.js.map +1 -0
- package/dist/lifecycle/JournalEntry.d.ts +67 -0
- package/dist/lifecycle/JournalEntry.d.ts.map +1 -0
- package/dist/lifecycle/JournalEntry.js +45 -0
- package/dist/lifecycle/JournalEntry.js.map +1 -0
- package/dist/lifecycle/JournalKeyValueStore.d.ts +30 -0
- package/dist/lifecycle/JournalKeyValueStore.d.ts.map +1 -0
- package/dist/lifecycle/JournalKeyValueStore.js +217 -0
- package/dist/lifecycle/JournalKeyValueStore.js.map +1 -0
- package/dist/lifecycle/KeyValueStoreIndexedDb.d.ts +54 -0
- package/dist/lifecycle/KeyValueStoreIndexedDb.d.ts.map +1 -0
- package/dist/lifecycle/KeyValueStoreIndexedDb.js +321 -0
- package/dist/lifecycle/KeyValueStoreIndexedDb.js.map +1 -0
- package/dist/lifecycle/KeyValueStoreOpfs.d.ts +65 -0
- package/dist/lifecycle/KeyValueStoreOpfs.d.ts.map +1 -0
- package/dist/lifecycle/KeyValueStoreOpfs.js +207 -0
- package/dist/lifecycle/KeyValueStoreOpfs.js.map +1 -0
- package/dist/lifecycle/Lifecycle.d.ts +416 -0
- package/dist/lifecycle/Lifecycle.d.ts.map +1 -0
- package/dist/lifecycle/Lifecycle.js +666 -0
- package/dist/lifecycle/Lifecycle.js.map +1 -0
- package/dist/lifecycle/Outcome.d.ts +132 -0
- package/dist/lifecycle/Outcome.d.ts.map +1 -0
- package/dist/lifecycle/Outcome.js +106 -0
- package/dist/lifecycle/Outcome.js.map +1 -0
- package/dist/lifecycle/SenderLock.d.ts +37 -0
- package/dist/lifecycle/SenderLock.d.ts.map +1 -0
- package/dist/lifecycle/SenderLock.js +57 -0
- package/dist/lifecycle/SenderLock.js.map +1 -0
- package/dist/lifecycle/SenderLockWebLocks.d.ts +37 -0
- package/dist/lifecycle/SenderLockWebLocks.d.ts.map +1 -0
- package/dist/lifecycle/SenderLockWebLocks.js +100 -0
- package/dist/lifecycle/SenderLockWebLocks.js.map +1 -0
- package/dist/lifecycle/SignedTransaction.d.ts +55 -0
- package/dist/lifecycle/SignedTransaction.d.ts.map +1 -0
- package/dist/lifecycle/SignedTransaction.js +109 -0
- package/dist/lifecycle/SignedTransaction.js.map +1 -0
- package/dist/lifecycle/SubmitConfig.d.ts +44 -0
- package/dist/lifecycle/SubmitConfig.d.ts.map +1 -0
- package/dist/lifecycle/SubmitConfig.js +39 -0
- package/dist/lifecycle/SubmitConfig.js.map +1 -0
- package/dist/lifecycle/index.d.ts +13 -0
- package/dist/lifecycle/index.d.ts.map +1 -0
- package/dist/lifecycle/index.js +13 -0
- package/dist/lifecycle/index.js.map +1 -0
- package/dist/wallet/Connection.d.ts +119 -0
- package/dist/wallet/Connection.d.ts.map +1 -0
- package/dist/wallet/Connection.js +197 -0
- package/dist/wallet/Connection.js.map +1 -0
- package/dist/wallet/Features.d.ts +91 -0
- package/dist/wallet/Features.d.ts.map +1 -0
- package/dist/wallet/Features.js +14 -0
- package/dist/wallet/Features.js.map +1 -0
- package/dist/wallet/Wallet.d.ts +151 -0
- package/dist/wallet/Wallet.d.ts.map +1 -0
- package/dist/wallet/Wallet.js +399 -0
- package/dist/wallet/Wallet.js.map +1 -0
- package/dist/wallet/index.d.ts +7 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +7 -0
- package/dist/wallet/index.js.map +1 -0
- package/dist/zklogin/AddressSeed.d.ts +40 -0
- package/dist/zklogin/AddressSeed.d.ts.map +1 -0
- package/dist/zklogin/AddressSeed.js +91 -0
- package/dist/zklogin/AddressSeed.js.map +1 -0
- package/dist/zklogin/Errors.d.ts +24 -0
- package/dist/zklogin/Errors.d.ts.map +1 -0
- package/dist/zklogin/Errors.js +25 -0
- package/dist/zklogin/Errors.js.map +1 -0
- package/dist/zklogin/Jwt.d.ts +51 -0
- package/dist/zklogin/Jwt.d.ts.map +1 -0
- package/dist/zklogin/Jwt.js +159 -0
- package/dist/zklogin/Jwt.js.map +1 -0
- package/dist/zklogin/Nonce.d.ts +9 -0
- package/dist/zklogin/Nonce.d.ts.map +1 -0
- package/dist/zklogin/Nonce.js +34 -0
- package/dist/zklogin/Nonce.js.map +1 -0
- package/dist/zklogin/Poseidon.d.ts +24 -0
- package/dist/zklogin/Poseidon.d.ts.map +1 -0
- package/dist/zklogin/Poseidon.js +54 -0
- package/dist/zklogin/Poseidon.js.map +1 -0
- package/dist/zklogin/PublicIdentifier.d.ts +49 -0
- package/dist/zklogin/PublicIdentifier.d.ts.map +1 -0
- package/dist/zklogin/PublicIdentifier.js +90 -0
- package/dist/zklogin/PublicIdentifier.js.map +1 -0
- package/dist/zklogin/Signature.d.ts +55 -0
- package/dist/zklogin/Signature.d.ts.map +1 -0
- package/dist/zklogin/Signature.js +70 -0
- package/dist/zklogin/Signature.js.map +1 -0
- package/dist/zklogin/ZkLogin.d.ts +41 -0
- package/dist/zklogin/ZkLogin.d.ts.map +1 -0
- package/dist/zklogin/ZkLogin.js +87 -0
- package/dist/zklogin/ZkLogin.js.map +1 -0
- package/dist/zklogin/ZkLoginAddress.d.ts +30 -0
- package/dist/zklogin/ZkLoginAddress.d.ts.map +1 -0
- package/dist/zklogin/ZkLoginAddress.js +31 -0
- package/dist/zklogin/ZkLoginAddress.js.map +1 -0
- package/dist/zklogin/ZkLoginVerifier.d.ts +37 -0
- package/dist/zklogin/ZkLoginVerifier.d.ts.map +1 -0
- package/dist/zklogin/ZkLoginVerifier.js +4 -0
- package/dist/zklogin/ZkLoginVerifier.js.map +1 -0
- package/dist/zklogin/ZkLoginVerifierGrpc.d.ts +12 -0
- package/dist/zklogin/ZkLoginVerifierGrpc.d.ts.map +1 -0
- package/dist/zklogin/ZkLoginVerifierGrpc.js +53 -0
- package/dist/zklogin/ZkLoginVerifierGrpc.js.map +1 -0
- package/dist/zklogin/index.d.ts +17 -0
- package/dist/zklogin/index.d.ts.map +1 -0
- package/dist/zklogin/index.js +17 -0
- package/dist/zklogin/index.js.map +1 -0
- package/dist/zklogin/internal/parse.d.ts +9 -0
- package/dist/zklogin/internal/parse.d.ts.map +1 -0
- package/dist/zklogin/internal/parse.js +33 -0
- package/dist/zklogin/internal/parse.js.map +1 -0
- package/dist/zklogin/internal/poseidon.d.ts +21 -0
- package/dist/zklogin/internal/poseidon.d.ts.map +1 -0
- package/dist/zklogin/internal/poseidon.js +40 -0
- package/dist/zklogin/internal/poseidon.js.map +1 -0
- package/package.json +69 -4
- package/src/Address.ts +45 -0
- package/src/AddressAlias.ts +160 -0
- package/src/Bip32.ts +37 -0
- package/src/Chain.ts +21 -0
- package/src/CheckpointData.ts +106 -0
- package/src/Checkpoints.ts +18 -0
- package/src/CoinReservation.ts +65 -0
- package/src/Coins.ts +86 -0
- package/src/DynamicFields.ts +179 -0
- package/src/Ecdsa.ts +103 -0
- package/src/Ed25519.ts +84 -0
- package/src/Events.ts +133 -0
- package/src/Hash.ts +39 -0
- package/src/MlDsa65.ts +92 -0
- package/src/Mnemonic.ts +109 -0
- package/src/Move.ts +440 -0
- package/src/MultiSig.ts +320 -0
- package/src/Objects.ts +112 -0
- package/src/Packages.ts +52 -0
- package/src/Passkey.ts +10 -0
- package/src/PrivateKey.ts +138 -0
- package/src/Ptb.ts +579 -0
- package/src/Resolve.ts +1367 -0
- package/src/RpcError.ts +41 -0
- package/src/Secp256k1.ts +29 -0
- package/src/Secp256r1.ts +29 -0
- package/src/SignatureScheme.ts +166 -0
- package/src/Signer.ts +62 -0
- package/src/Testing.ts +830 -0
- package/src/TransactionData.ts +134 -0
- package/src/TransactionJson.ts +1002 -0
- package/src/Transactions.ts +211 -0
- package/src/Tx.ts +367 -0
- package/src/TypeTag.ts +123 -0
- package/src/Verify.ts +42 -0
- package/src/enoki/EnokiClient.ts +204 -0
- package/src/enoki/EnokiHttp.ts +222 -0
- package/src/enoki/Sponsor.ts +280 -0
- package/src/enoki/ZkLoginFlow.ts +176 -0
- package/src/enoki/index.ts +8 -0
- package/src/graphql/ChainGraphQL.ts +76 -0
- package/src/graphql/CheckpointDataGraphQL.ts +191 -0
- package/src/graphql/CheckpointsGraphQL.ts +96 -0
- package/src/graphql/CoinsGraphQL.ts +85 -0
- package/src/graphql/DynamicFieldsGraphQL.ts +167 -0
- package/src/graphql/EventsGraphQL.ts +301 -0
- package/src/graphql/ObjectsGraphQL.ts +112 -0
- package/src/graphql/PackagesGraphQL.ts +173 -0
- package/src/graphql/SuiGraphQL.ts +77 -0
- package/src/graphql/TransactionsGraphQL.ts +292 -0
- package/src/graphql/convert.ts +450 -0
- package/src/graphql/index.ts +74 -0
- package/src/graphql/merge.ts +62 -0
- package/src/graphql/paging.ts +110 -0
- package/src/graphql/subscription.ts +58 -0
- package/src/graphql/tip.ts +38 -0
- package/src/grpc/ChainGrpc.ts +51 -0
- package/src/grpc/CheckpointDataGrpc.ts +47 -0
- package/src/grpc/CheckpointsGrpc.ts +37 -0
- package/src/grpc/CoinsGrpc.ts +50 -0
- package/src/grpc/DynamicFieldsGrpc.ts +128 -0
- package/src/grpc/EventsGrpc.ts +101 -0
- package/src/grpc/GrpcWeb.ts +343 -0
- package/src/grpc/ObjectsGrpc.ts +95 -0
- package/src/grpc/PackagesGrpc.ts +98 -0
- package/src/grpc/Rpc.ts +156 -0
- package/src/grpc/TransactionsGrpc.ts +88 -0
- package/src/grpc/cache.ts +68 -0
- package/src/grpc/convert.ts +227 -0
- package/src/grpc/generated/lean.ts +276 -0
- package/src/grpc/generated/proto.ts +2130 -0
- package/src/grpc/generated/rpc.ts +417 -0
- package/src/grpc/index.ts +97 -0
- package/src/grpc/scan.ts +183 -0
- package/src/grpc/transaction.ts +182 -0
- package/src/index.ts +35 -0
- package/src/internal/allowances.ts +238 -0
- package/src/internal/mnemonic.ts +99 -0
- package/src/internal/passkey/BrowserProvider.ts +131 -0
- package/src/internal/passkey/Passkey.ts +408 -0
- package/src/internal/passkey/SoftwareProvider.ts +90 -0
- package/src/lifecycle/Evidence.ts +85 -0
- package/src/lifecycle/EvidenceGraphQL.ts +67 -0
- package/src/lifecycle/EvidenceGrpc.ts +47 -0
- package/src/lifecycle/Journal.ts +117 -0
- package/src/lifecycle/JournalEntry.ts +68 -0
- package/src/lifecycle/JournalKeyValueStore.ts +276 -0
- package/src/lifecycle/KeyValueStoreIndexedDb.ts +361 -0
- package/src/lifecycle/KeyValueStoreOpfs.ts +230 -0
- package/src/lifecycle/Lifecycle.ts +990 -0
- package/src/lifecycle/Outcome.ts +130 -0
- package/src/lifecycle/SenderLock.ts +73 -0
- package/src/lifecycle/SenderLockWebLocks.ts +136 -0
- package/src/lifecycle/SignedTransaction.ts +133 -0
- package/src/lifecycle/SubmitConfig.ts +77 -0
- package/src/lifecycle/index.ts +12 -0
- package/src/wallet/Connection.ts +323 -0
- package/src/wallet/Features.ts +114 -0
- package/src/wallet/Wallet.ts +550 -0
- package/src/wallet/index.ts +6 -0
- package/src/zklogin/AddressSeed.ts +130 -0
- package/src/zklogin/Errors.ts +27 -0
- package/src/zklogin/Jwt.ts +186 -0
- package/src/zklogin/Nonce.ts +46 -0
- package/src/zklogin/Poseidon.ts +62 -0
- package/src/zklogin/PublicIdentifier.ts +111 -0
- package/src/zklogin/Signature.ts +88 -0
- package/src/zklogin/ZkLogin.ts +145 -0
- package/src/zklogin/ZkLoginAddress.ts +72 -0
- package/src/zklogin/ZkLoginVerifier.ts +37 -0
- package/src/zklogin/ZkLoginVerifierGrpc.ts +66 -0
- package/src/zklogin/index.ts +16 -0
- package/src/zklogin/internal/parse.ts +30 -0
- package/src/zklogin/internal/poseidon.ts +47 -0
package/src/Testing.ts
ADDED
|
@@ -0,0 +1,830 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An in-memory Sui node for tests: every capability service (Chain, Objects,
|
|
3
|
+
* Coins, Packages, Transactions, Checkpoints, DynamicFields, Events,
|
|
4
|
+
* CheckpointData) over state the test seeds, with a log of what was asked.
|
|
5
|
+
*
|
|
6
|
+
* const layer = Testing.layer({ objects: [{ objectId, type, contents }] })
|
|
7
|
+
* const node = yield* Testing.Node // seed and inspect mid-test
|
|
8
|
+
* yield* node.setAddressBalance({ owner, amount: 1_000_000_000n })
|
|
9
|
+
* const effects = yield* Tx.run(recipe, { signer, include: ["events"] })
|
|
10
|
+
* expect(yield* node.requests).toContainEqual({ method: "Objects.get", args: [id1, id2] })
|
|
11
|
+
*
|
|
12
|
+
* What it models, and what it doesn't:
|
|
13
|
+
*
|
|
14
|
+
* - `Objects.get` is batched as the transports batch it (concurrent gets, up
|
|
15
|
+
* to 50 a batch, one log entry per batch). `DynamicFields.get` / `getObject`
|
|
16
|
+
* read through the same batches. The batch window is one scheduler yield,
|
|
17
|
+
* not a timer, so it works under `TestClock`.
|
|
18
|
+
* - Transactions are not executed. Simulating or executing one asks the
|
|
19
|
+
* responder (`respond`), which answers the outcome (status, gas, changed
|
|
20
|
+
* objects, events, balance changes, return values; default: success, no gas,
|
|
21
|
+
* nothing changed). State changes only through the `Node` handle, which a
|
|
22
|
+
* responder may call. Signatures are not checked.
|
|
23
|
+
* - Each executed transaction (and each `putTransaction`) lands in a
|
|
24
|
+
* checkpoint of its own, at the current clock, so `Transactions.get` /
|
|
25
|
+
* `waitFor`, `Events`, `Checkpoints` and `CheckpointData` see it.
|
|
26
|
+
* - `Transactions.resolve` is not provided, so `Tx.build` / `Tx.run` resolve
|
|
27
|
+
* client-side: object inputs from `Objects`, Move signatures from
|
|
28
|
+
* `putPackage({ functions })`, gas from `Coins` (fund the sender first).
|
|
29
|
+
* - Unsupported or unseeded things fail typed: an unseeded Move function is
|
|
30
|
+
* `RpcError` `NOT_FOUND`, a `StreamHead` event filter `UNIMPLEMENTED`,
|
|
31
|
+
* transaction bytes that don't decode `INVALID_ARGUMENT`.
|
|
32
|
+
*
|
|
33
|
+
* Not in the `@unconfirmed/effect-sui` barrel: import `@unconfirmed/effect-sui/Testing`.
|
|
34
|
+
*/
|
|
35
|
+
import { base58 } from "@scure/base"
|
|
36
|
+
import * as Bcs from "@unconfirmed/effect-bcs/Bcs"
|
|
37
|
+
import * as Context from "effect/Context"
|
|
38
|
+
import * as Effect from "effect/Effect"
|
|
39
|
+
import * as Exit from "effect/Exit"
|
|
40
|
+
import * as Layer from "effect/Layer"
|
|
41
|
+
import * as PubSub from "effect/PubSub"
|
|
42
|
+
import * as EffectRequest from "effect/Request"
|
|
43
|
+
import * as RequestResolver from "effect/RequestResolver"
|
|
44
|
+
import * as Result from "effect/Result"
|
|
45
|
+
import * as Stream from "effect/Stream"
|
|
46
|
+
import * as Address from "./Address.ts"
|
|
47
|
+
import { Chain } from "./Chain.ts"
|
|
48
|
+
import { type Checkpoint, CheckpointData, CheckpointNotFound, type CheckpointTransaction } from "./CheckpointData.ts"
|
|
49
|
+
import { type CheckpointSummary, Checkpoints } from "./Checkpoints.ts"
|
|
50
|
+
import { type Balance, Coins, fromObjects } from "./Coins.ts"
|
|
51
|
+
import * as DynamicFields from "./DynamicFields.ts"
|
|
52
|
+
import { type Event, type EventFilter, Events, type Literal, toDnf, type TransactionEvent } from "./Events.ts"
|
|
53
|
+
import { blake2b256, transactionDigest } from "./Hash.ts"
|
|
54
|
+
import { ObjectNotFound, Objects, type Owner, type SuiObject } from "./Objects.ts"
|
|
55
|
+
import { type MoveFunction, PackageNotFound, Packages } from "./Packages.ts"
|
|
56
|
+
import { RpcError } from "./RpcError.ts"
|
|
57
|
+
import * as T from "./TransactionData.ts"
|
|
58
|
+
import {
|
|
59
|
+
type BalanceChange,
|
|
60
|
+
type ChangedObject,
|
|
61
|
+
type Effects,
|
|
62
|
+
type GasUsed,
|
|
63
|
+
type Include,
|
|
64
|
+
type Status,
|
|
65
|
+
TransactionNotFound,
|
|
66
|
+
Transactions
|
|
67
|
+
} from "./Transactions.ts"
|
|
68
|
+
import * as TypeTag from "./TypeTag.ts"
|
|
69
|
+
|
|
70
|
+
// -----------------------------------------------------------------------------
|
|
71
|
+
// Inputs
|
|
72
|
+
// -----------------------------------------------------------------------------
|
|
73
|
+
|
|
74
|
+
/** An object to put on the node. Ids and types are normalized as a node reports them. */
|
|
75
|
+
export interface ObjectInput {
|
|
76
|
+
readonly objectId: string
|
|
77
|
+
readonly type: string
|
|
78
|
+
/** The Move struct's BCS bytes, e.g. `Bcs.encodeSync(Counter)(value)`. Default empty. */
|
|
79
|
+
readonly contents?: Uint8Array
|
|
80
|
+
/** Default shared, initial version 1. */
|
|
81
|
+
readonly owner?: Owner
|
|
82
|
+
/** Default 1, or one more than the version it replaces. */
|
|
83
|
+
readonly version?: bigint
|
|
84
|
+
/** Default derived from the id and version. */
|
|
85
|
+
readonly digest?: string
|
|
86
|
+
readonly previousTransaction?: string | undefined
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A `0x2::dynamic_field::Field<N, V>` under `parent`, at the id `DynamicFields.deriveId` gives. */
|
|
90
|
+
export interface DynamicFieldInput {
|
|
91
|
+
readonly parent: string
|
|
92
|
+
readonly name: DynamicFields.Name
|
|
93
|
+
readonly valueType: string
|
|
94
|
+
/** The value's BCS bytes. */
|
|
95
|
+
readonly value: Uint8Array
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** A dynamic object field: the `Field<Wrapper<N>, ID>` and its child object, which the field owns. */
|
|
99
|
+
export interface DynamicObjectFieldInput {
|
|
100
|
+
readonly parent: string
|
|
101
|
+
readonly name: DynamicFields.Name
|
|
102
|
+
readonly object: Omit<ObjectInput, "owner">
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** A `0x2::coin::Coin<T>` owned by `owner`. */
|
|
106
|
+
export interface CoinInput {
|
|
107
|
+
readonly owner: string
|
|
108
|
+
readonly balance: bigint
|
|
109
|
+
/** Default SUI. */
|
|
110
|
+
readonly coinType?: string
|
|
111
|
+
/** Default a fresh id. */
|
|
112
|
+
readonly objectId?: string
|
|
113
|
+
readonly version?: bigint
|
|
114
|
+
readonly digest?: string
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface AddressBalanceInput {
|
|
118
|
+
readonly owner: string
|
|
119
|
+
readonly amount: bigint
|
|
120
|
+
/** Default SUI. */
|
|
121
|
+
readonly coinType?: string
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface PackageInput {
|
|
125
|
+
readonly packageId: string
|
|
126
|
+
/** Module name -> compiled bytes, for `Packages.getModules`. */
|
|
127
|
+
readonly modules?: Readonly<Record<string, Uint8Array>>
|
|
128
|
+
/** `"module::function"` -> signature, for `Packages.getFunction` (what client-side resolution reads for object arguments). */
|
|
129
|
+
readonly functions?: Readonly<Record<string, MoveFunction>>
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface ChainInput {
|
|
133
|
+
readonly chainId?: string
|
|
134
|
+
/** Default `"localnet"`. */
|
|
135
|
+
readonly chain?: string
|
|
136
|
+
/** Default 0. */
|
|
137
|
+
readonly epoch?: bigint
|
|
138
|
+
/** Default 1000. */
|
|
139
|
+
readonly referenceGasPrice?: bigint
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** An event a transaction emits. `sender` defaults to the transaction's; `packageId` and `module` to the event type's. */
|
|
143
|
+
export interface EventInput {
|
|
144
|
+
readonly type: string
|
|
145
|
+
readonly contents: Uint8Array
|
|
146
|
+
readonly sender?: string
|
|
147
|
+
readonly packageId?: string
|
|
148
|
+
readonly module?: string
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** What a transaction did, as the responder scripts it. Everything defaults to nothing: success, no gas. */
|
|
152
|
+
export interface Outcome {
|
|
153
|
+
readonly status?: Status
|
|
154
|
+
readonly gasUsed?: GasUsed
|
|
155
|
+
readonly changedObjects?: ReadonlyArray<ChangedObject>
|
|
156
|
+
readonly events?: ReadonlyArray<EventInput>
|
|
157
|
+
readonly balanceChanges?: ReadonlyArray<BalanceChange>
|
|
158
|
+
/** Each command's return values (simulation only). */
|
|
159
|
+
readonly returnValues?: ReadonlyArray<ReadonlyArray<Uint8Array>>
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** A transaction that landed without going through `execute` (sent elsewhere): for `Transactions.get` and `Events`. */
|
|
163
|
+
export interface TransactionInput extends Outcome {
|
|
164
|
+
/** Default a fresh digest. */
|
|
165
|
+
readonly digest?: string
|
|
166
|
+
/** The events' default sender. Default `0x0`. */
|
|
167
|
+
readonly sender?: string
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** A transaction the node was asked to simulate (each `Resolve.budget` dry run too) or execute. */
|
|
171
|
+
export interface Submission {
|
|
172
|
+
readonly mode: "simulate" | "execute"
|
|
173
|
+
readonly data: T.TransactionData
|
|
174
|
+
readonly bytes: Uint8Array
|
|
175
|
+
readonly digest: string
|
|
176
|
+
/** Empty for a simulation. */
|
|
177
|
+
readonly signatures: ReadonlyArray<Uint8Array>
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Scripts transaction outcomes. An `RpcError` fails the simulate / execute call itself. */
|
|
181
|
+
export type Responder = (submission: Submission) => Outcome | Effect.Effect<Outcome, RpcError>
|
|
182
|
+
|
|
183
|
+
export interface Seed {
|
|
184
|
+
readonly objects?: ReadonlyArray<ObjectInput>
|
|
185
|
+
readonly dynamicFields?: ReadonlyArray<DynamicFieldInput | DynamicObjectFieldInput>
|
|
186
|
+
readonly coins?: ReadonlyArray<CoinInput>
|
|
187
|
+
readonly addressBalances?: ReadonlyArray<AddressBalanceInput>
|
|
188
|
+
readonly packages?: ReadonlyArray<PackageInput>
|
|
189
|
+
/** Landed in order, one checkpoint each, after genesis (checkpoint 0). */
|
|
190
|
+
readonly transactions?: ReadonlyArray<TransactionInput>
|
|
191
|
+
/** The `0x6` clock and the timestamp of new checkpoints, in ms. Default 0. */
|
|
192
|
+
readonly clockMs?: bigint
|
|
193
|
+
readonly chain?: ChainInput
|
|
194
|
+
readonly respond?: Responder
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export type Method =
|
|
198
|
+
| "Chain.info"
|
|
199
|
+
| "Chain.referenceGasPrice"
|
|
200
|
+
| "Objects.get"
|
|
201
|
+
| "Objects.listOwned"
|
|
202
|
+
| "Coins.getBalance"
|
|
203
|
+
| "Coins.listBalances"
|
|
204
|
+
| "Coins.list"
|
|
205
|
+
| "Packages.getFunction"
|
|
206
|
+
| "Packages.getModules"
|
|
207
|
+
| "Transactions.simulate"
|
|
208
|
+
| "Transactions.execute"
|
|
209
|
+
| "Transactions.get"
|
|
210
|
+
| "DynamicFields.get"
|
|
211
|
+
| "DynamicFields.getObject"
|
|
212
|
+
| "DynamicFields.list"
|
|
213
|
+
| "Events.list"
|
|
214
|
+
| "Events.subscribe"
|
|
215
|
+
| "Checkpoints.list"
|
|
216
|
+
| "Checkpoints.subscribe"
|
|
217
|
+
| "CheckpointData.get"
|
|
218
|
+
| "CheckpointData.list"
|
|
219
|
+
| "CheckpointData.subscribe"
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* One request the node answered, with the call's arguments as given (decode
|
|
223
|
+
* transaction bytes with `TransactionData.decode`). `Objects.get` is the one
|
|
224
|
+
* exception: an entry per batch, whose arguments are the ids its gets asked
|
|
225
|
+
* for, in order, repeats included (a transport sends each id once).
|
|
226
|
+
*/
|
|
227
|
+
export interface Request {
|
|
228
|
+
readonly method: Method
|
|
229
|
+
readonly args: ReadonlyArray<unknown>
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** The handle on the node: seed and change its state mid-test, and read the request log. */
|
|
233
|
+
export class Node extends /* @__PURE__ */ Context.Service<Node, {
|
|
234
|
+
/** Put (or replace) an object. */
|
|
235
|
+
readonly putObject: (object: ObjectInput) => Effect.Effect<SuiObject>
|
|
236
|
+
readonly removeObject: (objectId: string) => Effect.Effect<void>
|
|
237
|
+
/** Put a dynamic field (or object field and its child); answers the field object. */
|
|
238
|
+
readonly putDynamicField: (field: DynamicFieldInput | DynamicObjectFieldInput) => Effect.Effect<SuiObject>
|
|
239
|
+
readonly putCoin: (coin: CoinInput) => Effect.Effect<SuiObject>
|
|
240
|
+
readonly setAddressBalance: (balance: AddressBalanceInput) => Effect.Effect<void>
|
|
241
|
+
/** Put a package: its object (type `package`), modules and function signatures. */
|
|
242
|
+
readonly putPackage: (pkg: PackageInput) => Effect.Effect<void>
|
|
243
|
+
/** Land a transaction in a new checkpoint; answers its effects, with everything included. */
|
|
244
|
+
readonly putTransaction: (transaction: TransactionInput) => Effect.Effect<Effects>
|
|
245
|
+
/** Set the `0x6` clock and the timestamp of later checkpoints. */
|
|
246
|
+
readonly setClock: (timestampMs: bigint) => Effect.Effect<void>
|
|
247
|
+
readonly setChain: (chain: ChainInput) => Effect.Effect<void>
|
|
248
|
+
/** Replace the responder. */
|
|
249
|
+
readonly respond: (responder: Responder) => Effect.Effect<void>
|
|
250
|
+
readonly requests: Effect.Effect<ReadonlyArray<Request>>
|
|
251
|
+
readonly clearRequests: Effect.Effect<void>
|
|
252
|
+
}>()("@unconfirmed/effect-sui/Testing/Node") {}
|
|
253
|
+
|
|
254
|
+
/** Every capability service the layer provides. */
|
|
255
|
+
export type Services =
|
|
256
|
+
| Chain
|
|
257
|
+
| Objects
|
|
258
|
+
| Coins
|
|
259
|
+
| Packages
|
|
260
|
+
| Transactions
|
|
261
|
+
| Checkpoints
|
|
262
|
+
| DynamicFields.DynamicFields
|
|
263
|
+
| Events
|
|
264
|
+
| CheckpointData
|
|
265
|
+
|
|
266
|
+
// -----------------------------------------------------------------------------
|
|
267
|
+
// Implementation
|
|
268
|
+
// -----------------------------------------------------------------------------
|
|
269
|
+
|
|
270
|
+
const MAX_BATCH = 50
|
|
271
|
+
const SUI = TypeTag.SUI
|
|
272
|
+
const COIN = "0x2::coin::Coin"
|
|
273
|
+
const SHARED: Owner = { _tag: "Shared", initialSharedVersion: 1n }
|
|
274
|
+
const NO_GAS: GasUsed = { computationCost: 0n, storageCost: 0n, storageRebate: 0n, nonRefundableStorageFee: 0n }
|
|
275
|
+
|
|
276
|
+
const encodeAddress = /* @__PURE__ */ Bcs.encodeSync(Bcs.Address)
|
|
277
|
+
const encodeClock = /* @__PURE__ */ Bcs.encodeSync(/* @__PURE__ */ Bcs.struct({ id: Bcs.Address, timestamp_ms: Bcs.u64 }))
|
|
278
|
+
const decodeCoin = /* @__PURE__ */ Bcs.decode(/* @__PURE__ */ Bcs.struct({ id: Bcs.Address, balance: Bcs.u64 }))
|
|
279
|
+
const encodeCoin = /* @__PURE__ */ Bcs.encodeSync(/* @__PURE__ */ Bcs.struct({ id: Bcs.Address, balance: Bcs.u64 }))
|
|
280
|
+
|
|
281
|
+
/** A stable 32-byte digest of `label`, base58. */
|
|
282
|
+
const digestOf = (label: string): string => base58.encode(blake2b256(new TextEncoder().encode(`testing:${label}`)))
|
|
283
|
+
|
|
284
|
+
/** A type as a node reports it; `package` and other non-types as given. */
|
|
285
|
+
const normalizeType = (type: string): string => {
|
|
286
|
+
try {
|
|
287
|
+
return TypeTag.normalizeString(type)
|
|
288
|
+
} catch {
|
|
289
|
+
return type
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const concat = (...parts: ReadonlyArray<Uint8Array>): Uint8Array => {
|
|
294
|
+
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0))
|
|
295
|
+
let o = 0
|
|
296
|
+
for (const p of parts) {
|
|
297
|
+
out.set(p, o)
|
|
298
|
+
o += p.length
|
|
299
|
+
}
|
|
300
|
+
return out
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** `Field<N, V>` -> `[N, V]`, formatted. */
|
|
304
|
+
const fieldTypes = (type: string): readonly [string, string] | undefined => {
|
|
305
|
+
try {
|
|
306
|
+
const t = TypeTag.parse(type)
|
|
307
|
+
return t._tag === "struct" && t.typeParams.length === 2
|
|
308
|
+
? [TypeTag.format(t.typeParams[0]!), TypeTag.format(t.typeParams[1]!)]
|
|
309
|
+
: undefined
|
|
310
|
+
} catch {
|
|
311
|
+
return undefined
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
interface FieldEntry {
|
|
316
|
+
readonly kind: "Field" | "Object"
|
|
317
|
+
readonly parent: Address.Address
|
|
318
|
+
readonly name: DynamicFields.Name
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
interface Landed {
|
|
322
|
+
readonly effects: Effects & {
|
|
323
|
+
readonly events: ReadonlyArray<TransactionEvent>
|
|
324
|
+
readonly balanceChanges: ReadonlyArray<BalanceChange>
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const view = (stored: Landed["effects"], include: ReadonlyArray<Include> | undefined, landed: boolean): Effects => ({
|
|
329
|
+
digest: stored.digest,
|
|
330
|
+
status: stored.status,
|
|
331
|
+
gasUsed: stored.gasUsed,
|
|
332
|
+
changedObjects: stored.changedObjects,
|
|
333
|
+
...(landed && stored.checkpoint !== undefined && { checkpoint: stored.checkpoint }),
|
|
334
|
+
...(landed && stored.timestampMs !== undefined && { timestampMs: stored.timestampMs }),
|
|
335
|
+
...(include?.includes("events") && { events: stored.events }),
|
|
336
|
+
...(include?.includes("balanceChanges") && { balanceChanges: stored.balanceChanges })
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
const matches = (l: Literal, e: Event): boolean => {
|
|
340
|
+
const p = l.predicate
|
|
341
|
+
const emitted = `${e.packageId}::${e.module}`
|
|
342
|
+
const hit = p._tag === "Sender"
|
|
343
|
+
? e.sender === p.address
|
|
344
|
+
: p._tag === "EmitModule"
|
|
345
|
+
? emitted === p.module || emitted.startsWith(`${p.module}::`)
|
|
346
|
+
: p._tag === "EventType"
|
|
347
|
+
? TypeTag.matchesPath(p.type, e.type)
|
|
348
|
+
: false
|
|
349
|
+
return l.negated ? !hit : hit
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** The filter as a predicate; an `RpcError` for what the in-memory node can't evaluate. */
|
|
353
|
+
const eventPredicate = (method: Method, filter: EventFilter | undefined): Result.Result<(e: Event) => boolean, RpcError> => {
|
|
354
|
+
if (filter === undefined) return Result.succeed(() => true)
|
|
355
|
+
const dnf = toDnf(filter)
|
|
356
|
+
if (dnf.some((term) => term.some((l) => l.predicate._tag === "StreamHead"))) {
|
|
357
|
+
return Result.fail(new RpcError({ method, code: "UNIMPLEMENTED", message: "the in-memory node has no authenticated event streams (StreamHead)" }))
|
|
358
|
+
}
|
|
359
|
+
return Result.succeed((e) => dnf.some((term) => term.every((l) => matches(l, e))))
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
class GetObject extends EffectRequest.Class<{ readonly objectId: Address.Address }, SuiObject, ObjectNotFound | RpcError> {}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* A new in-memory node: every capability service plus its `Node` handle.
|
|
366
|
+
* Starts with the `0x6` clock and a genesis checkpoint (0), whose digest is
|
|
367
|
+
* the chain id, then `seed`. Use `layer` unless one node must outlive a run
|
|
368
|
+
* (`Layer.succeedContext(Effect.runSync(Testing.make()))` shares it).
|
|
369
|
+
*/
|
|
370
|
+
export const make = (seed: Seed = {}): Effect.Effect<Context.Context<Services | Node>> => Effect.gen(function*() {
|
|
371
|
+
const objects = new Map<Address.Address, SuiObject>()
|
|
372
|
+
const fields = new Map<Address.Address, FieldEntry>()
|
|
373
|
+
const addressBalances = new Map<string, bigint>()
|
|
374
|
+
const packages = new Map<Address.Address, { readonly modules: ReadonlyMap<string, Uint8Array>; readonly functions: ReadonlyMap<string, MoveFunction> }>()
|
|
375
|
+
const transactions = new Map<string, Landed>()
|
|
376
|
+
const checkpoints: Array<Checkpoint> = []
|
|
377
|
+
const requests: Array<Request> = []
|
|
378
|
+
const landedCheckpoints = yield* PubSub.unbounded<Checkpoint>()
|
|
379
|
+
let chain = { chainId: digestOf("genesis"), chain: "localnet", epoch: 0n, referenceGasPrice: 1000n }
|
|
380
|
+
let clock = 0n
|
|
381
|
+
let responder: Responder = () => ({})
|
|
382
|
+
let fresh = 0
|
|
383
|
+
|
|
384
|
+
const log = (method: Method, ...args: ReadonlyArray<unknown>) => void requests.push({ method, args })
|
|
385
|
+
const freshId = () => Address.fromBytes(blake2b256(new TextEncoder().encode(`testing:object:${fresh++}`)))
|
|
386
|
+
|
|
387
|
+
// --- state -----------------------------------------------------------------
|
|
388
|
+
|
|
389
|
+
const putObject = (o: ObjectInput): SuiObject => {
|
|
390
|
+
const objectId = Address.normalize(o.objectId)
|
|
391
|
+
const version = o.version ?? (objects.has(objectId) ? objects.get(objectId)!.version + 1n : 1n)
|
|
392
|
+
const object: SuiObject = {
|
|
393
|
+
objectId,
|
|
394
|
+
version,
|
|
395
|
+
digest: (o.digest ?? digestOf(`${objectId}:${version}`)) as T.ObjectDigest,
|
|
396
|
+
owner: o.owner ?? SHARED,
|
|
397
|
+
type: normalizeType(o.type),
|
|
398
|
+
contents: o.contents ?? new Uint8Array(),
|
|
399
|
+
previousTransaction: o.previousTransaction
|
|
400
|
+
}
|
|
401
|
+
objects.set(objectId, object)
|
|
402
|
+
return object
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const setClock = (ms: bigint) => {
|
|
406
|
+
clock = ms
|
|
407
|
+
putObject({ objectId: Address.CLOCK, type: "0x2::clock::Clock", contents: encodeClock({ id: Address.CLOCK, timestamp_ms: ms }) })
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const putDynamicField = (f: DynamicFieldInput | DynamicObjectFieldInput): SuiObject => {
|
|
411
|
+
const parent = Address.normalize(f.parent)
|
|
412
|
+
const nameType = normalizeType(f.name.type)
|
|
413
|
+
const name = { type: nameType, bcs: f.name.bcs }
|
|
414
|
+
if ("object" in f) {
|
|
415
|
+
const wrapper = DynamicFields.objectFieldNameType(nameType)
|
|
416
|
+
const fieldId = DynamicFields.deriveId(parent, wrapper, name.bcs)
|
|
417
|
+
const child = putObject({ ...f.object, owner: { _tag: "ObjectOwner", address: fieldId } })
|
|
418
|
+
fields.set(fieldId, { kind: "Object", parent, name })
|
|
419
|
+
return putObject({
|
|
420
|
+
objectId: fieldId,
|
|
421
|
+
type: `0x2::dynamic_field::Field<${wrapper}, 0x2::object::ID>`,
|
|
422
|
+
owner: { _tag: "ObjectOwner", address: parent },
|
|
423
|
+
contents: concat(encodeAddress(fieldId), name.bcs, encodeAddress(child.objectId))
|
|
424
|
+
})
|
|
425
|
+
}
|
|
426
|
+
const fieldId = DynamicFields.deriveId(parent, nameType, name.bcs)
|
|
427
|
+
fields.set(fieldId, { kind: "Field", parent, name })
|
|
428
|
+
return putObject({
|
|
429
|
+
objectId: fieldId,
|
|
430
|
+
type: `0x2::dynamic_field::Field<${nameType}, ${f.valueType}>`,
|
|
431
|
+
owner: { _tag: "ObjectOwner", address: parent },
|
|
432
|
+
contents: concat(encodeAddress(fieldId), name.bcs, f.value)
|
|
433
|
+
})
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const putCoin = (c: CoinInput): SuiObject => {
|
|
437
|
+
const objectId = c.objectId === undefined ? freshId() : Address.normalize(c.objectId)
|
|
438
|
+
return putObject({
|
|
439
|
+
objectId,
|
|
440
|
+
type: `${COIN}<${c.coinType ?? SUI}>`,
|
|
441
|
+
owner: { _tag: "AddressOwner", address: Address.normalize(c.owner) },
|
|
442
|
+
contents: encodeCoin({ id: objectId, balance: c.balance }),
|
|
443
|
+
...(c.version !== undefined && { version: c.version }),
|
|
444
|
+
...(c.digest !== undefined && { digest: c.digest })
|
|
445
|
+
})
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const balanceKey = (owner: Address.Address, coinType: string) => `${owner}|${coinType}`
|
|
449
|
+
const setAddressBalance = (b: AddressBalanceInput) =>
|
|
450
|
+
void addressBalances.set(balanceKey(Address.normalize(b.owner), TypeTag.normalizeString(b.coinType ?? SUI)), b.amount)
|
|
451
|
+
|
|
452
|
+
const putPackage = (p: PackageInput) => {
|
|
453
|
+
const packageId = Address.normalize(p.packageId)
|
|
454
|
+
putObject({ objectId: packageId, type: "package", owner: { _tag: "Immutable" } })
|
|
455
|
+
packages.set(packageId, {
|
|
456
|
+
modules: new Map(Object.entries(p.modules ?? {})),
|
|
457
|
+
functions: new Map(Object.entries(p.functions ?? {}).map(([k, f]) => [`${packageId}::${k}`, f] as const))
|
|
458
|
+
})
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const setChain = (c: ChainInput) => void (chain = { ...chain, ...c })
|
|
462
|
+
|
|
463
|
+
/** Land a transaction in a checkpoint of its own; a digest that already landed answers what it did. */
|
|
464
|
+
const land = (digest: string, sender: Address.Address, o: Outcome): Landed["effects"] => {
|
|
465
|
+
const existing = transactions.get(digest)
|
|
466
|
+
if (existing) return existing.effects
|
|
467
|
+
const sequenceNumber = BigInt(checkpoints.length)
|
|
468
|
+
const events: Array<TransactionEvent> = (o.events ?? []).map((e, eventIndex) => {
|
|
469
|
+
const type = normalizeType(e.type)
|
|
470
|
+
const tag = Result.try(() => TypeTag.parse(type))
|
|
471
|
+
const struct = Result.isSuccess(tag) && tag.success._tag === "struct" ? tag.success : undefined
|
|
472
|
+
return {
|
|
473
|
+
type,
|
|
474
|
+
sender: e.sender === undefined ? sender : Address.normalize(e.sender),
|
|
475
|
+
packageId: e.packageId !== undefined ? Address.normalize(e.packageId) : struct?.address ?? Address.ZERO,
|
|
476
|
+
module: e.module ?? struct?.module ?? "",
|
|
477
|
+
contents: e.contents,
|
|
478
|
+
transactionDigest: digest,
|
|
479
|
+
eventIndex
|
|
480
|
+
}
|
|
481
|
+
})
|
|
482
|
+
const effects: Landed["effects"] = {
|
|
483
|
+
digest,
|
|
484
|
+
status: o.status ?? { _tag: "Success" },
|
|
485
|
+
gasUsed: o.gasUsed ?? NO_GAS,
|
|
486
|
+
changedObjects: o.changedObjects ?? [],
|
|
487
|
+
checkpoint: sequenceNumber,
|
|
488
|
+
timestampMs: clock,
|
|
489
|
+
events,
|
|
490
|
+
balanceChanges: o.balanceChanges ?? []
|
|
491
|
+
}
|
|
492
|
+
const transaction: CheckpointTransaction = {
|
|
493
|
+
digest,
|
|
494
|
+
index: 0n,
|
|
495
|
+
status: effects.status,
|
|
496
|
+
gasUsed: effects.gasUsed,
|
|
497
|
+
changedObjects: effects.changedObjects,
|
|
498
|
+
events: events.map((e) => ({ ...e, checkpoint: sequenceNumber, transactionIndex: 0n }))
|
|
499
|
+
}
|
|
500
|
+
const checkpoint = { sequenceNumber, digest: digestOf(`checkpoint:${sequenceNumber}`), epoch: chain.epoch, timestampMs: clock, transactions: [transaction] }
|
|
501
|
+
checkpoints.push(checkpoint)
|
|
502
|
+
transactions.set(digest, { effects })
|
|
503
|
+
PubSub.publishUnsafe(landedCheckpoints, checkpoint)
|
|
504
|
+
return effects
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const putTransaction = (t: TransactionInput) =>
|
|
508
|
+
land(t.digest ?? digestOf(`transaction:${checkpoints.length}`), t.sender === undefined ? Address.ZERO : Address.normalize(t.sender), t)
|
|
509
|
+
|
|
510
|
+
// --- seed ------------------------------------------------------------------
|
|
511
|
+
|
|
512
|
+
if (seed.chain) setChain(seed.chain)
|
|
513
|
+
setClock(seed.clockMs ?? 0n)
|
|
514
|
+
checkpoints.push({ sequenceNumber: 0n, digest: chain.chainId, epoch: chain.epoch, timestampMs: clock, transactions: [] })
|
|
515
|
+
for (const p of seed.packages ?? []) putPackage(p)
|
|
516
|
+
for (const o of seed.objects ?? []) putObject(o)
|
|
517
|
+
for (const f of seed.dynamicFields ?? []) putDynamicField(f)
|
|
518
|
+
for (const c of seed.coins ?? []) putCoin(c)
|
|
519
|
+
for (const b of seed.addressBalances ?? []) setAddressBalance(b)
|
|
520
|
+
for (const t of seed.transactions ?? []) putTransaction(t)
|
|
521
|
+
if (seed.respond) responder = seed.respond
|
|
522
|
+
|
|
523
|
+
// --- services --------------------------------------------------------------
|
|
524
|
+
|
|
525
|
+
const resolver = RequestResolver.make<GetObject>((entries) =>
|
|
526
|
+
Effect.sync(() => {
|
|
527
|
+
log("Objects.get", ...entries.map((e) => e.request.objectId))
|
|
528
|
+
for (const entry of entries) {
|
|
529
|
+
const o = objects.get(entry.request.objectId)
|
|
530
|
+
entry.completeUnsafe(o ? Exit.succeed(o) : Exit.fail(new ObjectNotFound({ objectId: entry.request.objectId })))
|
|
531
|
+
}
|
|
532
|
+
})
|
|
533
|
+
).pipe(RequestResolver.batchN(MAX_BATCH))
|
|
534
|
+
const getObject = (objectId: Address.Address) => Effect.request(new GetObject({ objectId }), resolver)
|
|
535
|
+
|
|
536
|
+
const owned = (owner: Address.Address, type: string | undefined) =>
|
|
537
|
+
[...objects.values()].filter((o) =>
|
|
538
|
+
(o.owner._tag === "AddressOwner" || o.owner._tag === "ConsensusAddressOwner") && o.owner.address === owner &&
|
|
539
|
+
(type === undefined || TypeTag.matchesPath(type, o.type))
|
|
540
|
+
)
|
|
541
|
+
|
|
542
|
+
const objectsService = Objects.of({
|
|
543
|
+
get: getObject,
|
|
544
|
+
listOwned: (owner, options) =>
|
|
545
|
+
Stream.suspend(() => {
|
|
546
|
+
log("Objects.listOwned", owner, options)
|
|
547
|
+
return Stream.fromIterable(owned(owner, options?.type))
|
|
548
|
+
})
|
|
549
|
+
})
|
|
550
|
+
|
|
551
|
+
const coinType = (method: Method, type: string) =>
|
|
552
|
+
Effect.try({
|
|
553
|
+
try: () => TypeTag.normalizeString(type),
|
|
554
|
+
catch: (e) => new RpcError({ method, code: "INVALID_ARGUMENT", message: `invalid coin type ${type}: ${e instanceof Error ? e.message : String(e)}` })
|
|
555
|
+
})
|
|
556
|
+
const balanceOf = (owner: Address.Address, type: string): Effect.Effect<Balance, RpcError> => {
|
|
557
|
+
let coinBalance = 0n
|
|
558
|
+
for (const o of owned(owner, `${COIN}<${type}>`)) {
|
|
559
|
+
const c = decodeCoin(o.contents)
|
|
560
|
+
if (Result.isFailure(c)) {
|
|
561
|
+
return Effect.fail(new RpcError({ method: "Coins.getBalance", code: "DATA_LOSS", message: `malformed coin ${o.objectId}` }))
|
|
562
|
+
}
|
|
563
|
+
coinBalance += c.success.balance
|
|
564
|
+
}
|
|
565
|
+
const addressBalance = addressBalances.get(balanceKey(owner, type)) ?? 0n
|
|
566
|
+
return Effect.succeed({ coinType: type, total: addressBalance + coinBalance, addressBalance, coinBalance })
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const coinsService = Coins.of({
|
|
570
|
+
getBalance: (owner, type = SUI) =>
|
|
571
|
+
Effect.suspend(() => {
|
|
572
|
+
log("Coins.getBalance", owner, type)
|
|
573
|
+
return Effect.flatMap(coinType("Coins.getBalance", type), (t) => balanceOf(owner, t))
|
|
574
|
+
}),
|
|
575
|
+
listBalances: (owner) =>
|
|
576
|
+
Stream.suspend(() => {
|
|
577
|
+
log("Coins.listBalances", owner)
|
|
578
|
+
const types = new Set<string>()
|
|
579
|
+
for (const key of addressBalances.keys()) if (key.startsWith(`${owner}|`)) types.add(key.slice(owner.length + 1))
|
|
580
|
+
for (const o of owned(owner, COIN)) {
|
|
581
|
+
const t = Result.try(() => TypeTag.parse(o.type))
|
|
582
|
+
if (Result.isSuccess(t) && t.success._tag === "struct" && t.success.typeParams[0]) types.add(TypeTag.format(t.success.typeParams[0]))
|
|
583
|
+
}
|
|
584
|
+
return Stream.fromIterable([...types].sort()).pipe(Stream.mapEffect((t) => balanceOf(owner, t)))
|
|
585
|
+
}),
|
|
586
|
+
list: (owner, type) =>
|
|
587
|
+
Stream.suspend(() => {
|
|
588
|
+
log("Coins.list", owner, type)
|
|
589
|
+
return fromObjects("Coins.list", type, (t) => Stream.suspend(() => Stream.fromIterable(owned(owner, t))))
|
|
590
|
+
})
|
|
591
|
+
})
|
|
592
|
+
|
|
593
|
+
const chainService = Chain.of({
|
|
594
|
+
info: Effect.sync(() => {
|
|
595
|
+
log("Chain.info")
|
|
596
|
+
return {
|
|
597
|
+
chainId: chain.chainId as T.ObjectDigest,
|
|
598
|
+
chain: chain.chain,
|
|
599
|
+
epoch: chain.epoch,
|
|
600
|
+
checkpointHeight: BigInt(checkpoints.length - 1)
|
|
601
|
+
}
|
|
602
|
+
}),
|
|
603
|
+
referenceGasPrice: Effect.sync(() => {
|
|
604
|
+
log("Chain.referenceGasPrice")
|
|
605
|
+
return chain.referenceGasPrice
|
|
606
|
+
})
|
|
607
|
+
})
|
|
608
|
+
|
|
609
|
+
const packagesService = Packages.of({
|
|
610
|
+
getFunction: (target) =>
|
|
611
|
+
Effect.suspend(() => {
|
|
612
|
+
log("Packages.getFunction", target)
|
|
613
|
+
const key = `${Address.normalize(target.package)}::${target.module}::${target.function}`
|
|
614
|
+
const f = packages.get(Address.normalize(target.package))?.functions.get(key)
|
|
615
|
+
return f
|
|
616
|
+
? Effect.succeed(f)
|
|
617
|
+
: Effect.fail(new RpcError({
|
|
618
|
+
method: "Packages.getFunction",
|
|
619
|
+
code: "NOT_FOUND",
|
|
620
|
+
message: `no function ${key} on the in-memory node (seed it with putPackage({ functions }))`
|
|
621
|
+
}))
|
|
622
|
+
}),
|
|
623
|
+
getModules: (packageId) =>
|
|
624
|
+
Effect.suspend((): Effect.Effect<ReadonlyMap<string, Uint8Array>, PackageNotFound | RpcError> => {
|
|
625
|
+
log("Packages.getModules", packageId)
|
|
626
|
+
const p = packages.get(packageId)
|
|
627
|
+
if (p) return Effect.succeed(p.modules)
|
|
628
|
+
return objects.has(packageId)
|
|
629
|
+
? Effect.fail(new RpcError({ method: "Packages.getModules", code: "INVALID_ARGUMENT", message: `${packageId} is not a package` }))
|
|
630
|
+
: Effect.fail(new PackageNotFound({ packageId }))
|
|
631
|
+
})
|
|
632
|
+
})
|
|
633
|
+
|
|
634
|
+
const submission = (method: Method, mode: Submission["mode"], bytes: Uint8Array, signatures: ReadonlyArray<Uint8Array>) =>
|
|
635
|
+
Effect.flatMap(
|
|
636
|
+
Result.match(T.decode(bytes), {
|
|
637
|
+
onFailure: (e) => Effect.fail(new RpcError({ method, code: "INVALID_ARGUMENT", message: `not TransactionData: ${e.message}` })),
|
|
638
|
+
onSuccess: (data) => Effect.succeed<Submission>({ mode, data, bytes, digest: transactionDigest(bytes), signatures })
|
|
639
|
+
}),
|
|
640
|
+
(s) =>
|
|
641
|
+
Effect.map(
|
|
642
|
+
Effect.suspend(() => {
|
|
643
|
+
const out = responder(s)
|
|
644
|
+
return Effect.isEffect(out) ? out : Effect.succeed(out)
|
|
645
|
+
}),
|
|
646
|
+
(outcome) => [s, outcome] as const
|
|
647
|
+
)
|
|
648
|
+
)
|
|
649
|
+
|
|
650
|
+
const transactionsService = Transactions.of({
|
|
651
|
+
simulate: (bytes, options) =>
|
|
652
|
+
Effect.suspend(() => {
|
|
653
|
+
log("Transactions.simulate", bytes, options)
|
|
654
|
+
return Effect.map(submission("Transactions.simulate", "simulate", bytes, []), ([s, o]) => ({
|
|
655
|
+
effects: {
|
|
656
|
+
digest: s.digest,
|
|
657
|
+
status: o.status ?? { _tag: "Success" },
|
|
658
|
+
gasUsed: o.gasUsed ?? NO_GAS,
|
|
659
|
+
changedObjects: o.changedObjects ?? []
|
|
660
|
+
},
|
|
661
|
+
returnValues: o.returnValues ?? []
|
|
662
|
+
}))
|
|
663
|
+
}),
|
|
664
|
+
execute: (bytes, signatures, options) =>
|
|
665
|
+
Effect.suspend(() => {
|
|
666
|
+
log("Transactions.execute", bytes, signatures, options)
|
|
667
|
+
const done = transactions.get(transactionDigest(bytes))
|
|
668
|
+
if (done) return Effect.succeed(view(done.effects, options?.include, false))
|
|
669
|
+
return Effect.map(
|
|
670
|
+
submission("Transactions.execute", "execute", bytes, signatures),
|
|
671
|
+
([s, o]) => view(land(s.digest, s.data.sender, o), options?.include, false)
|
|
672
|
+
)
|
|
673
|
+
}),
|
|
674
|
+
get: (digest, options) =>
|
|
675
|
+
Effect.suspend(() => {
|
|
676
|
+
log("Transactions.get", digest, options)
|
|
677
|
+
const t = transactions.get(digest)
|
|
678
|
+
return t ? Effect.succeed(view(t.effects, options?.include, true)) : Effect.fail(new TransactionNotFound({ digest }))
|
|
679
|
+
})
|
|
680
|
+
})
|
|
681
|
+
|
|
682
|
+
const readField = (parent: Address.Address, type: string, name: DynamicFields.Name) =>
|
|
683
|
+
Effect.flatMap(
|
|
684
|
+
Effect.try({
|
|
685
|
+
try: () => DynamicFields.deriveId(parent, type, name.bcs),
|
|
686
|
+
catch: (e) => new DynamicFields.InvalidDynamicFieldName({ nameType: type, issue: e instanceof Error ? e.message : String(e) })
|
|
687
|
+
}),
|
|
688
|
+
(fieldId) =>
|
|
689
|
+
getObject(fieldId).pipe(
|
|
690
|
+
Effect.catchTag("ObjectNotFound", () => Effect.fail(new DynamicFields.DynamicFieldNotFound({ parent, nameType: name.type, fieldId }))),
|
|
691
|
+
Effect.map((field): DynamicFields.DynamicField => ({
|
|
692
|
+
parent,
|
|
693
|
+
fieldId,
|
|
694
|
+
name,
|
|
695
|
+
valueType: fieldTypes(field.type)?.[1] ?? field.type,
|
|
696
|
+
value: field.contents.subarray(32 + name.bcs.length),
|
|
697
|
+
field
|
|
698
|
+
}))
|
|
699
|
+
)
|
|
700
|
+
)
|
|
701
|
+
|
|
702
|
+
const dynamicFieldsService = DynamicFields.DynamicFields.of({
|
|
703
|
+
get: (parent, name) =>
|
|
704
|
+
Effect.suspend(() => {
|
|
705
|
+
log("DynamicFields.get", parent, name)
|
|
706
|
+
return readField(parent, name.type, name)
|
|
707
|
+
}),
|
|
708
|
+
getObject: (parent, name) =>
|
|
709
|
+
Effect.suspend(() => {
|
|
710
|
+
log("DynamicFields.getObject", parent, name)
|
|
711
|
+
return Effect.flatMap(readField(parent, DynamicFields.objectFieldNameType(name.type), name), (f) =>
|
|
712
|
+
getObject(Address.fromBytes(f.value.subarray(0, 32))).pipe(
|
|
713
|
+
Effect.catchTag("ObjectNotFound", () =>
|
|
714
|
+
Effect.fail(new DynamicFields.DynamicFieldNotFound({ parent, nameType: name.type, fieldId: f.fieldId })))
|
|
715
|
+
))
|
|
716
|
+
}),
|
|
717
|
+
list: (parent, options) =>
|
|
718
|
+
Stream.suspend(() => {
|
|
719
|
+
log("DynamicFields.list", parent, options)
|
|
720
|
+
const out: Array<DynamicFields.FieldInfo> = []
|
|
721
|
+
for (const [fieldId, entry] of fields) {
|
|
722
|
+
const field = objects.get(fieldId)
|
|
723
|
+
if (entry.parent !== parent || field === undefined) continue
|
|
724
|
+
if (options?.nameType !== undefined && !TypeTag.matchesPath(options.nameType, entry.name.type)) continue
|
|
725
|
+
const value = field.contents.subarray(32 + entry.name.bcs.length)
|
|
726
|
+
const childId = entry.kind === "Object" ? Address.fromBytes(value.subarray(0, 32)) : undefined
|
|
727
|
+
out.push({
|
|
728
|
+
kind: entry.kind,
|
|
729
|
+
parent,
|
|
730
|
+
fieldId,
|
|
731
|
+
name: entry.name,
|
|
732
|
+
valueType: childId !== undefined ? objects.get(childId)?.type ?? "" : fieldTypes(field.type)?.[1] ?? "",
|
|
733
|
+
value,
|
|
734
|
+
childId
|
|
735
|
+
})
|
|
736
|
+
}
|
|
737
|
+
return Stream.fromIterable(out)
|
|
738
|
+
})
|
|
739
|
+
})
|
|
740
|
+
|
|
741
|
+
const range = <A>(start: bigint | undefined, end: bigint | undefined, f: (c: Checkpoint) => Iterable<A>) =>
|
|
742
|
+
checkpoints.filter((c) => (start === undefined || c.sequenceNumber >= start) && (end === undefined || c.sequenceNumber < end)).flatMap(
|
|
743
|
+
(c) => [...f(c)]
|
|
744
|
+
)
|
|
745
|
+
const allEvents = (c: Checkpoint) => c.transactions.flatMap((t) => t.events)
|
|
746
|
+
const summary = (c: Checkpoint): CheckpointSummary => ({ sequenceNumber: c.sequenceNumber, digest: c.digest })
|
|
747
|
+
const live = Stream.fromPubSub(landedCheckpoints)
|
|
748
|
+
|
|
749
|
+
const eventsService = Events.of({
|
|
750
|
+
list: (options) =>
|
|
751
|
+
Stream.suspend(() => {
|
|
752
|
+
log("Events.list", options)
|
|
753
|
+
return Result.match(eventPredicate("Events.list", options?.filter), {
|
|
754
|
+
onFailure: Stream.fail,
|
|
755
|
+
onSuccess: (keep) => {
|
|
756
|
+
const events = range(options?.start, options?.end, allEvents).filter(keep)
|
|
757
|
+
return Stream.fromIterable(options?.descending ? events.reverse() : events)
|
|
758
|
+
}
|
|
759
|
+
})
|
|
760
|
+
}),
|
|
761
|
+
subscribe: (filter) =>
|
|
762
|
+
Stream.suspend(() => {
|
|
763
|
+
log("Events.subscribe", filter)
|
|
764
|
+
return Result.match(eventPredicate("Events.subscribe", filter), {
|
|
765
|
+
onFailure: Stream.fail,
|
|
766
|
+
onSuccess: (keep) => live.pipe(Stream.flatMap((c) => Stream.fromIterable(allEvents(c).filter(keep))))
|
|
767
|
+
})
|
|
768
|
+
})
|
|
769
|
+
})
|
|
770
|
+
|
|
771
|
+
const checkpointsService = Checkpoints.of({
|
|
772
|
+
list: (options) =>
|
|
773
|
+
Stream.suspend(() => {
|
|
774
|
+
log("Checkpoints.list", options)
|
|
775
|
+
return Stream.fromIterable(range(options?.start, options?.end, (c) => [summary(c)]))
|
|
776
|
+
}),
|
|
777
|
+
subscribe: Stream.suspend(() => {
|
|
778
|
+
log("Checkpoints.subscribe")
|
|
779
|
+
return Stream.map(live, summary)
|
|
780
|
+
})
|
|
781
|
+
})
|
|
782
|
+
|
|
783
|
+
const checkpointDataService = CheckpointData.of({
|
|
784
|
+
get: (sequenceNumber) =>
|
|
785
|
+
Effect.suspend(() => {
|
|
786
|
+
log("CheckpointData.get", sequenceNumber)
|
|
787
|
+
const c = checkpoints[Number(sequenceNumber)]
|
|
788
|
+
return c ? Effect.succeed(c) : Effect.fail(new CheckpointNotFound({ sequenceNumber }))
|
|
789
|
+
}),
|
|
790
|
+
list: (options) =>
|
|
791
|
+
Stream.suspend(() => {
|
|
792
|
+
log("CheckpointData.list", options)
|
|
793
|
+
return Stream.fromIterable(range(options?.start, options?.end, (c) => [c]))
|
|
794
|
+
}),
|
|
795
|
+
subscribe: Stream.suspend(() => {
|
|
796
|
+
log("CheckpointData.subscribe")
|
|
797
|
+
return live
|
|
798
|
+
})
|
|
799
|
+
})
|
|
800
|
+
|
|
801
|
+
const node = Node.of({
|
|
802
|
+
putObject: (o) => Effect.sync(() => putObject(o)),
|
|
803
|
+
removeObject: (objectId) => Effect.sync(() => void objects.delete(Address.normalize(objectId))),
|
|
804
|
+
putDynamicField: (f) => Effect.sync(() => putDynamicField(f)),
|
|
805
|
+
putCoin: (c) => Effect.sync(() => putCoin(c)),
|
|
806
|
+
setAddressBalance: (b) => Effect.sync(() => setAddressBalance(b)),
|
|
807
|
+
putPackage: (p) => Effect.sync(() => putPackage(p)),
|
|
808
|
+
putTransaction: (t) => Effect.sync(() => putTransaction(t)),
|
|
809
|
+
setClock: (ms) => Effect.sync(() => setClock(ms)),
|
|
810
|
+
setChain: (c) => Effect.sync(() => setChain(c)),
|
|
811
|
+
respond: (r) => Effect.sync(() => void (responder = r)),
|
|
812
|
+
requests: Effect.sync(() => [...requests]),
|
|
813
|
+
clearRequests: Effect.sync(() => void (requests.length = 0))
|
|
814
|
+
})
|
|
815
|
+
|
|
816
|
+
return Context.make(Objects, objectsService).pipe(
|
|
817
|
+
Context.add(Coins, coinsService),
|
|
818
|
+
Context.add(Chain, chainService),
|
|
819
|
+
Context.add(Packages, packagesService),
|
|
820
|
+
Context.add(Transactions, transactionsService),
|
|
821
|
+
Context.add(DynamicFields.DynamicFields, dynamicFieldsService),
|
|
822
|
+
Context.add(Events, eventsService),
|
|
823
|
+
Context.add(Checkpoints, checkpointsService),
|
|
824
|
+
Context.add(CheckpointData, checkpointDataService),
|
|
825
|
+
Context.add(Node, node)
|
|
826
|
+
)
|
|
827
|
+
})
|
|
828
|
+
|
|
829
|
+
/** A fresh in-memory node for each use of the layer (see `make`). */
|
|
830
|
+
export const layer = (seed: Seed = {}): Layer.Layer<Services | Node> => Layer.effectContext(make(seed))
|