@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,140 @@
|
|
|
1
|
+
import { verifyFrostSignature, hexToBytes } from '@t3foundry/tasra-sdk'
|
|
2
|
+
export type Hex = `0x${string}`
|
|
3
|
+
export const toHex = (bytes: Uint8Array): Hex =>
|
|
4
|
+
`0x${Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('')}`
|
|
5
|
+
|
|
6
|
+
export const people = ['alice', 'bob'] as const
|
|
7
|
+
export type Person = (typeof people)[number]
|
|
8
|
+
export type Manifest = {
|
|
9
|
+
schema: 'tasra-sign/v1'
|
|
10
|
+
requestId: string
|
|
11
|
+
version: number
|
|
12
|
+
title: string
|
|
13
|
+
documentSha256: string
|
|
14
|
+
chainId: number
|
|
15
|
+
keyRegistry: Hex
|
|
16
|
+
signers: Array<{ name: Person; slotId: Hex }>
|
|
17
|
+
}
|
|
18
|
+
export type Proof = {
|
|
19
|
+
name: Person
|
|
20
|
+
slotId: Hex
|
|
21
|
+
publicKey: Hex
|
|
22
|
+
epoch: number
|
|
23
|
+
r: Hex
|
|
24
|
+
z: Hex
|
|
25
|
+
receiptStatus: 'verified'
|
|
26
|
+
}
|
|
27
|
+
export type Bundle = { manifest: Manifest; signatures: Proof[] }
|
|
28
|
+
export type Phase =
|
|
29
|
+
| 'pending'
|
|
30
|
+
| 'opening'
|
|
31
|
+
| 'awaiting_wallet'
|
|
32
|
+
| 'signing'
|
|
33
|
+
| 'signed'
|
|
34
|
+
| 'refused'
|
|
35
|
+
| 'uncertain'
|
|
36
|
+
export type History = { at: string; event: string; person?: Person }
|
|
37
|
+
export type PublicRequest = {
|
|
38
|
+
manifest: Manifest
|
|
39
|
+
status:
|
|
40
|
+
| 'awaiting_alice'
|
|
41
|
+
| 'awaiting_bob'
|
|
42
|
+
| 'completed'
|
|
43
|
+
| 'cancelled'
|
|
44
|
+
| 'declined'
|
|
45
|
+
signers: Record<
|
|
46
|
+
Person,
|
|
47
|
+
{ phase: Phase; attemptId?: string; signature?: Proof; error?: string }
|
|
48
|
+
>
|
|
49
|
+
history: History[]
|
|
50
|
+
}
|
|
51
|
+
export function statement(manifest: Manifest): Uint8Array {
|
|
52
|
+
// One canonical field order, shared by the browser, backend and verifier.
|
|
53
|
+
return new TextEncoder().encode(
|
|
54
|
+
JSON.stringify({
|
|
55
|
+
schema: manifest.schema,
|
|
56
|
+
requestId: manifest.requestId,
|
|
57
|
+
version: manifest.version,
|
|
58
|
+
title: manifest.title,
|
|
59
|
+
documentSha256: manifest.documentSha256,
|
|
60
|
+
chainId: manifest.chainId,
|
|
61
|
+
keyRegistry: manifest.keyRegistry,
|
|
62
|
+
signers: manifest.signers.map(({ name, slotId }) => ({ name, slotId })),
|
|
63
|
+
}),
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
export async function digest(bytes: Uint8Array): Promise<string> {
|
|
67
|
+
const hash = await crypto.subtle.digest(
|
|
68
|
+
'SHA-256',
|
|
69
|
+
Uint8Array.from(bytes).buffer,
|
|
70
|
+
)
|
|
71
|
+
return Array.from(new Uint8Array(hash), (b) =>
|
|
72
|
+
b.toString(16).padStart(2, '0'),
|
|
73
|
+
).join('')
|
|
74
|
+
}
|
|
75
|
+
export function validateManifest(m: Manifest) {
|
|
76
|
+
if (
|
|
77
|
+
m.schema !== 'tasra-sign/v1' ||
|
|
78
|
+
!/^[0-9a-f-]{36}$/i.test(m.requestId) ||
|
|
79
|
+
!Number.isSafeInteger(m.version) ||
|
|
80
|
+
m.version < 1 ||
|
|
81
|
+
typeof m.title !== 'string' ||
|
|
82
|
+
!m.title.trim() ||
|
|
83
|
+
m.title.length > 120 ||
|
|
84
|
+
!/^[0-9a-f]{64}$/.test(m.documentSha256) ||
|
|
85
|
+
!Number.isSafeInteger(m.chainId) ||
|
|
86
|
+
m.chainId <= 0 ||
|
|
87
|
+
!/^0x[0-9a-f]{40}$/i.test(m.keyRegistry) ||
|
|
88
|
+
m.signers.length !== 2 ||
|
|
89
|
+
new Set(m.signers.map((s) => s.slotId.toLowerCase())).size !== 2 ||
|
|
90
|
+
!people.every(
|
|
91
|
+
(name, i) =>
|
|
92
|
+
m.signers[i]?.name === name &&
|
|
93
|
+
/^0x[0-9a-f]{64}$/i.test(m.signers[i]!.slotId),
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
throw new Error('Invalid document manifest')
|
|
97
|
+
}
|
|
98
|
+
export async function verifyBundle(
|
|
99
|
+
pdf: Uint8Array,
|
|
100
|
+
expected: Manifest,
|
|
101
|
+
bundle: Bundle,
|
|
102
|
+
readKey: (
|
|
103
|
+
id: Hex,
|
|
104
|
+
) => Promise<{
|
|
105
|
+
publicKey: Hex
|
|
106
|
+
epoch: number
|
|
107
|
+
mode: number
|
|
108
|
+
cancelled: boolean
|
|
109
|
+
}>,
|
|
110
|
+
) {
|
|
111
|
+
validateManifest(expected)
|
|
112
|
+
validateManifest(bundle.manifest)
|
|
113
|
+
if (
|
|
114
|
+
(await digest(pdf)) !== expected.documentSha256 ||
|
|
115
|
+
new TextDecoder().decode(statement(expected)) !==
|
|
116
|
+
new TextDecoder().decode(statement(bundle.manifest)) ||
|
|
117
|
+
bundle.signatures.length !== 2 ||
|
|
118
|
+
new Set(bundle.signatures.map((s) => s.name)).size !== 2
|
|
119
|
+
)
|
|
120
|
+
throw new Error('Document or request differs')
|
|
121
|
+
for (const signer of expected.signers) {
|
|
122
|
+
const proof = bundle.signatures.find(
|
|
123
|
+
(s) => s.name === signer.name && s.slotId === signer.slotId,
|
|
124
|
+
)
|
|
125
|
+
if (!proof) throw new Error('Missing assigned signer')
|
|
126
|
+
const key = await readKey(signer.slotId)
|
|
127
|
+
if (
|
|
128
|
+
key.cancelled ||
|
|
129
|
+
key.mode !== 0 ||
|
|
130
|
+
key.epoch !== proof.epoch ||
|
|
131
|
+
key.publicKey.toLowerCase() !== proof.publicKey.toLowerCase() ||
|
|
132
|
+
!verifyFrostSignature(hexToBytes(key.publicKey), statement(expected), {
|
|
133
|
+
r: hexToBytes(proof.r),
|
|
134
|
+
z: hexToBytes(proof.z),
|
|
135
|
+
})
|
|
136
|
+
)
|
|
137
|
+
throw new Error('Invalid or outdated signer proof')
|
|
138
|
+
}
|
|
139
|
+
return true
|
|
140
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Download and validate the public testnet manifest used by these examples. */
|
|
2
|
+
import {readFileSync, writeFileSync} from 'node:fs'
|
|
3
|
+
import {resolve} from 'node:path'
|
|
4
|
+
import {fileURLToPath} from 'node:url'
|
|
5
|
+
import {parsePinnedNetworkManifest} from '@t3foundry/tasra-sdk/chain'
|
|
6
|
+
import {resolveApplicationManifest} from '@t3foundry/tasra-sdk/app'
|
|
7
|
+
|
|
8
|
+
const base = 'https://raw.githubusercontent.com/t3foundry/tasra-releases/main/networks/testnet/'
|
|
9
|
+
type Pin = {sha256: string; manifestUrl: string}
|
|
10
|
+
|
|
11
|
+
/** Fetch the pointer and its checksum-verified manifest, then save the original bytes. */
|
|
12
|
+
export async function downloadNetwork(fetchImpl: typeof fetch = fetch, directory = '.') {
|
|
13
|
+
const download = async (url: string) => {
|
|
14
|
+
const response = await fetchImpl(url, {signal: AbortSignal.timeout(15_000), redirect: 'error'})
|
|
15
|
+
if (!response.ok) throw new Error(`Network manifest download failed: HTTP ${response.status}`)
|
|
16
|
+
return response.text()
|
|
17
|
+
}
|
|
18
|
+
const pointer = JSON.parse(await download(base + 'current.json')) as Record<string, unknown>
|
|
19
|
+
if (pointer.schemaVersion !== 1 || pointer.network !== 'testnet' || pointer.chainId !== 43113 ||
|
|
20
|
+
pointer.status !== 'active' || typeof pointer.manifest !== 'string' ||
|
|
21
|
+
!/^deployments\/[a-z0-9.-]+\.json$/.test(pointer.manifest) ||
|
|
22
|
+
typeof pointer.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(pointer.sha256)) {
|
|
23
|
+
throw new Error('Expected an active testnet pointer with a manifest path and SHA-256')
|
|
24
|
+
}
|
|
25
|
+
const pin = {sha256: pointer.sha256, manifestUrl: base + pointer.manifest}
|
|
26
|
+
const text = await download(pin.manifestUrl)
|
|
27
|
+
checkedManifest(text, pin)
|
|
28
|
+
writeFileSync(resolve(directory, 'network.json'), text)
|
|
29
|
+
writeFileSync(resolve(directory, 'network-pin.json'), JSON.stringify(pin, null, 2) + '\n')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function checkedManifest(text: string, pin: Pin) {
|
|
33
|
+
if (!pin || typeof pin.sha256 !== 'string' || typeof pin.manifestUrl !== 'string' ||
|
|
34
|
+
!pin.manifestUrl.startsWith(base + 'deployments/')) throw new Error('Invalid downloaded manifest pin')
|
|
35
|
+
const manifest = parsePinnedNetworkManifest(text, pin.sha256)
|
|
36
|
+
if (manifest.network !== 'testnet' || manifest.chainId !== 43113 || manifest.status !== 'active') {
|
|
37
|
+
throw new Error('Expected an active testnet manifest')
|
|
38
|
+
}
|
|
39
|
+
return manifest
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Read the saved manifest and verify its bytes before configuring any client. */
|
|
43
|
+
export function loadNetwork(directory = '.') {
|
|
44
|
+
const text = readFileSync(resolve(directory, 'network.json'), 'utf8')
|
|
45
|
+
const pin = JSON.parse(readFileSync(resolve(directory, 'network-pin.json'), 'utf8')) as Pin
|
|
46
|
+
const manifest = checkedManifest(text, pin)
|
|
47
|
+
// Coordinator selection is an explicit application setting, absent from the manifest schema.
|
|
48
|
+
const resolved = resolveApplicationManifest(manifest, {coordinator: 'lowest-operator-id'})
|
|
49
|
+
resolved.deployment = {...resolved.deployment, provenance: {
|
|
50
|
+
networkRevision: `${manifest.deploymentId}@${manifest.revision}`, manifestSha256: pin.sha256,
|
|
51
|
+
}}
|
|
52
|
+
return resolved
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
56
|
+
await downloadNetwork()
|
|
57
|
+
console.log('Saved checksum-verified network.json and network-pin.json from tasra-releases.')
|
|
58
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tasra-document-signing-tutorial",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"setup": "node --import tsx setup.ts",
|
|
7
|
+
"build": "tsc --noEmit && node build.mjs",
|
|
8
|
+
"start": "node --import tsx server.ts",
|
|
9
|
+
"verify": "node --import tsx verify.ts",
|
|
10
|
+
"test": "node --import tsx --test workflow.test.ts"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"pdfjs-dist": "6.3.289",
|
|
14
|
+
"@t3foundry/tasra-sdk": "latest"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/node": "22.19.17",
|
|
18
|
+
"esbuild": "0.25.12",
|
|
19
|
+
"tsx": "4.23.13",
|
|
20
|
+
"typescript": "5.9.3"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=24"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Tasra Sign</title>
|
|
7
|
+
<link rel="stylesheet" href="/styles.css" />
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<header>
|
|
11
|
+
<div class="bar">
|
|
12
|
+
<a class="brand" href="/"
|
|
13
|
+
>Tasra Sign <span class="label">LOCAL DEMO</span></a
|
|
14
|
+
>
|
|
15
|
+
<nav aria-label="Main">
|
|
16
|
+
<a href="/">Documents</a><a href="/verify">Verify</a>
|
|
17
|
+
</nav>
|
|
18
|
+
</div>
|
|
19
|
+
</header>
|
|
20
|
+
<main id="app"><p>Opening your document workspace…</p></main>
|
|
21
|
+
<div id="notice" role="status" aria-live="polite"></div>
|
|
22
|
+
<footer>
|
|
23
|
+
Built with Tasra SDK · Two people. Two independently verified signatures.
|
|
24
|
+
</footer>
|
|
25
|
+
<script type="module" src="/app.js"></script>
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
%PDF-1.4
|
|
2
|
+
1 0 obj
|
|
3
|
+
<</Type/Catalog/Pages 2 0 R>>
|
|
4
|
+
endobj
|
|
5
|
+
2 0 obj
|
|
6
|
+
<</Type/Pages/Count 1/Kids[3 0 R]>>
|
|
7
|
+
endobj
|
|
8
|
+
3 0 obj
|
|
9
|
+
<</Type/Page/Parent 2 0 R/MediaBox[0 0 612 792]/Resources<</Font<</F1 4 0 R>>>>/Contents 5 0 R>>
|
|
10
|
+
endobj
|
|
11
|
+
4 0 obj
|
|
12
|
+
<</Type/Font/Subtype/Type1/BaseFont/Helvetica>>
|
|
13
|
+
endobj
|
|
14
|
+
5 0 obj
|
|
15
|
+
<</Length 75>>
|
|
16
|
+
stream
|
|
17
|
+
BT /F1 18 Tf 72 700 Td (Synthetic agreement: Alice and Bob approve.) Tj ET
|
|
18
|
+
endstream
|
|
19
|
+
endobj
|
|
20
|
+
xref
|
|
21
|
+
0 6
|
|
22
|
+
0000000000 65535 f
|
|
23
|
+
0000000009 00000 n
|
|
24
|
+
0000000054 00000 n
|
|
25
|
+
0000000105 00000 n
|
|
26
|
+
0000000217 00000 n
|
|
27
|
+
0000000280 00000 n
|
|
28
|
+
trailer<</Size 6/Root 1 0 R>>
|
|
29
|
+
startxref
|
|
30
|
+
402
|
|
31
|
+
%%EOF
|