@t3foundry/tasra-sdk 0.0.0-stage → 0.3.0-next.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/CHANGELOG.md +148 -0
- package/LICENSE +202 -0
- package/NOTICE +94 -0
- package/README.md +137 -2
- package/SECURITY.md +115 -0
- package/dist/app/approvals.d.ts +50 -0
- package/dist/app/approvals.js +90 -0
- package/dist/app/authorization.d.ts +19 -0
- package/dist/app/authorization.js +20 -0
- package/dist/app/client.d.ts +231 -0
- package/dist/app/client.js +272 -0
- package/dist/app/creation.d.ts +73 -0
- package/dist/app/creation.js +77 -0
- package/dist/app/deployment.d.ts +36 -0
- package/dist/app/deployment.js +18 -0
- package/dist/app/identity.d.ts +211 -0
- package/dist/app/identity.js +287 -0
- package/dist/app/index.d.ts +22 -0
- package/dist/app/index.js +12 -0
- package/dist/app/manifest.d.ts +74 -0
- package/dist/app/manifest.js +120 -0
- package/dist/app/node.d.ts +30 -0
- package/dist/app/node.js +159 -0
- package/dist/app/ready-slot.d.ts +157 -0
- package/dist/app/ready-slot.js +199 -0
- package/dist/app/tasra-client.d.ts +125 -0
- package/dist/app/tasra-client.js +79 -0
- package/dist/app/viem.d.ts +10 -0
- package/dist/app/viem.js +32 -0
- package/dist/app/wallet.d.ts +126 -0
- package/dist/app/wallet.js +137 -0
- package/dist/auth/dpop.d.ts +86 -0
- package/dist/auth/dpop.js +142 -0
- package/dist/auth/holderProof.d.ts +102 -0
- package/dist/auth/holderProof.js +161 -0
- package/dist/auth/identityScope.d.ts +19 -0
- package/dist/auth/identityScope.js +82 -0
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.js +13 -0
- package/dist/auth/oid4vp.d.ts +230 -0
- package/dist/auth/oid4vp.js +780 -0
- package/dist/auth/rego/wasm/PINS.json +11 -0
- package/dist/auth/rego/wasm/keykeeper_rego_wasm.d.ts +76 -0
- package/dist/auth/rego/wasm/keykeeper_rego_wasm.js +379 -0
- package/dist/auth/rego/wasm/keykeeper_rego_wasm_bg.wasm +0 -0
- package/dist/auth/rego.d.ts +192 -0
- package/dist/auth/rego.js +492 -0
- package/dist/auth/verifier.d.ts +166 -0
- package/dist/auth/verifier.js +211 -0
- package/dist/chain/abis/accountantSetRegistry.d.ts +441 -0
- package/dist/chain/abis/accountantSetRegistry.js +574 -0
- package/dist/chain/abis/accountantSlashing.d.ts +2071 -0
- package/dist/chain/abis/accountantSlashing.js +2670 -0
- package/dist/chain/abis/bondingCurve.d.ts +398 -0
- package/dist/chain/abis/bondingCurve.js +521 -0
- package/dist/chain/abis/equivocationSlasher.d.ts +292 -0
- package/dist/chain/abis/equivocationSlasher.js +379 -0
- package/dist/chain/abis/fixedTasraPriceOracle.d.ts +52 -0
- package/dist/chain/abis/fixedTasraPriceOracle.js +72 -0
- package/dist/chain/abis/index.d.ts +12801 -0
- package/dist/chain/abis/index.js +64 -0
- package/dist/chain/abis/keeperShareRegistry.d.ts +519 -0
- package/dist/chain/abis/keeperShareRegistry.js +675 -0
- package/dist/chain/abis/keyRegistry.d.ts +2421 -0
- package/dist/chain/abis/keyRegistry.js +3114 -0
- package/dist/chain/abis/livenessRegistry.d.ts +402 -0
- package/dist/chain/abis/livenessRegistry.js +524 -0
- package/dist/chain/abis/mockEurc.d.ts +210 -0
- package/dist/chain/abis/mockEurc.js +276 -0
- package/dist/chain/abis/nodeRegistry.d.ts +1630 -0
- package/dist/chain/abis/nodeRegistry.js +2113 -0
- package/dist/chain/abis/platformExecutor.d.ts +328 -0
- package/dist/chain/abis/platformExecutor.js +429 -0
- package/dist/chain/abis/prevrandaoSaltBeacon.d.ts +16 -0
- package/dist/chain/abis/prevrandaoSaltBeacon.js +24 -0
- package/dist/chain/abis/serviceRegistry.d.ts +556 -0
- package/dist/chain/abis/serviceRegistry.js +719 -0
- package/dist/chain/abis/settlement.d.ts +1624 -0
- package/dist/chain/abis/settlement.js +2096 -0
- package/dist/chain/abis/tasraSwapRouter.d.ts +92 -0
- package/dist/chain/abis/tasraSwapRouter.js +122 -0
- package/dist/chain/abis/tasraToken.d.ts +455 -0
- package/dist/chain/abis/tasraToken.js +599 -0
- package/dist/chain/abis/tasraVestingVault.d.ts +165 -0
- package/dist/chain/abis/tasraVestingVault.js +215 -0
- package/dist/chain/abis/thresholdRandomBeacon.d.ts +378 -0
- package/dist/chain/abis/thresholdRandomBeacon.js +494 -0
- package/dist/chain/abis/treasury.d.ts +301 -0
- package/dist/chain/abis/treasury.js +390 -0
- package/dist/chain/abis/verifierSetRegistry.d.ts +445 -0
- package/dist/chain/abis/verifierSetRegistry.js +579 -0
- package/dist/chain/client.d.ts +212 -0
- package/dist/chain/client.js +576 -0
- package/dist/chain/commitmentRecovery.d.ts +21 -0
- package/dist/chain/commitmentRecovery.js +44 -0
- package/dist/chain/committeeClient.d.ts +102 -0
- package/dist/chain/committeeClient.js +137 -0
- package/dist/chain/deployments.d.ts +56 -0
- package/dist/chain/deployments.js +269 -0
- package/dist/chain/discovery.d.ts +49 -0
- package/dist/chain/discovery.js +107 -0
- package/dist/chain/events.d.ts +58 -0
- package/dist/chain/events.js +125 -0
- package/dist/chain/format.d.ts +25 -0
- package/dist/chain/format.js +51 -0
- package/dist/chain/index.d.ts +41 -0
- package/dist/chain/index.js +56 -0
- package/dist/chain/manifest.d.ts +165 -0
- package/dist/chain/manifest.js +132 -0
- package/dist/chain/network-profiles.json +75 -0
- package/dist/chain/networks.d.ts +73 -0
- package/dist/chain/networks.js +62 -0
- package/dist/chain/node.d.ts +44 -0
- package/dist/chain/node.js +176 -0
- package/dist/chain/offchain.d.ts +149 -0
- package/dist/chain/offchain.js +73 -0
- package/dist/chain/provisionRule.d.ts +164 -0
- package/dist/chain/provisionRule.js +212 -0
- package/dist/chain/registeredAgent.d.ts +64 -0
- package/dist/chain/registeredAgent.js +140 -0
- package/dist/chain/registeredOperation.d.ts +49 -0
- package/dist/chain/registeredOperation.js +136 -0
- package/dist/chain/registeredRelay.d.ts +206 -0
- package/dist/chain/registeredRelay.js +312 -0
- package/dist/chain/revertReason.d.ts +14 -0
- package/dist/chain/revertReason.js +62 -0
- package/dist/chain/ruleAmendment.d.ts +80 -0
- package/dist/chain/ruleAmendment.js +195 -0
- package/dist/chain/ruleAmendmentCore.d.ts +129 -0
- package/dist/chain/ruleAmendmentCore.js +152 -0
- package/dist/chain/ruleInput.d.ts +10 -0
- package/dist/chain/ruleInput.js +13 -0
- package/dist/chain/serviceIdentity.d.ts +176 -0
- package/dist/chain/serviceIdentity.js +237 -0
- package/dist/chain/serviceProfiles.d.ts +39 -0
- package/dist/chain/serviceProfiles.js +74 -0
- package/dist/chain/services.d.ts +141 -0
- package/dist/chain/services.js +79 -0
- package/dist/chain/slotClient.d.ts +55 -0
- package/dist/chain/slotClient.js +62 -0
- package/dist/chain/slotSeed.d.ts +31 -0
- package/dist/chain/slotSeed.js +98 -0
- package/dist/chain/write.d.ts +431 -0
- package/dist/chain/write.js +958 -0
- package/dist/client/client.d.ts +112 -0
- package/dist/client/client.js +111 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +2 -0
- package/dist/client/session.d.ts +67 -0
- package/dist/client/session.js +238 -0
- package/dist/committee/client.d.ts +284 -0
- package/dist/committee/client.js +351 -0
- package/dist/committee/dual-sign.d.ts +110 -0
- package/dist/committee/dual-sign.js +202 -0
- package/dist/committee/ecdsa.d.ts +36 -0
- package/dist/committee/ecdsa.js +45 -0
- package/dist/committee/extraction.d.ts +82 -0
- package/dist/committee/extraction.js +96 -0
- package/dist/committee/index.d.ts +19 -0
- package/dist/committee/index.js +13 -0
- package/dist/committee/oauth.d.ts +51 -0
- package/dist/committee/oauth.js +90 -0
- package/dist/committee/receipts.d.ts +51 -0
- package/dist/committee/receipts.js +59 -0
- package/dist/committee/request.d.ts +264 -0
- package/dist/committee/request.js +305 -0
- package/dist/committee/token.d.ts +274 -0
- package/dist/committee/token.js +418 -0
- package/dist/crypto/constants.d.ts +10 -0
- package/dist/crypto/constants.js +32 -0
- package/dist/crypto/detect.d.ts +20 -0
- package/dist/crypto/detect.js +44 -0
- package/dist/crypto/envelope.d.ts +60 -0
- package/dist/crypto/envelope.js +243 -0
- package/dist/crypto/frost.d.ts +49 -0
- package/dist/crypto/frost.js +152 -0
- package/dist/crypto/hex.d.ts +7 -0
- package/dist/crypto/hex.js +24 -0
- package/dist/crypto/ibe-blob.d.ts +114 -0
- package/dist/crypto/ibe-blob.js +208 -0
- package/dist/crypto/ibe.d.ts +88 -0
- package/dist/crypto/ibe.js +262 -0
- package/dist/crypto/index.d.ts +12 -0
- package/dist/crypto/index.js +12 -0
- package/dist/crypto/kem.d.ts +55 -0
- package/dist/crypto/kem.js +241 -0
- package/dist/decryption/client.d.ts +64 -0
- package/dist/decryption/client.js +82 -0
- package/dist/decryption/index.d.ts +2 -0
- package/dist/decryption/index.js +2 -0
- package/dist/errors.d.ts +124 -0
- package/dist/errors.js +167 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +98 -0
- package/dist/keys/index.d.ts +1 -0
- package/dist/keys/index.js +4 -0
- package/dist/keys/node-client.d.ts +27 -0
- package/dist/keys/node-client.js +97 -0
- package/dist/oid4vp/binding.d.ts +76 -0
- package/dist/oid4vp/binding.js +118 -0
- package/dist/oid4vp/did-web.d.ts +49 -0
- package/dist/oid4vp/did-web.js +57 -0
- package/dist/oid4vp/index.d.ts +9 -0
- package/dist/oid4vp/index.js +10 -0
- package/dist/oid4vp/jose.d.ts +166 -0
- package/dist/oid4vp/jose.js +242 -0
- package/dist/oid4vp/jwe.d.ts +30 -0
- package/dist/oid4vp/jwe.js +93 -0
- package/dist/oid4vp/oid4vci.d.ts +84 -0
- package/dist/oid4vp/oid4vci.js +85 -0
- package/dist/oid4vp/request-object.d.ts +109 -0
- package/dist/oid4vp/request-object.js +96 -0
- package/dist/oid4vp/sd-jwt.d.ts +177 -0
- package/dist/oid4vp/sd-jwt.js +208 -0
- package/dist/oid4vp/verifier-agent.d.ts +161 -0
- package/dist/oid4vp/verifier-agent.js +132 -0
- package/dist/oid4vp/wallet.d.ts +116 -0
- package/dist/oid4vp/wallet.js +108 -0
- package/dist/recipient/store.d.ts +67 -0
- package/dist/recipient/store.js +98 -0
- package/dist/signing/ecdsa.d.ts +49 -0
- package/dist/signing/ecdsa.js +79 -0
- package/dist/signing/frost.d.ts +88 -0
- package/dist/signing/frost.js +145 -0
- package/dist/signing/index.d.ts +4 -0
- package/dist/signing/index.js +3 -0
- package/dist/slots/faucet.d.ts +23 -0
- package/dist/slots/faucet.js +35 -0
- package/dist/slots/index.d.ts +2 -0
- package/dist/slots/index.js +4 -0
- package/dist/verifier-agent/index.d.ts +241 -0
- package/dist/verifier-agent/index.js +411 -0
- package/docs/DEVELOPER-EXPERIENCE.md +62 -0
- package/docs/README.md +33 -0
- package/docs/access-control.md +76 -0
- package/docs/ai-development.md +292 -0
- package/docs/api.md +338 -0
- package/docs/application-api.md +335 -0
- package/docs/architecture.md +65 -0
- package/docs/basics.md +48 -0
- package/docs/capabilities.md +86 -0
- package/docs/chain.md +153 -0
- package/docs/compatibility.md +36 -0
- package/docs/consumer-migrations.md +80 -0
- package/docs/create-slot.md +104 -0
- package/docs/document-signing.md +243 -0
- package/docs/encrypted-notes.md +129 -0
- package/docs/encryption.md +100 -0
- package/docs/errors.md +76 -0
- package/docs/flows.md +289 -0
- package/docs/fuji.md +127 -0
- package/docs/funding.md +126 -0
- package/docs/getting-started.md +94 -0
- package/docs/glossary.md +44 -0
- package/docs/installation.md +132 -0
- package/docs/manage-slot.md +95 -0
- package/docs/native-approvals.md +124 -0
- package/docs/prerequisites.md +137 -0
- package/docs/read-slot.md +41 -0
- package/docs/reference/README.md +30 -0
- package/docs/reference/app-node.md +102 -0
- package/docs/reference/app.md +1737 -0
- package/docs/reference/chain-node.md +159 -0
- package/docs/reference/chain.md +3609 -0
- package/docs/reference/committee.md +2176 -0
- package/docs/reference/main.md +4068 -0
- package/docs/reference/oid4vp.md +2547 -0
- package/docs/reference/verifier-agent.md +498 -0
- package/docs/shared-account.md +168 -0
- package/docs/signing-and-encryption.md +52 -0
- package/docs/signing.md +172 -0
- package/examples/committee-slot.ts +16 -0
- package/examples/connect-fuji.ts +41 -0
- package/examples/connect-network.ts +14 -0
- package/examples/credential-approvals.ts +46 -0
- package/examples/document-signing/README.md +59 -0
- package/examples/document-signing/backend.ts +132 -0
- package/examples/document-signing/build.mjs +19 -0
- package/examples/document-signing/config.ts +34 -0
- package/examples/document-signing/gitignore.template +9 -0
- package/examples/document-signing/model.ts +140 -0
- package/examples/document-signing/network.ts +58 -0
- package/examples/document-signing/package.json +25 -0
- package/examples/document-signing/public/index.html +27 -0
- package/examples/document-signing/public/sample.pdf +31 -0
- package/examples/document-signing/public/styles.css +531 -0
- package/examples/document-signing/server.ts +358 -0
- package/examples/document-signing/setup.ts +111 -0
- package/examples/document-signing/store.ts +105 -0
- package/examples/document-signing/tsconfig.json +24 -0
- package/examples/document-signing/verify.ts +24 -0
- package/examples/document-signing/web/app.ts +312 -0
- package/examples/document-signing/web/preview.ts +67 -0
- package/examples/document-signing/web/wallet.ts +146 -0
- package/examples/document-signing/workflow.test.ts +228 -0
- package/examples/document-signing/workflow.ts +241 -0
- package/examples/document-signing.ts +96 -0
- package/examples/encrypted-notes.ts +86 -0
- package/examples/ethers-signer.ts +204 -0
- package/examples/fund-slot.ts +73 -0
- package/examples/getting-started.ts +25 -0
- package/examples/learning-authorize.ts +23 -0
- package/examples/learning-cancel-slot.ts +11 -0
- package/examples/learning-context.ts +28 -0
- package/examples/learning-create-slot.ts +25 -0
- package/examples/learning-read-slot.ts +8 -0
- package/examples/learning-renew-slot.ts +12 -0
- package/examples/learning-sign.ts +8 -0
- package/examples/live-config.ts +71 -0
- package/examples/minimal.ts +6 -0
- package/examples/native-approvals.ts +57 -0
- package/examples/network.ts +58 -0
- package/examples/offline.ts +16 -0
- package/examples/personal-vault.ts +20 -0
- package/examples/provision-slot.ts +47 -0
- package/examples/shared-account.ts +46 -0
- package/examples/slot-address.ts +13 -0
- package/examples/slot-creation.ts +9 -0
- package/examples/tutorial-negative.ts +26 -0
- package/examples/tutorial-support.ts +76 -0
- package/examples/viem-account.ts +203 -0
- package/package.json +303 -4
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { equalBytes } from '@noble/curves/utils.js';
|
|
2
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
3
|
+
import { recoverAddress, toHex } from 'viem';
|
|
4
|
+
import { createTasraChainClient } from '../chain/client.js';
|
|
5
|
+
import { addressFromEoaPubkey } from '../signing/ecdsa.js';
|
|
6
|
+
import { verify } from '../crypto/frost.js';
|
|
7
|
+
import { kemEncrypt } from '../crypto/envelope.js';
|
|
8
|
+
import { TasraError } from '../errors.js';
|
|
9
|
+
import { committeeSign, committeeDecrypt } from '../committee/client.js';
|
|
10
|
+
import { committeeSignEoaDigest } from '../committee/ecdsa.js';
|
|
11
|
+
import { createDualSignClient } from '../committee/dual-sign.js';
|
|
12
|
+
import { auditOperationId, protocolHex, verifyOperationReceipt } from '../committee/receipts.js';
|
|
13
|
+
import { compoundTokenHash, decodeCompoundToken } from '../committee/token.js';
|
|
14
|
+
import { payloadDigestFor, requestHash, decryptPayloadDigest } from '../oid4vp/binding.js';
|
|
15
|
+
import { defineDeployment } from './deployment.js';
|
|
16
|
+
/**
|
|
17
|
+
* An application operation rejected because its deployment, slot, authorization or result failed validation.
|
|
18
|
+
*/
|
|
19
|
+
export class TasraApplicationError extends TasraError {
|
|
20
|
+
code;
|
|
21
|
+
constructor(/** Stable application error category used to choose recovery behavior. */ code, message) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.code = code;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Configure one application client. Construction does no I/O and holds no wallet credentials.
|
|
28
|
+
* Start with `await tasra.slots.ecdsa(slotId)` and `await account.getAddress()`;
|
|
29
|
+
* provide an authorizer only when signing or decrypting.
|
|
30
|
+
* @param config Validated deployment settings and optional transport adapters.
|
|
31
|
+
* @returns A client with read-only checks and authorized slot operations.
|
|
32
|
+
*/
|
|
33
|
+
export function createTasra(config) {
|
|
34
|
+
const deployment = defineDeployment(config.deployment);
|
|
35
|
+
const chain = config.chain ?? createTasraChainClient(deployment);
|
|
36
|
+
for (const name of ['KeyRegistry', 'NodeRegistry']) {
|
|
37
|
+
if (chain.addresses[name]?.toLowerCase() !== deployment.addresses[name].toLowerCase())
|
|
38
|
+
throw new TasraError(`Injected chain client uses a different ${name}`);
|
|
39
|
+
}
|
|
40
|
+
const route = config.keeperUrl ?? ((url) => url), fetchImpl = config.fetchImpl;
|
|
41
|
+
async function assertChain() {
|
|
42
|
+
if (await chain.client.getChainId() !== deployment.chainId)
|
|
43
|
+
throw new TasraApplicationError('CHAIN_MISMATCH', 'RPC chain does not match the application deployment');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Read slot metadata after checking the deployment chain and slot status.
|
|
47
|
+
* @param slotId Identifier of the slot on this deployment.
|
|
48
|
+
*/
|
|
49
|
+
async function get(slotId) {
|
|
50
|
+
protocolHex(slotId, 32, 'slot id');
|
|
51
|
+
await assertChain();
|
|
52
|
+
const s = await chain.readers.keyRegistry.getKeySlot(slotId);
|
|
53
|
+
if (!s.exists)
|
|
54
|
+
throw new TasraApplicationError('SLOT_NOT_FOUND', 'Slot does not exist on this deployment');
|
|
55
|
+
if (s.cancelled)
|
|
56
|
+
throw new TasraApplicationError('SLOT_CANCELLED', 'Slot is cancelled');
|
|
57
|
+
return { slotId, mode: Number(s.mode), epoch: Number(s.epoch), threshold: { k: Number(s.threshold.k), n: Number(s.threshold.n) },
|
|
58
|
+
publicKey: s.publicKey, ready: s.publicKey !== '0x' };
|
|
59
|
+
}
|
|
60
|
+
async function ready(slotId, mode) {
|
|
61
|
+
const s = await get(slotId);
|
|
62
|
+
if (s.mode !== mode)
|
|
63
|
+
throw new TasraApplicationError('WRONG_SLOT_MODE', `Slot mode ${s.mode} does not support this operation`);
|
|
64
|
+
if (!s.ready)
|
|
65
|
+
throw new TasraApplicationError('KEY_NOT_READY', 'Slot key generation has not completed');
|
|
66
|
+
return s;
|
|
67
|
+
}
|
|
68
|
+
async function unchanged(s) {
|
|
69
|
+
const current = await ready(s.slotId, s.mode);
|
|
70
|
+
if (current.epoch !== s.epoch || current.publicKey !== s.publicKey || current.threshold.k !== s.threshold.k || current.threshold.n !== s.threshold.n) {
|
|
71
|
+
throw new TasraApplicationError('SLOT_CHANGED', 'Slot changed while authorization was pending; authorize a new operation');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function keepers(slotId) {
|
|
75
|
+
const assigned = await chain.readers.keyRegistry.assignedNodes(slotId);
|
|
76
|
+
const nodes = await Promise.all(assigned.map(async (operator) => {
|
|
77
|
+
const [node, id] = await Promise.all([chain.readers.nodeRegistry.nodeOf(operator), chain.readers.nodeRegistry.operatorIdOf(operator)]);
|
|
78
|
+
return { operator, nodeUrl: route(node.url), publicKey: protocolHex(node.pubkey, 32, 'keeper identity key'), id };
|
|
79
|
+
}));
|
|
80
|
+
if (!nodes.length)
|
|
81
|
+
throw new TasraError('Slot has no assigned keepers');
|
|
82
|
+
if (deployment.coordinator === 'lowest-operator-id')
|
|
83
|
+
nodes.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
84
|
+
return nodes;
|
|
85
|
+
}
|
|
86
|
+
async function authorize(s, action, payload, options) {
|
|
87
|
+
options.signal?.throwIfAborted();
|
|
88
|
+
const expectedDigest = payloadDigestFor(action, payload);
|
|
89
|
+
const expected = requestHash(deployment.chainId, protocolHex(s.slotId, 32, 'slot'), action, expectedDigest);
|
|
90
|
+
const grant = structuredClone(await options.authorize(Object.freeze({ chainId: deployment.chainId, keyRegistry: deployment.addresses.KeyRegistry, slotId: s.slotId,
|
|
91
|
+
action, ...payload, message: payload.message?.slice(), payloadDigest: payload.payloadDigest?.slice(),
|
|
92
|
+
description: options.description ?? `Tasra ${action}`, signal: options.signal })));
|
|
93
|
+
options.signal?.throwIfAborted();
|
|
94
|
+
if (grant.token.binding !== 'holder_key' || !Number.isSafeInteger(grant.token.exp) || grant.token.exp * 1000 <= Date.now() ||
|
|
95
|
+
!equalBytes(protocolHex(grant.token.slot_id, 32, 'grant slot'), protocolHex(s.slotId, 32, 'slot')) ||
|
|
96
|
+
!equalBytes(protocolHex(grant.token.request_hash, 32, 'request hash'), expected) || !grant.verifierProofs.length) {
|
|
97
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Grant must be fresh and holder-bound to this exact operation');
|
|
98
|
+
}
|
|
99
|
+
await unchanged(s);
|
|
100
|
+
options.signal?.throwIfAborted();
|
|
101
|
+
return grant;
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
/** Validated configuration for the selected deployment. */
|
|
105
|
+
deployment,
|
|
106
|
+
/** Read-only chain client bound to the selected deployment. */
|
|
107
|
+
chain,
|
|
108
|
+
/** Read-only chain and registry probe. Does not claim keeper/issuer compatibility. */
|
|
109
|
+
async check() {
|
|
110
|
+
await assertChain();
|
|
111
|
+
const entries = await Promise.all(['KeyRegistry', 'NodeRegistry'].map(async (name) => ({ name,
|
|
112
|
+
deployed: ((await chain.client.getCode({ address: deployment.addresses[name] }))?.length ?? 0) > 2 })));
|
|
113
|
+
return { chainId: deployment.chainId, registries: entries, ready: entries.every(e => e.deployed),
|
|
114
|
+
authorization: 'unknown', nativeMultiApproverIbe: 'unsupported', taskContextEnforcement: 'unsupported' };
|
|
115
|
+
},
|
|
116
|
+
/** Slot metadata reads and capability-specific signing or encryption adapters. */
|
|
117
|
+
slots: {
|
|
118
|
+
get,
|
|
119
|
+
/**
|
|
120
|
+
* Open a ready threshold ECDSA slot for verified Ethereum signatures.
|
|
121
|
+
* @param slotId Identifier of the ECDSA slot.
|
|
122
|
+
*/
|
|
123
|
+
async ecdsa(slotId) {
|
|
124
|
+
await ready(slotId, 2);
|
|
125
|
+
const getAddress = async () => addressFromEoaPubkey(protocolHex((await ready(slotId, 2)).publicKey, 33, 'secp256k1 public key'));
|
|
126
|
+
return {
|
|
127
|
+
/** Identifier of the threshold ECDSA slot. */
|
|
128
|
+
slotId,
|
|
129
|
+
/** Recheck slot readiness and derive its Ethereum address from the current public key. */
|
|
130
|
+
getAddress,
|
|
131
|
+
/**
|
|
132
|
+
* Authorize and sign an exact 32-byte Ethereum digest, then verify the recovered account.
|
|
133
|
+
* @param input Exactly 32 digest bytes.
|
|
134
|
+
* @param options Fresh operation authorization and cancellation controls.
|
|
135
|
+
*/
|
|
136
|
+
async signDigest(input, options) {
|
|
137
|
+
if (input.length !== 32)
|
|
138
|
+
throw new TasraError('Ethereum digest must be exactly 32 bytes');
|
|
139
|
+
const digest = input.slice(), s = await ready(slotId, 2);
|
|
140
|
+
const grant = await authorize(s, 'sign', { message: digest }, options), node = (await keepers(slotId))[0];
|
|
141
|
+
options.signal?.throwIfAborted();
|
|
142
|
+
const result = await committeeSignEoaDigest({ nodeUrl: node.nodeUrl, committeeToken: grant.token, verifierProofs: grant.verifierProofs,
|
|
143
|
+
digest, userSignature: options.userSignature, targetKeykeeper: node.operator, signal: options.signal, fetchImpl });
|
|
144
|
+
const publicKey = protocolHex(s.publicKey, 33, 'secp256k1 public key');
|
|
145
|
+
const recovered = await recoverAddress({ hash: toHex(digest), signature: { r: toHex(result.r), s: toHex(result.s), yParity: result.yParity } });
|
|
146
|
+
if (!equalBytes(result.groupPublicKey, publicKey) || recovered.toLowerCase() !== addressFromEoaPubkey(publicKey).toLowerCase())
|
|
147
|
+
throw new TasraApplicationError('INVALID_RESULT', 'Signature does not match the anchored Ethereum account');
|
|
148
|
+
return result;
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
/**
|
|
153
|
+
* Open a ready FROST slot for verified Ed25519 signatures and native approvals.
|
|
154
|
+
* @param slotId Identifier of the FROST slot.
|
|
155
|
+
*/
|
|
156
|
+
async frost(slotId) {
|
|
157
|
+
await ready(slotId, 0);
|
|
158
|
+
return {
|
|
159
|
+
/** Identifier of the FROST signing slot. */
|
|
160
|
+
slotId,
|
|
161
|
+
/**
|
|
162
|
+
* Authorize the exact message and verify the returned signature, epoch and optional receipt.
|
|
163
|
+
* @param input Message bytes to sign.
|
|
164
|
+
* @param options Fresh authorization and optional verified-receipt requirement.
|
|
165
|
+
*/
|
|
166
|
+
async sign(input, options) {
|
|
167
|
+
const message = input.slice(), s = await ready(slotId, 0);
|
|
168
|
+
const grant = await authorize(s, 'sign', { message }, options), node = (await keepers(slotId))[0];
|
|
169
|
+
options.signal?.throwIfAborted();
|
|
170
|
+
const result = await committeeSign({ nodeUrl: node.nodeUrl, committeeToken: grant.token, message, verifierProofs: grant.verifierProofs,
|
|
171
|
+
targetKeykeeper: node.operator, userSignature: options.userSignature, signal: options.signal, fetchImpl });
|
|
172
|
+
const publicKey = protocolHex(s.publicKey, 32, 'FROST public key');
|
|
173
|
+
if (!equalBytes(result.groupPublicKey, publicKey) || !equalBytes(result.messageSha256, sha256(message)) || result.epoch !== s.epoch ||
|
|
174
|
+
!equalBytes(protocolHex(result.keySlotId, 32, 'result slot'), protocolHex(slotId, 32, 'slot')) || !verify(publicKey, message, result.signature)) {
|
|
175
|
+
throw new TasraApplicationError('INVALID_RESULT', 'FROST signature does not match the expected slot, epoch or message');
|
|
176
|
+
}
|
|
177
|
+
const hash = compoundTokenHash(decodeCompoundToken(grant.token)), slot = protocolHex(slotId, 32, 'slot');
|
|
178
|
+
const verified = verifyOperationReceipt(result.receipt, { chainId: deployment.chainId, slotId: slot, tokenHash: hash,
|
|
179
|
+
opId: auditOperationId(slot, 'sign', hash, sha256(message)), keeperPublicKey: node.publicKey });
|
|
180
|
+
if (result.receipt && !verified || options.requireReceipt && !verified)
|
|
181
|
+
throw new TasraApplicationError('INVALID_RESULT', 'Verified keeper receipt required');
|
|
182
|
+
return { ...result, receiptStatus: verified ? 'verified' : 'absent' };
|
|
183
|
+
},
|
|
184
|
+
/** Quorum and approval mode must come from the application's independently pinned policy. */
|
|
185
|
+
async approvals(policy) {
|
|
186
|
+
const s = await ready(slotId, 0), node = (await keepers(slotId))[0];
|
|
187
|
+
return createDualSignClient({ chainId: deployment.chainId, nodeUrl: node.nodeUrl, slotId, groupPublicKey: protocolHex(s.publicKey, 32, 'FROST public key'), ...policy, fetchImpl });
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
},
|
|
191
|
+
/**
|
|
192
|
+
* Open a ready BLS slot for KEM key wrapping and committee-authorized unwrapping.
|
|
193
|
+
* @param slotId Identifier of the BLS slot.
|
|
194
|
+
*/
|
|
195
|
+
async bls(slotId) {
|
|
196
|
+
await ready(slotId, 1);
|
|
197
|
+
const groupKey = (s) => {
|
|
198
|
+
if (![194, 290].includes(s.publicKey.length))
|
|
199
|
+
throw new TasraError('Invalid anchored BLS public key');
|
|
200
|
+
return protocolHex(s.publicKey, (s.publicKey.length - 2) / 2, 'BLS public key').slice(0, 96);
|
|
201
|
+
};
|
|
202
|
+
return {
|
|
203
|
+
/** Identifier of the BLS key-encryption slot. */
|
|
204
|
+
slotId,
|
|
205
|
+
/**
|
|
206
|
+
* BLS KEM-wrap a symmetric data key. Local — no credential or network round-trip needed.
|
|
207
|
+
* @param aad Additional authenticated data binding the key to an application scope.
|
|
208
|
+
* @param dataKey 32-byte symmetric key to wrap under the slot's group public key.
|
|
209
|
+
*/
|
|
210
|
+
async encrypt(aad, dataKey) {
|
|
211
|
+
return kemEncrypt(groupKey(await ready(slotId, 1)), aad, dataKey);
|
|
212
|
+
},
|
|
213
|
+
/**
|
|
214
|
+
* Authorize and recover the KEM-wrapped symmetric key via committee custody decrypt.
|
|
215
|
+
* @param aad Original authenticated data from encryption.
|
|
216
|
+
* @param kemCt BLS KEM ciphertext wrapping the symmetric key.
|
|
217
|
+
* @param options Fresh authorization and optional verified-receipt requirement.
|
|
218
|
+
*/
|
|
219
|
+
async decrypt(aad, kemCt, options) {
|
|
220
|
+
const s = await ready(slotId, 1);
|
|
221
|
+
const pd = decryptPayloadDigest(kemCt.u, kemCt.aeadCt);
|
|
222
|
+
const grant = await authorize(s, 'decrypt', { payloadDigest: pd }, options);
|
|
223
|
+
options.signal?.throwIfAborted();
|
|
224
|
+
const assigned = await keepers(slotId);
|
|
225
|
+
const coordinator = assigned[0];
|
|
226
|
+
// Resolve BLS peer identifiers from each assigned keeper's public info.
|
|
227
|
+
const blsPeers = [];
|
|
228
|
+
for (const k of assigned) {
|
|
229
|
+
try {
|
|
230
|
+
const res = await (fetchImpl ?? fetch)(`${k.nodeUrl}/v1/info`, { signal: options.signal });
|
|
231
|
+
if (res.ok) {
|
|
232
|
+
const info = await res.json();
|
|
233
|
+
if (info.peer_id && info.node_identifier !== undefined) {
|
|
234
|
+
blsPeers.push({ id: info.node_identifier, peerId: info.peer_id });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
catch { /* skip unreachable keepers */ }
|
|
239
|
+
}
|
|
240
|
+
blsPeers.sort((a, b) => a.id - b.id);
|
|
241
|
+
const decryptingSet = blsPeers.slice(0, s.threshold.k).map(p => p.id);
|
|
242
|
+
if (decryptingSet.length < s.threshold.k)
|
|
243
|
+
throw new TasraError('Not enough reachable keeper peers for threshold decryption');
|
|
244
|
+
const plaintext = await committeeDecrypt({
|
|
245
|
+
nodeUrl: coordinator.nodeUrl,
|
|
246
|
+
committeeToken: grant.token,
|
|
247
|
+
verifierProofs: grant.verifierProofs,
|
|
248
|
+
ciphertext: kemCt,
|
|
249
|
+
identity: aad,
|
|
250
|
+
decryptingSet,
|
|
251
|
+
blsPeers,
|
|
252
|
+
ciphertextEpoch: s.epoch,
|
|
253
|
+
userSignature: options.userSignature,
|
|
254
|
+
targetKeykeeper: coordinator.operator,
|
|
255
|
+
fetchImpl,
|
|
256
|
+
});
|
|
257
|
+
return {
|
|
258
|
+
plaintext,
|
|
259
|
+
shareTrust: 'anchored-group',
|
|
260
|
+
evidence: assigned.slice(0, 1).map(k => ({
|
|
261
|
+
operator: k.operator,
|
|
262
|
+
identifier: 0,
|
|
263
|
+
nodeUrl: k.nodeUrl,
|
|
264
|
+
receiptStatus: 'unverified',
|
|
265
|
+
})),
|
|
266
|
+
};
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type Address, type Hex } from 'viem';
|
|
2
|
+
import { type CommitRevealOptions, type CreateSlotArgs, type TasraWriteClient, type WriteClientWalletConfig } from '../chain/write.js';
|
|
3
|
+
import { TasraError } from '../errors.js';
|
|
4
|
+
import { type TasraDeployment } from './deployment.js';
|
|
5
|
+
/**
|
|
6
|
+
* Private durable creation intent and transaction progress required to resume the same slot.
|
|
7
|
+
*/
|
|
8
|
+
export interface SlotCreationJournal {
|
|
9
|
+
/**
|
|
10
|
+
* Creation journal schema version.
|
|
11
|
+
*/
|
|
12
|
+
schemaVersion: 1;
|
|
13
|
+
/**
|
|
14
|
+
* Deployment snapshot saved when the intent was prepared.
|
|
15
|
+
*/
|
|
16
|
+
deployment: TasraDeployment;
|
|
17
|
+
/**
|
|
18
|
+
* Account authorized to commit and reveal this slot.
|
|
19
|
+
*/
|
|
20
|
+
creator: Address;
|
|
21
|
+
/** Private durable data: includes the rule and its salt. Do not put in public evidence. */
|
|
22
|
+
intent: CreateSlotArgs & {
|
|
23
|
+
slotId: Hex;
|
|
24
|
+
salt: Hex;
|
|
25
|
+
ruleSalt: Hex;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Saved commit-submission phase and transaction hash, when known.
|
|
29
|
+
*/
|
|
30
|
+
commit?: {
|
|
31
|
+
phase: 'submitting' | 'submitted' | 'confirmed';
|
|
32
|
+
hash?: Hex;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Saved reveal phase, transaction hash and seed-path choice.
|
|
36
|
+
*/
|
|
37
|
+
reveal?: {
|
|
38
|
+
phase: 'submitting' | 'submitted' | 'confirmed';
|
|
39
|
+
hash?: Hex;
|
|
40
|
+
seeded?: boolean;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Confirmed commit-reveal result after slot creation.
|
|
44
|
+
*/
|
|
45
|
+
result?: Awaited<ReturnType<TasraWriteClient['createSlotCommitReveal']>>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creation paused because the journal has no transaction hash and the submission outcome is unknown. This does not establish whether broadcasting occurred.
|
|
49
|
+
*/
|
|
50
|
+
export declare class CreationReconciliationRequiredError extends TasraError {
|
|
51
|
+
readonly slotId: Hex;
|
|
52
|
+
readonly step: 'commit' | 'reveal';
|
|
53
|
+
constructor(/** Slot whose creation transaction hash must be recovered. */ slotId: Hex, /** Commit or reveal phase whose submission outcome is unknown. */ step: 'commit' | 'reveal');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Prepare without I/O. Save this private journal durably before requesting creation.
|
|
57
|
+
* @param deployment Approved network settings.
|
|
58
|
+
* @param creator Account that will own and create the slot.
|
|
59
|
+
* @param input Key mode, threshold, rule and optional creation policy.
|
|
60
|
+
* @returns Private journal containing the generated slot ID and salts.
|
|
61
|
+
*/
|
|
62
|
+
export declare function prepareSlot(deployment: TasraDeployment, creator: Address, input: CreateSlotArgs): SlotCreationJournal;
|
|
63
|
+
/**
|
|
64
|
+
* Create or resume one persisted slot intent. Persistence must be atomic and runs must be serialized. Saved transaction hashes are observed without resubmission; missing hashes require wallet reconciliation. Cancellation cannot undo a submitted transaction.
|
|
65
|
+
* @param input Private journal returned by prepareSlot or a previous attempt.
|
|
66
|
+
* @param config Creator wallet, durable persistence callback and commit-reveal controls.
|
|
67
|
+
* @returns Updated journal after on-chain creation; key generation and rule provisioning are separate stages.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createPreparedSlot(input: SlotCreationJournal, config: {
|
|
70
|
+
wallet: WriteClientWalletConfig['wallet'];
|
|
71
|
+
persist: (journal: SlotCreationJournal) => Promise<void>;
|
|
72
|
+
options?: Omit<CommitRevealOptions, 'recovery'>;
|
|
73
|
+
}): Promise<SlotCreationJournal>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { requireRule } from '../chain/ruleInput.js';
|
|
2
|
+
import { toHex } from 'viem';
|
|
3
|
+
import { createTasraWriteClient } from '../chain/write.js';
|
|
4
|
+
import { TasraError } from '../errors.js';
|
|
5
|
+
import { protocolHex } from '../committee/receipts.js';
|
|
6
|
+
import { defineDeployment } from './deployment.js';
|
|
7
|
+
/**
|
|
8
|
+
* Creation paused because the journal has no transaction hash and the submission outcome is unknown. This does not establish whether broadcasting occurred.
|
|
9
|
+
*/
|
|
10
|
+
export class CreationReconciliationRequiredError extends TasraError {
|
|
11
|
+
slotId;
|
|
12
|
+
step;
|
|
13
|
+
constructor(/** Slot whose creation transaction hash must be recovered. */ slotId, /** Commit or reveal phase whose submission outcome is unknown. */ step) {
|
|
14
|
+
super(`${step} outcome is unknown for ${slotId}; recover its transaction hash before resuming`);
|
|
15
|
+
this.slotId = slotId;
|
|
16
|
+
this.step = step;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Prepare without I/O. Save this private journal durably before requesting creation.
|
|
21
|
+
* @param deployment Approved network settings.
|
|
22
|
+
* @param creator Account that will own and create the slot.
|
|
23
|
+
* @param input Key mode, threshold, rule and optional creation policy.
|
|
24
|
+
* @returns Private journal containing the generated slot ID and salts.
|
|
25
|
+
*/
|
|
26
|
+
export function prepareSlot(deployment, creator, input) {
|
|
27
|
+
const config = defineDeployment(deployment);
|
|
28
|
+
protocolHex(creator, 20, 'creator');
|
|
29
|
+
if (!Number.isSafeInteger(input.k) || !Number.isSafeInteger(input.n) || input.k < 1 || input.k > input.n || input.n > 65535)
|
|
30
|
+
throw new TasraError('Invalid slot threshold');
|
|
31
|
+
const rule = requireRule(input);
|
|
32
|
+
if (input.exportable)
|
|
33
|
+
throw new TasraError('Prepared creation requires a rule and a non-exportable slot');
|
|
34
|
+
const random = () => toHex(crypto.getRandomValues(new Uint8Array(32)));
|
|
35
|
+
const intent = { ...structuredClone(input), rule, slotId: input.slotId ?? random(), salt: input.salt ?? random(), ruleSalt: input.ruleSalt ?? random(), tags: input.tags?.slice() ?? ['keykeeper'] };
|
|
36
|
+
for (const field of ['slotId', 'salt', 'ruleSalt'])
|
|
37
|
+
protocolHex(intent[field], 32, field);
|
|
38
|
+
return { schemaVersion: 1, deployment: structuredClone(config), creator, intent };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create or resume one persisted slot intent. Persistence must be atomic and runs must be serialized. Saved transaction hashes are observed without resubmission; missing hashes require wallet reconciliation. Cancellation cannot undo a submitted transaction.
|
|
42
|
+
* @param input Private journal returned by prepareSlot or a previous attempt.
|
|
43
|
+
* @param config Creator wallet, durable persistence callback and commit-reveal controls.
|
|
44
|
+
* @returns Updated journal after on-chain creation; key generation and rule provisioning are separate stages.
|
|
45
|
+
*/
|
|
46
|
+
export async function createPreparedSlot(input, config) {
|
|
47
|
+
const journal = structuredClone(input), deployment = defineDeployment(journal.deployment);
|
|
48
|
+
if (journal.schemaVersion !== 1 || !journal.intent.slotId || !journal.intent.ruleSalt || !journal.intent.salt)
|
|
49
|
+
throw new TasraError('Incomplete creation journal');
|
|
50
|
+
prepareSlot(deployment, journal.creator, journal.intent);
|
|
51
|
+
if (config.wallet.account.address.toLowerCase() !== journal.creator.toLowerCase() || config.wallet.chain.id !== deployment.chainId)
|
|
52
|
+
throw new TasraError('Creation wallet differs from the saved creator or chain');
|
|
53
|
+
config.options?.signal?.throwIfAborted();
|
|
54
|
+
for (const step of ['commit', 'reveal']) {
|
|
55
|
+
if (journal[step] && !journal[step].hash)
|
|
56
|
+
throw new CreationReconciliationRequiredError(journal.intent.slotId, step);
|
|
57
|
+
if (journal[step]?.hash)
|
|
58
|
+
protocolHex(journal[step].hash, 32, `${step} hash`);
|
|
59
|
+
}
|
|
60
|
+
if (journal.reveal && !journal.commit)
|
|
61
|
+
throw new TasraError('Reveal journal has no commit');
|
|
62
|
+
const writer = createTasraWriteClient({ rpcUrl: deployment.rpcUrl, addresses: deployment.addresses, chainId: deployment.chainId, wallet: config.wallet });
|
|
63
|
+
if (await writer.pub.getChainId() !== deployment.chainId)
|
|
64
|
+
throw new TasraError('Creation RPC chain differs from the saved deployment');
|
|
65
|
+
// Even a fresh journal is persisted here: a caller cannot accidentally omit the initial save.
|
|
66
|
+
await config.persist(structuredClone(journal));
|
|
67
|
+
const result = await writer.createSlotCommitReveal({ ...journal.intent, ...config.options, recovery: {
|
|
68
|
+
commitTx: journal.commit?.hash, revealTx: journal.reveal?.hash, seeded: journal.reveal?.seeded,
|
|
69
|
+
async onTransaction(event) {
|
|
70
|
+
journal[event.step] = { phase: event.phase, hash: event.hash, ...(event.step === 'reveal' ? { seeded: event.seeded } : {}) };
|
|
71
|
+
await config.persist(structuredClone(journal));
|
|
72
|
+
},
|
|
73
|
+
} });
|
|
74
|
+
journal.result = result;
|
|
75
|
+
await config.persist(structuredClone(journal));
|
|
76
|
+
return journal;
|
|
77
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AddressBook } from '../chain/deployments.js';
|
|
2
|
+
/** Public, versioned application configuration. Never contains credentials or private keys. */
|
|
3
|
+
export interface TasraDeployment {
|
|
4
|
+
/**
|
|
5
|
+
* Deployment descriptor schema version.
|
|
6
|
+
*/
|
|
7
|
+
schemaVersion: 1;
|
|
8
|
+
/**
|
|
9
|
+
* Human-readable deployment identifier.
|
|
10
|
+
*/
|
|
11
|
+
name: string;
|
|
12
|
+
/**
|
|
13
|
+
* EVM chain ID used to bind transactions and authorization.
|
|
14
|
+
*/
|
|
15
|
+
chainId: number;
|
|
16
|
+
/**
|
|
17
|
+
* HTTP or HTTPS JSON-RPC endpoint from the approved network configuration.
|
|
18
|
+
*/
|
|
19
|
+
rpcUrl: string;
|
|
20
|
+
/**
|
|
21
|
+
* Contract addresses resolved from the network manifest.
|
|
22
|
+
*/
|
|
23
|
+
addresses: AddressBook;
|
|
24
|
+
/** Explicit coordinator convention of the tested network build. */
|
|
25
|
+
coordinator: 'lowest-operator-id' | 'assigned-first';
|
|
26
|
+
/** Optional immutable deployment provenance; an active manifest alone is not readiness. */
|
|
27
|
+
provenance?: {
|
|
28
|
+
networkRevision: string;
|
|
29
|
+
manifestSha256?: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validate a caller-approved descriptor. This does not establish its authenticity.
|
|
34
|
+
* @param value Caller-approved public deployment descriptor.
|
|
35
|
+
*/
|
|
36
|
+
export declare function defineDeployment(value: TasraDeployment): Readonly<TasraDeployment>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TasraError } from '../errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validate a caller-approved descriptor. This does not establish its authenticity.
|
|
4
|
+
* @param value Caller-approved public deployment descriptor.
|
|
5
|
+
*/
|
|
6
|
+
export function defineDeployment(value) {
|
|
7
|
+
if (value.schemaVersion !== 1 || !value.name || !Number.isSafeInteger(value.chainId) || value.chainId <= 0 ||
|
|
8
|
+
!['lowest-operator-id', 'assigned-first'].includes(value.coordinator))
|
|
9
|
+
throw new TasraError('Invalid deployment schema, chain or coordinator policy');
|
|
10
|
+
const rpc = new URL(value.rpcUrl);
|
|
11
|
+
if (!['http:', 'https:'].includes(rpc.protocol) || rpc.username || rpc.password || rpc.hash)
|
|
12
|
+
throw new TasraError('Invalid deployment RPC URL');
|
|
13
|
+
for (const name of ['KeyRegistry', 'NodeRegistry']) {
|
|
14
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(value.addresses[name] ?? '') || /^0x0{40}$/i.test(value.addresses[name]))
|
|
15
|
+
throw new TasraError(`Deployment requires ${name}`);
|
|
16
|
+
}
|
|
17
|
+
return Object.freeze({ ...value, addresses: Object.freeze({ ...value.addresses }), ...(value.provenance ? { provenance: Object.freeze({ ...value.provenance }) } : {}) });
|
|
18
|
+
}
|