@unconfirmed/effect-sui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/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 +6 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +6 -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/Features.ts +114 -0
- package/src/wallet/Wallet.ts +550 -0
- package/src/wallet/index.ts +5 -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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two ways zkLogin inputs are refused. Neither is thrown across the
|
|
3
|
+
* public API: every function that can refuse answers an `Effect` failing
|
|
4
|
+
* with one of these.
|
|
5
|
+
*/
|
|
6
|
+
import * as Schema from "effect/Schema"
|
|
7
|
+
|
|
8
|
+
/** A value the zkLogin circuit cannot represent (too long, out of field, escaped claim, ...). */
|
|
9
|
+
export class InvalidZkLoginInput extends Schema.TaggedError<InvalidZkLoginInput>()("InvalidZkLoginInput", {
|
|
10
|
+
reason: Schema.String
|
|
11
|
+
}) {
|
|
12
|
+
override get message(): string {
|
|
13
|
+
return this.reason
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A JWT that is malformed, too long, or lacks the claims zkLogin needs. */
|
|
18
|
+
export class InvalidJwt extends Schema.TaggedError<InvalidJwt>()("InvalidJwt", {
|
|
19
|
+
reason: Schema.String
|
|
20
|
+
}) {
|
|
21
|
+
override get message(): string {
|
|
22
|
+
return `invalid JWT: ${this.reason}`
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @internal Internals throw plain errors; the public boundary converts them. */
|
|
27
|
+
export const reasonOf = (e: unknown): string => (e instanceof Error ? e.message : String(e))
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JWT handling for zkLogin: decode (not verify — the proof does that) with
|
|
3
|
+
* Schema-validated claims, the circuit's length limits, and the
|
|
4
|
+
* `issBase64Details`-style claim extraction the prover outputs.
|
|
5
|
+
*/
|
|
6
|
+
import * as Effect from "effect/Effect"
|
|
7
|
+
import * as Result from "effect/Result"
|
|
8
|
+
import * as Schema from "effect/Schema"
|
|
9
|
+
import { InvalidJwt, reasonOf } from "./Errors.ts"
|
|
10
|
+
import { normalizeIssuer } from "./PublicIdentifier.ts"
|
|
11
|
+
|
|
12
|
+
// -----------------------------------------------------------------------------
|
|
13
|
+
// Decoding
|
|
14
|
+
// -----------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
/** The registered claims zkLogin reads; any other claim is kept as `unknown`. */
|
|
17
|
+
export const JwtClaims = Schema.StructWithRest(
|
|
18
|
+
Schema.Struct({
|
|
19
|
+
iss: Schema.NonEmptyString,
|
|
20
|
+
sub: Schema.NonEmptyString,
|
|
21
|
+
/** zkLogin needs a single audience; an array is refused. */
|
|
22
|
+
aud: Schema.NonEmptyString,
|
|
23
|
+
exp: Schema.optionalKey(Schema.Number),
|
|
24
|
+
nbf: Schema.optionalKey(Schema.Number),
|
|
25
|
+
iat: Schema.optionalKey(Schema.Number),
|
|
26
|
+
jti: Schema.optionalKey(Schema.String),
|
|
27
|
+
nonce: Schema.optionalKey(Schema.String)
|
|
28
|
+
}),
|
|
29
|
+
[Schema.Record(Schema.String, Schema.Unknown)]
|
|
30
|
+
)
|
|
31
|
+
export type JwtClaims = typeof JwtClaims.Type
|
|
32
|
+
|
|
33
|
+
export const JwtHeader = Schema.StructWithRest(
|
|
34
|
+
Schema.Struct({
|
|
35
|
+
alg: Schema.optionalKey(Schema.String),
|
|
36
|
+
kid: Schema.optionalKey(Schema.String),
|
|
37
|
+
typ: Schema.optionalKey(Schema.String)
|
|
38
|
+
}),
|
|
39
|
+
[Schema.Record(Schema.String, Schema.Unknown)]
|
|
40
|
+
)
|
|
41
|
+
export type JwtHeader = typeof JwtHeader.Type
|
|
42
|
+
|
|
43
|
+
/** Decoded claims, with `iss` normalized for address derivation and the token's own value in `rawIss`. */
|
|
44
|
+
export type DecodedJwt = JwtClaims & { readonly rawIss: string }
|
|
45
|
+
|
|
46
|
+
const base64UrlDecode = (s: string): string => {
|
|
47
|
+
let b64 = s.replace(/-/g, "+").replace(/_/g, "/")
|
|
48
|
+
switch (b64.length % 4) {
|
|
49
|
+
case 0:
|
|
50
|
+
break
|
|
51
|
+
case 2:
|
|
52
|
+
b64 += "=="
|
|
53
|
+
break
|
|
54
|
+
case 3:
|
|
55
|
+
b64 += "="
|
|
56
|
+
break
|
|
57
|
+
default:
|
|
58
|
+
throw new Error("base64 string is not of the correct length")
|
|
59
|
+
}
|
|
60
|
+
const binary = atob(b64)
|
|
61
|
+
const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0))
|
|
62
|
+
try {
|
|
63
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes)
|
|
64
|
+
} catch {
|
|
65
|
+
return binary
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const part = (jwt: string, index: 0 | 1): Result.Result<unknown, InvalidJwt> => {
|
|
70
|
+
const segment = jwt.split(".")[index]
|
|
71
|
+
if (segment === undefined) return Result.fail(new InvalidJwt({ reason: `missing part #${index + 1}` }))
|
|
72
|
+
let text: string
|
|
73
|
+
try {
|
|
74
|
+
text = base64UrlDecode(segment)
|
|
75
|
+
} catch (e) {
|
|
76
|
+
return Result.fail(new InvalidJwt({ reason: `invalid base64 for part #${index + 1} (${reasonOf(e)})` }))
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
return Result.succeed(JSON.parse(text))
|
|
80
|
+
} catch (e) {
|
|
81
|
+
return Result.fail(new InvalidJwt({ reason: `invalid json for part #${index + 1} (${reasonOf(e)})` }))
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const decodeClaims = Schema.decodeUnknownResult(JwtClaims)
|
|
86
|
+
const decodeHeaderSchema = Schema.decodeUnknownResult(JwtHeader)
|
|
87
|
+
|
|
88
|
+
/** Decode a JWT's payload. The signature is not checked: the zk proof is what binds the token. */
|
|
89
|
+
export const decode = (jwt: string): Effect.Effect<DecodedJwt, InvalidJwt> =>
|
|
90
|
+
Effect.fromResult(
|
|
91
|
+
Result.flatMap(part(jwt, 1), (json) =>
|
|
92
|
+
Result.match(decodeClaims(json), {
|
|
93
|
+
onFailure: (e) => Result.fail(new InvalidJwt({ reason: e.message })),
|
|
94
|
+
onSuccess: (claims) => Result.succeed({ ...claims, iss: normalizeIssuer(claims.iss), rawIss: claims.iss })
|
|
95
|
+
}))
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
/** Decode a JWT's header. */
|
|
99
|
+
export const decodeHeader = (jwt: string): Effect.Effect<JwtHeader, InvalidJwt> =>
|
|
100
|
+
Effect.fromResult(
|
|
101
|
+
Result.flatMap(part(jwt, 0), (json) =>
|
|
102
|
+
Result.mapError(decodeHeaderSchema(json), (e) => new InvalidJwt({ reason: e.message })))
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
// -----------------------------------------------------------------------------
|
|
106
|
+
// Circuit limits
|
|
107
|
+
// -----------------------------------------------------------------------------
|
|
108
|
+
|
|
109
|
+
export const MAX_HEADER_LEN_B64 = 279
|
|
110
|
+
export const MAX_PADDED_UNSIGNED_JWT_LEN = 64 * 30
|
|
111
|
+
|
|
112
|
+
/** The header and the SHA-256-padded `header.payload` must fit the circuit. */
|
|
113
|
+
export const lengthChecks = (jwt: string): Effect.Effect<void, InvalidJwt> => {
|
|
114
|
+
const [header = "", payload = ""] = jwt.split(".")
|
|
115
|
+
if (header.length > MAX_HEADER_LEN_B64) return Effect.fail(new InvalidJwt({ reason: "Header is too long" }))
|
|
116
|
+
const L = (header.length + 1 + payload.length) * 8
|
|
117
|
+
const K = (512 + 448 - ((L % 512) + 1)) % 512
|
|
118
|
+
const padded = (L + 1 + K + 64) / 8
|
|
119
|
+
return padded > MAX_PADDED_UNSIGNED_JWT_LEN ? Effect.fail(new InvalidJwt({ reason: "JWT is too long" })) : Effect.void
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// -----------------------------------------------------------------------------
|
|
123
|
+
// Claims as the prover reports them
|
|
124
|
+
// -----------------------------------------------------------------------------
|
|
125
|
+
|
|
126
|
+
/** A claim's base64url slice of the payload and its offset mod 4 (`issBase64Details`). */
|
|
127
|
+
export interface Claim {
|
|
128
|
+
readonly value: string
|
|
129
|
+
readonly indexMod4: number
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
|
|
133
|
+
|
|
134
|
+
/** Decode a base64url slice that started at offset `i` of the full string. */
|
|
135
|
+
const decodeBase64UrlSlice = (s: string, i: number): string => {
|
|
136
|
+
if (s.length < 2) throw new Error(`Input (s = ${s}) is not tightly packed because s.length < 2`)
|
|
137
|
+
const bits: Array<number> = []
|
|
138
|
+
for (const ch of s) {
|
|
139
|
+
const index = ALPHABET.indexOf(ch)
|
|
140
|
+
if (index === -1) throw new Error("Invalid base64Url character: " + ch)
|
|
141
|
+
for (let b = 5; b >= 0; b--) bits.push((index >> b) & 1)
|
|
142
|
+
}
|
|
143
|
+
let start = 0
|
|
144
|
+
let end = bits.length
|
|
145
|
+
const first = i % 4
|
|
146
|
+
if (first === 1) start = 2
|
|
147
|
+
else if (first === 2) start = 4
|
|
148
|
+
else if (first === 3) throw new Error(`Input (s = ${s}) is not tightly packed because i%4 = 3 (i = ${i}))`)
|
|
149
|
+
const last = (i + s.length - 1) % 4
|
|
150
|
+
if (last === 2) end -= 2
|
|
151
|
+
else if (last === 1) end -= 4
|
|
152
|
+
else if (last === 0) {
|
|
153
|
+
throw new Error(`Input (s = ${s}) is not tightly packed because (i + s.length - 1)%4 = 0 (i = ${i}))`)
|
|
154
|
+
}
|
|
155
|
+
const used = bits.slice(start, end)
|
|
156
|
+
const bytes = new Uint8Array(used.length / 8)
|
|
157
|
+
for (let k = 0; k < bytes.length; k++) {
|
|
158
|
+
let byte = 0
|
|
159
|
+
for (let b = 0; b < 8; b++) byte = (byte << 1) | used[k * 8 + b]!
|
|
160
|
+
bytes[k] = byte
|
|
161
|
+
}
|
|
162
|
+
return new TextDecoder().decode(bytes)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** @internal */
|
|
166
|
+
export const extractClaimValueUnsafe = (claim: Claim, claimName: string): unknown => {
|
|
167
|
+
const extended = decodeBase64UrlSlice(claim.value, claim.indexMod4)
|
|
168
|
+
const last = extended.slice(-1)
|
|
169
|
+
if (last !== "}" && last !== ",") throw new Error("Invalid claim")
|
|
170
|
+
const json = JSON.parse("{" + extended.slice(0, -1) + "}") as Record<string, unknown>
|
|
171
|
+
const keys = Object.keys(json)
|
|
172
|
+
if (keys.length !== 1) throw new Error("Invalid claim")
|
|
173
|
+
if (keys[0] !== claimName) throw new Error(`Invalid field name: found ${keys[0]} expected ${claimName}`)
|
|
174
|
+
return json[claimName]
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The value of a claim from its base64 details, checking the claim's name. */
|
|
178
|
+
export const extractClaimValue = (claim: Claim, claimName: string): Effect.Effect<unknown, InvalidJwt> =>
|
|
179
|
+
Effect.try({ try: () => extractClaimValueUnsafe(claim, claimName), catch: (e) => new InvalidJwt({ reason: reasonOf(e) }) })
|
|
180
|
+
|
|
181
|
+
/** @internal The issuer named by `issBase64Details`. */
|
|
182
|
+
export const issuerOfUnsafe = (claim: Claim): string => {
|
|
183
|
+
const iss = extractClaimValueUnsafe(claim, "iss")
|
|
184
|
+
if (typeof iss !== "string") throw new Error("iss claim is not a string")
|
|
185
|
+
return iss
|
|
186
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OAuth nonce that binds a JWT to an ephemeral key:
|
|
3
|
+
* `base64url(poseidon(pk_hi, pk_lo, maxEpoch, randomness))` where `pk` is the
|
|
4
|
+
* ephemeral key's `flag || bytes` read as a big-endian integer.
|
|
5
|
+
*/
|
|
6
|
+
import { base64urlnopad } from "@scure/base"
|
|
7
|
+
import type * as SignatureScheme from "../SignatureScheme.ts"
|
|
8
|
+
import * as Effect from "effect/Effect"
|
|
9
|
+
import { poseidon4 } from "poseidon-lite/poseidon4"
|
|
10
|
+
import { InvalidZkLoginInput, reasonOf } from "./Errors.ts"
|
|
11
|
+
import * as Parse from "./internal/parse.ts"
|
|
12
|
+
import * as Core from "./internal/poseidon.ts"
|
|
13
|
+
import { toPaddedBigEndianBytes } from "./PublicIdentifier.ts"
|
|
14
|
+
|
|
15
|
+
/** The nonce hashes four elements: only that arity ships (see `internal/poseidon.ts`). */
|
|
16
|
+
const poseidon = Core.make({ 4: poseidon4 })
|
|
17
|
+
|
|
18
|
+
export const NONCE_LENGTH = 27
|
|
19
|
+
|
|
20
|
+
const toBigIntBE = (bytes: Uint8Array): bigint =>
|
|
21
|
+
bytes.length === 0 ? 0n : BigInt("0x" + Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(""))
|
|
22
|
+
|
|
23
|
+
/** 16 random bytes as a decimal string, the form provers and Enoki use. */
|
|
24
|
+
export const generateRandomness: Effect.Effect<string> = Effect.sync(() =>
|
|
25
|
+
String(toBigIntBE(crypto.getRandomValues(new Uint8Array(16))))
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
/** The nonce for an ephemeral public key, the proof's `maxEpoch` and the randomness. */
|
|
29
|
+
export const generate = (
|
|
30
|
+
ephemeralPublicKey: SignatureScheme.PublicKey,
|
|
31
|
+
maxEpoch: bigint,
|
|
32
|
+
randomness: bigint | string
|
|
33
|
+
): Effect.Effect<string, InvalidZkLoginInput> =>
|
|
34
|
+
Effect.try({
|
|
35
|
+
try: () => {
|
|
36
|
+
const suiBytes = new Uint8Array(1 + ephemeralPublicKey.bytes.length)
|
|
37
|
+
suiBytes[0] = ephemeralPublicKey.flag
|
|
38
|
+
suiBytes.set(ephemeralPublicKey.bytes, 1)
|
|
39
|
+
const pk = toBigIntBE(suiBytes)
|
|
40
|
+
const hash = poseidon([pk / 2n ** 128n, pk % 2n ** 128n, Parse.epoch(maxEpoch), BigInt(randomness)])
|
|
41
|
+
const nonce = base64urlnopad.encode(toPaddedBigEndianBytes(hash, 20))
|
|
42
|
+
if (nonce.length !== NONCE_LENGTH) throw new Error(`nonce ${nonce} has length ${nonce.length}, expected ${NONCE_LENGTH}`)
|
|
43
|
+
return nonce
|
|
44
|
+
},
|
|
45
|
+
catch: (e) => new InvalidZkLoginInput({ reason: reasonOf(e) })
|
|
46
|
+
})
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Poseidon over BN254, as the zkLogin circuit uses it (`poseidon-lite`).
|
|
3
|
+
* Up to 16 inputs hash directly; 17 to 64 are hashed in chunks of 16 and the
|
|
4
|
+
* chunk hashes hashed again.
|
|
5
|
+
*
|
|
6
|
+
* This module loads all sixteen arities (about 590 KB minified). `Nonce` and
|
|
7
|
+
* the default address-seed path don't import it: they load only the arities
|
|
8
|
+
* the circuit uses (1, 2, 4 and 5).
|
|
9
|
+
*/
|
|
10
|
+
import * as Effect from "effect/Effect"
|
|
11
|
+
import { poseidon1 } from "poseidon-lite/poseidon1"
|
|
12
|
+
import { poseidon10 } from "poseidon-lite/poseidon10"
|
|
13
|
+
import { poseidon11 } from "poseidon-lite/poseidon11"
|
|
14
|
+
import { poseidon12 } from "poseidon-lite/poseidon12"
|
|
15
|
+
import { poseidon13 } from "poseidon-lite/poseidon13"
|
|
16
|
+
import { poseidon14 } from "poseidon-lite/poseidon14"
|
|
17
|
+
import { poseidon15 } from "poseidon-lite/poseidon15"
|
|
18
|
+
import { poseidon16 } from "poseidon-lite/poseidon16"
|
|
19
|
+
import { poseidon2 } from "poseidon-lite/poseidon2"
|
|
20
|
+
import { poseidon3 } from "poseidon-lite/poseidon3"
|
|
21
|
+
import { poseidon4 } from "poseidon-lite/poseidon4"
|
|
22
|
+
import { poseidon5 } from "poseidon-lite/poseidon5"
|
|
23
|
+
import { poseidon6 } from "poseidon-lite/poseidon6"
|
|
24
|
+
import { poseidon7 } from "poseidon-lite/poseidon7"
|
|
25
|
+
import { poseidon8 } from "poseidon-lite/poseidon8"
|
|
26
|
+
import { poseidon9 } from "poseidon-lite/poseidon9"
|
|
27
|
+
import { InvalidZkLoginInput, reasonOf } from "./Errors.ts"
|
|
28
|
+
import * as Core from "./internal/poseidon.ts"
|
|
29
|
+
|
|
30
|
+
export const BN254_FIELD_SIZE = Core.BN254_FIELD_SIZE
|
|
31
|
+
|
|
32
|
+
export type Input = Core.Input
|
|
33
|
+
|
|
34
|
+
/** A Poseidon hash that throws on inputs it can't hash (what `AddressSeedOptions.poseidon` takes). */
|
|
35
|
+
export type Hasher = Core.Hasher
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Poseidon of 1 to 64 field elements, every arity loaded. Throws on inputs
|
|
39
|
+
* outside the field or an unsupported length; `hash` is the `Effect` form.
|
|
40
|
+
*/
|
|
41
|
+
export const hashUnsafe: Hasher = Core.make({
|
|
42
|
+
1: poseidon1,
|
|
43
|
+
2: poseidon2,
|
|
44
|
+
3: poseidon3,
|
|
45
|
+
4: poseidon4,
|
|
46
|
+
5: poseidon5,
|
|
47
|
+
6: poseidon6,
|
|
48
|
+
7: poseidon7,
|
|
49
|
+
8: poseidon8,
|
|
50
|
+
9: poseidon9,
|
|
51
|
+
10: poseidon10,
|
|
52
|
+
11: poseidon11,
|
|
53
|
+
12: poseidon12,
|
|
54
|
+
13: poseidon13,
|
|
55
|
+
14: poseidon14,
|
|
56
|
+
15: poseidon15,
|
|
57
|
+
16: poseidon16
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
/** Poseidon hash of 1 to 64 field elements. */
|
|
61
|
+
export const hash = (inputs: ReadonlyArray<Input>): Effect.Effect<bigint, InvalidZkLoginInput> =>
|
|
62
|
+
Effect.try({ try: () => hashUnsafe(inputs), catch: (e) => new InvalidZkLoginInput({ reason: reasonOf(e) }) })
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The zkLogin public identifier: `len(iss) || iss || addressSeed`, the bytes a
|
|
3
|
+
* zkLogin "public key" has (in multisig, and for address derivation).
|
|
4
|
+
*
|
|
5
|
+
* The seed is 32 bytes big-endian. Before Sui fixed it, seeds with leading
|
|
6
|
+
* zero bytes were stored *unpadded*: those accounts have a different
|
|
7
|
+
* ("legacy") address. Identifier bytes here are always the padded form, as in
|
|
8
|
+
* `@mysten/sui`; legacy-ness is a property of the address you derive.
|
|
9
|
+
*/
|
|
10
|
+
import * as Bytes from "@unconfirmed/effect-bcs/Bytes"
|
|
11
|
+
import * as Address from "../Address.ts"
|
|
12
|
+
import type * as SignatureScheme from "../SignatureScheme.ts"
|
|
13
|
+
import * as Effect from "effect/Effect"
|
|
14
|
+
import * as Result from "effect/Result"
|
|
15
|
+
import { InvalidZkLoginInput, reasonOf } from "./Errors.ts"
|
|
16
|
+
import * as Parse from "./internal/parse.ts"
|
|
17
|
+
import { BN254_FIELD_SIZE } from "./internal/poseidon.ts"
|
|
18
|
+
|
|
19
|
+
export const FLAG = 0x05
|
|
20
|
+
|
|
21
|
+
/** `num` as `width` big-endian bytes, left-padded with zeros (truncated if wider). */
|
|
22
|
+
export const toPaddedBigEndianBytes = (num: bigint, width: number): Uint8Array =>
|
|
23
|
+
Bytes.fromHex(num.toString(16).padStart(width * 2, "0").slice(-width * 2))
|
|
24
|
+
|
|
25
|
+
/** `num` as big-endian bytes without leading zeros (`[0]` for zero). */
|
|
26
|
+
export const toBigEndianBytes = (num: bigint, width: number): Uint8Array => {
|
|
27
|
+
const bytes = toPaddedBigEndianBytes(num, width)
|
|
28
|
+
const first = bytes.findIndex((b) => b !== 0)
|
|
29
|
+
return first === -1 ? new Uint8Array([0]) : bytes.slice(first)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Google's tokens say `accounts.google.com`; addresses use `https://accounts.google.com`. */
|
|
33
|
+
export const normalizeIssuer = (iss: string): string => (iss === "accounts.google.com" ? "https://accounts.google.com" : iss)
|
|
34
|
+
|
|
35
|
+
const seedBytes = (seed: bigint, legacyAddress: boolean) =>
|
|
36
|
+
legacyAddress ? toBigEndianBytes(seed, 32) : toPaddedBigEndianBytes(seed, 32)
|
|
37
|
+
|
|
38
|
+
/** @internal `len || iss || seed`, the seed padded or (legacy) not. Throws on a seed outside the BN254 field. */
|
|
39
|
+
export const encode = (addressSeed: bigint, iss: string, legacyAddress: boolean): Uint8Array => {
|
|
40
|
+
Parse.seed(addressSeed)
|
|
41
|
+
const issBytes = new TextEncoder().encode(normalizeIssuer(iss))
|
|
42
|
+
if (issBytes.length > 255) throw new Error(`issuer is ${issBytes.length} bytes, at most 255 allowed`)
|
|
43
|
+
const seed = seedBytes(addressSeed, legacyAddress)
|
|
44
|
+
const out = new Uint8Array(1 + issBytes.length + seed.length)
|
|
45
|
+
out[0] = issBytes.length
|
|
46
|
+
out.set(issBytes, 1)
|
|
47
|
+
out.set(seed, 1 + issBytes.length)
|
|
48
|
+
return out
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** `make`, synchronously: a `Result` instead of an `Effect`. */
|
|
52
|
+
export const makeResult = (addressSeed: bigint, iss: string): Result.Result<Uint8Array, InvalidZkLoginInput> =>
|
|
53
|
+
Result.try({ try: () => encode(addressSeed, iss, false), catch: (e) => new InvalidZkLoginInput({ reason: reasonOf(e) }) })
|
|
54
|
+
|
|
55
|
+
/** The (padded) public identifier for an address seed and issuer. */
|
|
56
|
+
export const make = (addressSeed: bigint, iss: string): Effect.Effect<Uint8Array, InvalidZkLoginInput> =>
|
|
57
|
+
Effect.fromResult(makeResult(addressSeed, iss))
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Identifier bytes as a zkLogin `PublicKey` (flag 0x05): a multisig member, or the key
|
|
61
|
+
* `SignatureScheme.toSuiBytes` / `Address.fromPublicKey` take.
|
|
62
|
+
*
|
|
63
|
+
* const pk = Result.map(PublicIdentifier.makeResult(addressSeed, iss), PublicIdentifier.toPublicKey)
|
|
64
|
+
*/
|
|
65
|
+
export const toPublicKey = (bytes: Uint8Array): SignatureScheme.PublicKey => ({ flag: FLAG, bytes })
|
|
66
|
+
|
|
67
|
+
export interface Parsed {
|
|
68
|
+
readonly iss: string
|
|
69
|
+
readonly addressSeed: bigint
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Split identifier bytes into issuer and seed. */
|
|
73
|
+
export const parse = (bytes: Uint8Array): Effect.Effect<Parsed, InvalidZkLoginInput> => {
|
|
74
|
+
const issLength = bytes[0]
|
|
75
|
+
if (issLength === undefined || bytes.length < 1 + issLength + 1) {
|
|
76
|
+
return Effect.fail(new InvalidZkLoginInput({ reason: "public identifier is too short" }))
|
|
77
|
+
}
|
|
78
|
+
const seed = bytes.subarray(1 + issLength)
|
|
79
|
+
if (seed.length > 32) return Effect.fail(new InvalidZkLoginInput({ reason: "address seed is longer than 32 bytes" }))
|
|
80
|
+
const addressSeed = BigInt("0x" + Bytes.toHex(seed))
|
|
81
|
+
if (addressSeed >= BN254_FIELD_SIZE) return Effect.fail(new InvalidZkLoginInput({ reason: "address seed is not in the BN254 field" }))
|
|
82
|
+
return Effect.succeed({ iss: new TextDecoder().decode(bytes.subarray(1, 1 + issLength)), addressSeed })
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** @internal Re-encode identifier bytes with a padded (or legacy) seed. Assumes `bytes` parse. */
|
|
86
|
+
export const normalizeUnsafe = (bytes: Uint8Array, legacyAddress: boolean): Uint8Array => {
|
|
87
|
+
const issEnd = bytes[0]! + 1
|
|
88
|
+
const seedHex = Bytes.toHex(bytes.subarray(issEnd))
|
|
89
|
+
const seed = seedBytes(seedHex.length === 0 ? 0n : BigInt("0x" + seedHex), legacyAddress)
|
|
90
|
+
const out = new Uint8Array(issEnd + seed.length)
|
|
91
|
+
out.set(bytes.subarray(0, issEnd))
|
|
92
|
+
out.set(seed, issEnd)
|
|
93
|
+
return out
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Whether identifier bytes carry an unpadded (legacy) seed. */
|
|
97
|
+
export const isLegacy = (bytes: Uint8Array): boolean => bytes.length !== (bytes[0] ?? 0) + 1 + 32
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The address of identifier bytes: `blake2b256(0x05 || bytes)`. Padded bytes
|
|
101
|
+
* give the current address; pass `legacyAddress: true` for the legacy one.
|
|
102
|
+
* Bytes that are themselves unpadded already derive the legacy address.
|
|
103
|
+
*/
|
|
104
|
+
export const toAddress = (bytes: Uint8Array, options?: { readonly legacyAddress?: boolean }): Address.Address =>
|
|
105
|
+
Address.fromPublicKey(FLAG, options?.legacyAddress ? normalizeUnsafe(bytes, true) : bytes)
|
|
106
|
+
|
|
107
|
+
/** Both addresses an identifier may own. */
|
|
108
|
+
export const addresses = (bytes: Uint8Array): { readonly current: Address.Address; readonly legacy: Address.Address } => ({
|
|
109
|
+
current: Address.fromPublicKey(FLAG, normalizeUnsafe(bytes, false)),
|
|
110
|
+
legacy: Address.fromPublicKey(FLAG, normalizeUnsafe(bytes, true))
|
|
111
|
+
})
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* zkLogin signatures: `0x05 || BCS(ZkLoginSignature)`, where the BCS struct
|
|
3
|
+
* holds the proof inputs, the proof's `maxEpoch` and the ephemeral key's own
|
|
4
|
+
* serialized signature.
|
|
5
|
+
*
|
|
6
|
+
* `ZkLoginSignatureInputs` is both the BCS layout and the Schema for the JSON
|
|
7
|
+
* a prover (or Enoki's `zklogin/zkp`) returns: decode that JSON with it.
|
|
8
|
+
*/
|
|
9
|
+
import * as Bcs from "@unconfirmed/effect-bcs/Bcs"
|
|
10
|
+
import * as Effect from "effect/Effect"
|
|
11
|
+
import * as Result from "effect/Result"
|
|
12
|
+
import { InvalidZkLoginInput, reasonOf } from "./Errors.ts"
|
|
13
|
+
import * as Parse from "./internal/parse.ts"
|
|
14
|
+
import { FLAG } from "./PublicIdentifier.ts"
|
|
15
|
+
|
|
16
|
+
export const ZkLoginSignatureInputs = Bcs.struct({
|
|
17
|
+
proofPoints: Bcs.struct({
|
|
18
|
+
a: Bcs.vector(Bcs.string),
|
|
19
|
+
b: Bcs.vector(Bcs.vector(Bcs.string)),
|
|
20
|
+
c: Bcs.vector(Bcs.string)
|
|
21
|
+
}),
|
|
22
|
+
issBase64Details: Bcs.struct({ value: Bcs.string, indexMod4: Bcs.u8 }),
|
|
23
|
+
headerBase64: Bcs.string,
|
|
24
|
+
addressSeed: Bcs.string
|
|
25
|
+
})
|
|
26
|
+
export type ZkLoginSignatureInputs = typeof ZkLoginSignatureInputs.Type
|
|
27
|
+
|
|
28
|
+
export const ZkLoginSignature = Bcs.struct({
|
|
29
|
+
inputs: ZkLoginSignatureInputs,
|
|
30
|
+
maxEpoch: Bcs.u64,
|
|
31
|
+
userSignature: Bcs.byteVector
|
|
32
|
+
})
|
|
33
|
+
export type ZkLoginSignature = typeof ZkLoginSignature.Type
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The largest serialized body we produce: `@mysten/sui`'s BCS serializer caps
|
|
37
|
+
* a zkLogin signature at 2048 bytes (`{ maxSize: 2048 }`), so we refuse larger
|
|
38
|
+
* ones the same way. This is a serializer limit; no validator limit of this
|
|
39
|
+
* size is confirmed.
|
|
40
|
+
*/
|
|
41
|
+
export const MAX_SIZE = 2048
|
|
42
|
+
|
|
43
|
+
const encodeBody = Bcs.encode(ZkLoginSignature)
|
|
44
|
+
const decodeBody = Bcs.decode(ZkLoginSignature)
|
|
45
|
+
|
|
46
|
+
export interface SerializeInput {
|
|
47
|
+
readonly inputs: ZkLoginSignatureInputs
|
|
48
|
+
/** A u64. */
|
|
49
|
+
readonly maxEpoch: bigint
|
|
50
|
+
/** The ephemeral signer's serialized signature (`flag || sig || pk`). */
|
|
51
|
+
readonly userSignature: Uint8Array
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** `0x05 || BCS(ZkLoginSignature)`. */
|
|
55
|
+
export const serialize = (input: SerializeInput): Effect.Effect<Uint8Array, InvalidZkLoginInput> =>
|
|
56
|
+
Effect.suspend(() => {
|
|
57
|
+
let maxEpoch: bigint
|
|
58
|
+
try {
|
|
59
|
+
maxEpoch = Parse.epoch(input.maxEpoch)
|
|
60
|
+
} catch (e) {
|
|
61
|
+
return Effect.fail(new InvalidZkLoginInput({ reason: reasonOf(e) }))
|
|
62
|
+
}
|
|
63
|
+
return Result.match(encodeBody({ inputs: input.inputs, maxEpoch, userSignature: input.userSignature }), {
|
|
64
|
+
onFailure: (e) => Effect.fail(new InvalidZkLoginInput({ reason: e.message })),
|
|
65
|
+
onSuccess: (body) => {
|
|
66
|
+
if (body.length > MAX_SIZE) {
|
|
67
|
+
return Effect.fail(new InvalidZkLoginInput({ reason: `signature is ${body.length} bytes, at most ${MAX_SIZE}` }))
|
|
68
|
+
}
|
|
69
|
+
const out = new Uint8Array(1 + body.length)
|
|
70
|
+
out[0] = FLAG
|
|
71
|
+
out.set(body, 1)
|
|
72
|
+
return Effect.succeed(out)
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
/** Parse the BCS body (everything after the flag byte). */
|
|
78
|
+
export const parseBody = (body: Uint8Array): Effect.Effect<ZkLoginSignature, InvalidZkLoginInput> =>
|
|
79
|
+
Result.match(decodeBody(body), {
|
|
80
|
+
onFailure: (e) => Effect.fail(new InvalidZkLoginInput({ reason: `malformed zkLogin signature: ${e.message}` })),
|
|
81
|
+
onSuccess: Effect.succeed
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
/** Parse a serialized zkLogin signature (`0x05 || ...`). */
|
|
85
|
+
export const parse = (serialized: Uint8Array): Effect.Effect<ZkLoginSignature, InvalidZkLoginInput> =>
|
|
86
|
+
serialized[0] === FLAG
|
|
87
|
+
? parseBody(serialized.subarray(1))
|
|
88
|
+
: Effect.fail(new InvalidZkLoginInput({ reason: "not a zkLogin signature (flag 0x05)" }))
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* zkLogin for `@unconfirmed/effect-sui`: a `SignatureScheme` (flag 0x05) to install
|
|
3
|
+
* in the registry and a `Signer` that wraps any ephemeral `Signer`.
|
|
4
|
+
*
|
|
5
|
+
* SignatureSchemes.layer(Ed25519.scheme, ZkLogin.scheme, MultiSig.scheme)
|
|
6
|
+
* .pipe(Layer.provide(ZkLoginVerifierGrpc.layer), Layer.provide(GrpcWeb.layer({ url })))
|
|
7
|
+
*
|
|
8
|
+
* const signer = yield* ZkLogin.signer({ ephemeral, inputs, maxEpoch })
|
|
9
|
+
* yield* Tx.run(recipe, { signer })
|
|
10
|
+
*
|
|
11
|
+
* Verification needs chain state, so `scheme` requires `ZkLoginVerifier`;
|
|
12
|
+
* that requirement is carried by the registry layer until you provide it.
|
|
13
|
+
* Because the scheme has `verifyMember`, multisigs with zkLogin members verify
|
|
14
|
+
* through the same registry.
|
|
15
|
+
*/
|
|
16
|
+
import type * as Address from "../Address.ts"
|
|
17
|
+
import * as SignatureScheme from "../SignatureScheme.ts"
|
|
18
|
+
import * as Signer from "../Signer.ts"
|
|
19
|
+
import * as Effect from "effect/Effect"
|
|
20
|
+
import { reasonOf } from "./Errors.ts"
|
|
21
|
+
import * as Parse from "./internal/parse.ts"
|
|
22
|
+
import { issuerOfUnsafe } from "./Jwt.ts"
|
|
23
|
+
import * as PublicIdentifier from "./PublicIdentifier.ts"
|
|
24
|
+
import * as Signature from "./Signature.ts"
|
|
25
|
+
import { ZkLoginVerifier } from "./ZkLoginVerifier.ts"
|
|
26
|
+
import * as Bytes from "@unconfirmed/effect-bcs/Bytes"
|
|
27
|
+
|
|
28
|
+
export const FLAG = PublicIdentifier.FLAG
|
|
29
|
+
const NAME = "ZkLogin"
|
|
30
|
+
|
|
31
|
+
const invalid = (reason: string) => new SignatureScheme.InvalidSignature({ scheme: NAME, reason })
|
|
32
|
+
|
|
33
|
+
/** @internal The padded public identifier a signature's proof inputs commit to. */
|
|
34
|
+
const identifierOf = (inputs: Signature.ZkLoginSignatureInputs): Uint8Array =>
|
|
35
|
+
PublicIdentifier.encode(Parse.seed(inputs.addressSeed), issuerOfUnsafe(inputs.issBase64Details), false)
|
|
36
|
+
|
|
37
|
+
const parse = (body: Uint8Array) =>
|
|
38
|
+
Effect.flatMap(
|
|
39
|
+
Effect.mapError(Signature.parseBody(body), (e) => invalid(e.reason)),
|
|
40
|
+
(sig) =>
|
|
41
|
+
Effect.try({
|
|
42
|
+
try: () => ({ sig, identifier: identifierOf(sig.inputs) }),
|
|
43
|
+
catch: (e) => invalid(`invalid proof inputs: ${reasonOf(e)}`)
|
|
44
|
+
})
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
const ask = (signature: Uint8Array, intentMessage: Uint8Array, address: Address.Address) =>
|
|
48
|
+
Effect.flatMap(Effect.service(ZkLoginVerifier), (v) => v.verify({ signature, intentMessage, address }))
|
|
49
|
+
|
|
50
|
+
const withFlag = (body: Uint8Array) => {
|
|
51
|
+
const out = new Uint8Array(1 + body.length)
|
|
52
|
+
out[0] = FLAG
|
|
53
|
+
out.set(body, 1)
|
|
54
|
+
return out
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
export const scheme: SignatureScheme.SignatureScheme<ZkLoginVerifier> = {
|
|
59
|
+
name: NAME,
|
|
60
|
+
flag: FLAG,
|
|
61
|
+
// The address of identifier bytes as given: padded bytes give the current
|
|
62
|
+
// address, unpadded (legacy) bytes the legacy one, as in `@mysten/sui`.
|
|
63
|
+
address: (publicKey) => PublicIdentifier.toAddress(publicKey),
|
|
64
|
+
verify: (body, intentMessage) =>
|
|
65
|
+
Effect.gen(function*() {
|
|
66
|
+
const { identifier } = yield* parse(body)
|
|
67
|
+
yield* ask(withFlag(body), intentMessage, PublicIdentifier.toAddress(identifier))
|
|
68
|
+
return { flag: FLAG, bytes: identifier }
|
|
69
|
+
}),
|
|
70
|
+
// Both derivations an identifier may own: current (padded seed) and legacy (unpadded).
|
|
71
|
+
addresses: (publicKey) => {
|
|
72
|
+
const { current, legacy } = PublicIdentifier.addresses(publicKey)
|
|
73
|
+
return current === legacy ? [current] : [current, legacy]
|
|
74
|
+
},
|
|
75
|
+
verifyMember: (publicKey, signature, intentMessage) =>
|
|
76
|
+
Effect.gen(function*() {
|
|
77
|
+
// Sui stores a zkLogin member's signature in full, `0x05 || body`, and so does the
|
|
78
|
+
// multisig scheme when it hands it to us. Anything else is refused, as validators do.
|
|
79
|
+
if (signature[0] !== FLAG) return yield* invalid("member signature is not a serialized zkLogin signature (0x05 || body)")
|
|
80
|
+
const body = signature.subarray(1)
|
|
81
|
+
const { identifier } = yield* parse(body)
|
|
82
|
+
const member = yield* Effect.try({
|
|
83
|
+
try: () => PublicIdentifier.normalizeUnsafe(publicKey, false),
|
|
84
|
+
catch: () => invalid("malformed member public identifier")
|
|
85
|
+
})
|
|
86
|
+
if (!Bytes.equal(identifier, member)) return yield* invalid("signature is not from this member's zkLogin identity")
|
|
87
|
+
yield* ask(signature, intentMessage, PublicIdentifier.toAddress(publicKey))
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// -----------------------------------------------------------------------------
|
|
92
|
+
// Signer
|
|
93
|
+
// -----------------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
export interface SignerOptions {
|
|
96
|
+
/** The ephemeral key the JWT's nonce committed to. Any `Signer`. */
|
|
97
|
+
readonly ephemeral: Signer.Signer
|
|
98
|
+
/** The proof inputs from the prover (or Enoki), including `addressSeed`. */
|
|
99
|
+
readonly inputs: Signature.ZkLoginSignatureInputs
|
|
100
|
+
/** The `maxEpoch` the nonce, and so the proof, was made for (a u64). */
|
|
101
|
+
readonly maxEpoch: bigint
|
|
102
|
+
/** The account uses the legacy (unpadded-seed) address. Default `false`. */
|
|
103
|
+
readonly legacyAddress?: boolean
|
|
104
|
+
/** The address you expect; a mismatch (e.g. a wrong `legacyAddress`) is refused. */
|
|
105
|
+
readonly address?: Address.Address
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A `Signer` for a zkLogin account: signs with the ephemeral signer and wraps
|
|
110
|
+
* that signature with the proof. Works anywhere a `Signer` does.
|
|
111
|
+
*/
|
|
112
|
+
export const signer = (options: SignerOptions): Effect.Effect<Signer.Signer, Signer.InvalidKey> =>
|
|
113
|
+
Effect.gen(function*() {
|
|
114
|
+
const refuse = (reason: string) => new Signer.InvalidKey({ scheme: NAME, reason })
|
|
115
|
+
const { identifier, address, maxEpoch } = yield* Effect.try({
|
|
116
|
+
try: () => {
|
|
117
|
+
const iss = issuerOfUnsafe(options.inputs.issBase64Details)
|
|
118
|
+
const seed = Parse.seed(options.inputs.addressSeed)
|
|
119
|
+
return {
|
|
120
|
+
identifier: PublicIdentifier.encode(seed, iss, false),
|
|
121
|
+
address: PublicIdentifier.toAddress(PublicIdentifier.encode(seed, iss, options.legacyAddress ?? false)),
|
|
122
|
+
maxEpoch: Parse.epoch(options.maxEpoch)
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
catch: (e) => refuse(reasonOf(e))
|
|
126
|
+
})
|
|
127
|
+
if (options.address !== undefined && options.address !== address) {
|
|
128
|
+
return yield* refuse(
|
|
129
|
+
`proof does not match the expected address (derived ${address}, expected ${options.address}); check legacyAddress`
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
const { ephemeral, inputs } = options
|
|
133
|
+
return {
|
|
134
|
+
address,
|
|
135
|
+
publicKey: { flag: FLAG, bytes: identifier },
|
|
136
|
+
sign: (intentMessage) =>
|
|
137
|
+
ephemeral.sign(intentMessage).pipe(
|
|
138
|
+
Effect.flatMap((userSignature) =>
|
|
139
|
+
Signature.serialize({ inputs, maxEpoch, userSignature }).pipe(
|
|
140
|
+
Effect.mapError((e) => new Signer.SigningError({ reason: "failed", message: e.reason }))
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
} satisfies Signer.Signer
|
|
145
|
+
})
|