@t3foundry/tasra-sdk 0.0.0-stage → 0.3.1-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,52 @@
|
|
|
1
|
+
# Use your slot
|
|
2
|
+
|
|
3
|
+
**Goal:** sign your first message with the existing slot and Alice's credential.
|
|
4
|
+
Finish [Give a user access](access-control.md) first.
|
|
5
|
+
|
|
6
|
+
Complete [Buy TASRA and fund your slot](funding.md) before signing. A ready key
|
|
7
|
+
and a funded creator wallet do not provide the slot's usage credits.
|
|
8
|
+
|
|
9
|
+
## Sign a message
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
cp node_modules/@t3foundry/tasra-sdk/examples/learning-sign.ts .
|
|
13
|
+
npx tsc --noEmit
|
|
14
|
+
npx tsx learning-sign.ts
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
<!-- learning-sign-example -->
|
|
18
|
+
```ts
|
|
19
|
+
import {authorize} from './learning-authorize.js'
|
|
20
|
+
import {savedSlotId, tasra} from './learning-context.js'
|
|
21
|
+
|
|
22
|
+
const signer = await tasra.slots.frost(await savedSlotId())
|
|
23
|
+
const message = new TextEncoder().encode('I approve this first TASRA example.')
|
|
24
|
+
const result = await signer.sign(message, {authorize})
|
|
25
|
+
console.log('Signature verified:', result.signature)
|
|
26
|
+
console.log('Key epoch:', result.epoch)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Success:** `Signature verified`, followed by the signature and key epoch.
|
|
30
|
+
The SDK requests authorization and verifies the returned signature.
|
|
31
|
+
For a real document, sign a statement containing its digest, version and request ID.
|
|
32
|
+
Keep that statement with the document.
|
|
33
|
+
|
|
34
|
+
## Choose what to build next
|
|
35
|
+
|
|
36
|
+
Each slot has one mode, chosen at creation. Your first slot uses `frost`.
|
|
37
|
+
Create a separate slot for a different kind of key.
|
|
38
|
+
|
|
39
|
+
| Application | Mode | Next tutorial |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| Document approval | `frost` | [Collect document signatures](document-signing.md) |
|
|
42
|
+
| Shared Ethereum account | `ecdsa` | [Let Alice and Bob send transactions](shared-account.md) |
|
|
43
|
+
| Private documents | `bls` | [Encrypt notes for an authorized reader](encrypted-notes.md) |
|
|
44
|
+
|
|
45
|
+
An Ethereum slot signs transactions from one address; that address needs funds for
|
|
46
|
+
transaction fees. Encryption uses a public key, while decryption requires permission.
|
|
47
|
+
Use a new access identity for each encrypted document version. Access expiry cannot
|
|
48
|
+
remove plaintext or decryption keys someone already holds.
|
|
49
|
+
|
|
50
|
+
You have connected, created, funded, inspected and used a slot.
|
|
51
|
+
Continue to [manage your slot](manage-slot.md) to renew it or cancel it when finished.
|
|
52
|
+
You can also choose one application tutorial above.
|
package/docs/signing.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Sign Ethereum transactions (ethers / viem / Hardhat)
|
|
2
|
+
|
|
3
|
+
> Threshold ECDSA for EVM accounts, wired into ethers, viem and Hardhat.
|
|
4
|
+
|
|
5
|
+
## Before you start
|
|
6
|
+
|
|
7
|
+
Load the network manifest from [tasra-releases](https://github.com/t3foundry/tasra-releases).
|
|
8
|
+
You need a **secp256k1 tECDSA slot** (mode 2), completed distributed key generation, and the current registry
|
|
9
|
+
address. BLS, FROST, and P-256 slots cannot serve as Ethereum accounts.
|
|
10
|
+
|
|
11
|
+
Address lookup is public and requires no credential or funded wallet. Signing also
|
|
12
|
+
requires authorization accepted by the keeper, metering funds, and an enabled ECDSA
|
|
13
|
+
route. Broadcasting a transaction requires native gas funds on the slot's address.
|
|
14
|
+
|
|
15
|
+
## Get the Ethereum address
|
|
16
|
+
|
|
17
|
+
After the [quickstart installation](getting-started.md#1-create-the-app), save this as
|
|
18
|
+
**`address.ts`**. It reads the public key from the registry and derives the address;
|
|
19
|
+
no signature is needed. Use the manifest for the network where the slot was created.
|
|
20
|
+
|
|
21
|
+
<!-- slot-address-example -->
|
|
22
|
+
```ts
|
|
23
|
+
import {loadNetwork} from './network.js'
|
|
24
|
+
import {TasraClient} from '@t3foundry/tasra-sdk/app'
|
|
25
|
+
|
|
26
|
+
// Read the checksum-verified manifest downloaded from tasra-releases.
|
|
27
|
+
const network = loadNetwork()
|
|
28
|
+
const tasra = new TasraClient({manifest: network.deployment, verifierAgentUrl: network.verifierAgentUrl})
|
|
29
|
+
const slotId = process.argv[2]
|
|
30
|
+
if (!slotId || !/^0x[0-9a-fA-F]{64}$/.test(slotId)) {
|
|
31
|
+
throw new Error('Usage: npx tsx address.ts <0x-prefixed slot ID>')
|
|
32
|
+
}
|
|
33
|
+
if (!(await tasra.check()).ready) throw new Error('Configured registries are unavailable')
|
|
34
|
+
const slot = await tasra.slots.ecdsa(slotId as `0x${string}`)
|
|
35
|
+
console.log(await slot.getAddress())
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Run `npx tsx address.ts YOUR_SLOT_ID`, replacing `YOUR_SLOT_ID` with your slot's
|
|
39
|
+
0x-prefixed ID. Success prints one checksummed `0x…` Ethereum address.
|
|
40
|
+
|
|
41
|
+
The typed ECDSA handle checks existence, readiness and slot mode. `getAddress()`
|
|
42
|
+
derives the Ethereum address without requiring credentials. Create your own slot
|
|
43
|
+
with the [shared-account tutorial](shared-account.md) before using this lookup.
|
|
44
|
+
|
|
45
|
+
## Sign with credential-based authorization
|
|
46
|
+
|
|
47
|
+
For a complete runnable app, follow [Alice and Bob's shared account](shared-account.md).
|
|
48
|
+
It includes slot creation, issuer/holder keys, rule provisioning and actual receipts.
|
|
49
|
+
Install with `npm install @t3foundry/tasra-sdk@latest`. The application uses
|
|
50
|
+
`tasra.credentials.authorize`, `tasra.wallets.fromSlot` and a named
|
|
51
|
+
`wallet.transfer`; the SDK handles signature verification and durable submission.
|
|
52
|
+
[Compatibility](compatibility.md).
|
|
53
|
+
|
|
54
|
+
## Advanced committee signing adapter
|
|
55
|
+
|
|
56
|
+
The lower-level operation below is for integrations that need explicit control
|
|
57
|
+
over the digest and verifier session.
|
|
58
|
+
|
|
59
|
+
After presenting a credential and obtaining `grant` from `awaitVerifierAgentResult`:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import {committeeSignEoaDigest} from '@t3foundry/tasra-sdk/committee'
|
|
63
|
+
|
|
64
|
+
const signature = await committeeSignEoaDigest({
|
|
65
|
+
nodeUrl: coordinatorUrl,
|
|
66
|
+
committeeToken: grant.token,
|
|
67
|
+
verifierProofs: grant.verifierProofs,
|
|
68
|
+
digest, // Uint8Array: exactly the 32-byte transaction signing hash
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
| Input | Meaning |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `nodeUrl` | A keeper in the slot's active ECDSA signing subset; the example derives its order from on-chain operator IDs. |
|
|
75
|
+
| `committeeToken` | Fresh request-bound authorization for this slot and digest. Open the verifier session with `action: 'sign'` and `message: digest`. |
|
|
76
|
+
| `digest` | 32 bytes to sign. The binding uses SHA-256 of these bytes; ECDSA signs the original digest. |
|
|
77
|
+
| `verifierProofs` | Snapshot membership proofs returned with the authorization, required by the configured network. |
|
|
78
|
+
| `requestId`, `signal` | Optional request correlation and cancellation. |
|
|
79
|
+
| `userSignature`, `targetKeykeeper` | Optional additional owner signature and operator pin for fleets requiring them. |
|
|
80
|
+
|
|
81
|
+
Returns a promise of `{groupPublicKey, r, s, yParity}`. The key is compressed
|
|
82
|
+
secp256k1; `r` and `s` are 32-byte arrays; `yParity` is 0 or 1. Invalid digest lengths,
|
|
83
|
+
non-Ethereum replies, and malformed responses throw. HTTP failures use SDK error
|
|
84
|
+
classes; 401/403 is an authorization denial. The helper does not retry or fall back
|
|
85
|
+
to JWT authorization. Verify signature recovery and transaction receipts as in the tutorial.
|
|
86
|
+
|
|
87
|
+
## JWT-compatible adapters
|
|
88
|
+
|
|
89
|
+
The adapters below use the **JWT-authorized `/v1/sign/eoa-digest` route**. Confirm that
|
|
90
|
+
your fleet supports it. A request-bound verifier-agent compound authorization is not
|
|
91
|
+
a replacement JWT for these adapters. Running their offline self-tests does not
|
|
92
|
+
establish live compatibility.
|
|
93
|
+
|
|
94
|
+
For an EVM project, a **threshold-ECDSA (tECDSA) slot** *is* an Ethereum account
|
|
95
|
+
whose key is split across the fleet — every signature needs k-of-n nodes and no
|
|
96
|
+
machine ever holds the whole key. `signEoaDigest` signs a 32-byte prehash and
|
|
97
|
+
returns Ethereum `{r, s, yParity}`; `addressFromEoaPubkey` derives the EOA's
|
|
98
|
+
EIP-55 address from its secp256k1 group key (using only `@noble`):
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import {signEoaDigest, ethSignatureV, addressFromEoaPubkey} from '@t3foundry/tasra-sdk'
|
|
102
|
+
|
|
103
|
+
const {groupPublicKey, r, s, yParity} = await signEoaDigest({nodeUrl, jwt, slotId, digest})
|
|
104
|
+
const from = addressFromEoaPubkey(groupPublicKey) // 0x… checksummed address
|
|
105
|
+
const v = ethSignatureV(yParity, chainId) // EIP-155 v
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Wrap that in an **ethers v6 `Signer`** and it drops into ethers or Hardhat like any
|
|
109
|
+
key-backed account. `examples/ethers-signer.ts` (shipped with the package) is a complete, copy-paste
|
|
110
|
+
`TasraSigner extends AbstractSigner` (getAddress + signTransaction / signMessage /
|
|
111
|
+
signTypedData), with the JWT supplied by your `getJwt` callback:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import {redeemRenewalToken} from '@t3foundry/tasra-sdk'
|
|
115
|
+
import {TasraSigner} from './tasra-signer' // copied from the package's examples/ethers-signer.ts
|
|
116
|
+
|
|
117
|
+
const signer = new TasraSigner({
|
|
118
|
+
nodes, slotId, // a tECDSA signing slot
|
|
119
|
+
getJwt: async () => (await redeemRenewalToken(verifier, renewalToken)).token,
|
|
120
|
+
}).connect(provider)
|
|
121
|
+
|
|
122
|
+
await signer.getAddress()
|
|
123
|
+
await signer.sendTransaction({to, value}) // signed by the fleet, broadcast via the provider
|
|
124
|
+
|
|
125
|
+
// Hardhat: const c = await ethers.getContractAt(abi, addr, signer.connect(ethers.provider))
|
|
126
|
+
// await c.transfer(to, amount)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Prefer **viem** (and thus wagmi, or an ERC-4337 stack)? `examples/viem-account.ts`
|
|
130
|
+
(shipped with the package) is the same adapter as a viem `LocalAccount` via `toAccount`. viem is
|
|
131
|
+
included by the SDK. If your application imports viem directly, declare it alongside:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import {createWalletClient, http} from 'viem'
|
|
135
|
+
import {redeemRenewalToken} from '@t3foundry/tasra-sdk'
|
|
136
|
+
import {createTasraAccount} from './tasra-account' // copied from the package's examples/viem-account.ts
|
|
137
|
+
|
|
138
|
+
const account = await createTasraAccount({
|
|
139
|
+
nodes, slotId, // a tECDSA signing slot
|
|
140
|
+
getJwt: async () => (await redeemRenewalToken(verifier, renewalToken)).token,
|
|
141
|
+
})
|
|
142
|
+
const wallet = createWalletClient({account, chain, transport: http(rpcUrl)})
|
|
143
|
+
await wallet.sendTransaction({to, value}) // signed by the fleet
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Both are just adapters — the SDK's shipped surface stays signer-lib-agnostic (the
|
|
147
|
+
address helper uses only `@noble`; `ethers` is a dev-only dependency for that example,
|
|
148
|
+
while viem is included by the SDK). **Note:** the node's `/v1/sign/eoa-digest` path
|
|
149
|
+
may be feature-gated in your deployment; each example's offline self-test
|
|
150
|
+
(`npm run example:ethers` / `npm run example:viem`) proves the signature assembly
|
|
151
|
+
end-to-end with a local stand-in key.
|
|
152
|
+
|
|
153
|
+
## Allow Alice and Bob to use one account
|
|
154
|
+
|
|
155
|
+
Both users target the **same slot ID**, so both sign from the same Ethereum address.
|
|
156
|
+
Give each user their own holder key and an issuer credential accepted by the slot's
|
|
157
|
+
rule. Obtain fresh authorization for the acting user before each operation; do not
|
|
158
|
+
share a renewal token between users.
|
|
159
|
+
|
|
160
|
+
A rule allowing Alice **or** Bob permits either user to sign independently. Requiring
|
|
161
|
+
both users to approve the same transaction is a different authorization workflow;
|
|
162
|
+
keeper `k-of-n` alone does not implement two-user approval.
|
|
163
|
+
|
|
164
|
+
Verify each user separately: sign, broadcast, check the receipt and recovered sender,
|
|
165
|
+
then attempt the same operation with an unauthorized holder and record the denial.
|
|
166
|
+
[Credential presentation APIs](api.md#t3foundrytasra-sdkoid4vp--credential-wallets-against-the-verifier-agent)
|
|
167
|
+
provide the wallet flow. The [shared-account app](shared-account.md) includes assertions
|
|
168
|
+
for both users' transactions and Mallory's server-side refusal.
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
[Back to the README](../README.md) · [Documentation index](README.md)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Signing uses a separate, provisioned FROST slot, not the BLS encryption slot.
|
|
2
|
+
import {verifyFrostSignature} from '@t3foundry/tasra-sdk'
|
|
3
|
+
import {committeeClient, loadHolder, loadNetwork, slotId} from './live-config.ts'
|
|
4
|
+
|
|
5
|
+
const network = await loadNetwork()
|
|
6
|
+
const slot = slotId('KK_SIGN_SLOT_ID')
|
|
7
|
+
const identity = loadHolder()
|
|
8
|
+
try {
|
|
9
|
+
const client = committeeClient(network.chain, slot, identity, 'sign')
|
|
10
|
+
const message = new TextEncoder().encode('Hello Tasra')
|
|
11
|
+
const result = await client.sign(slot, message)
|
|
12
|
+
if (!verifyFrostSignature(result.groupPublicKey, message, result.signature)) throw new Error('Invalid FROST signature')
|
|
13
|
+
console.log('Threshold signature verified.')
|
|
14
|
+
} finally {
|
|
15
|
+
identity.secretKey.fill(0)
|
|
16
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NETWORKS, parsePinnedNetworkManifest, addressBookFromManifest,
|
|
3
|
+
createTasraChainClient,
|
|
4
|
+
} from '@t3foundry/tasra-sdk/chain'
|
|
5
|
+
|
|
6
|
+
// Keep the pointer and manifest at the same reviewed tasra-releases commit.
|
|
7
|
+
const revision = '3b34d86432c4577eef5d8a10e14eda272f87769b'
|
|
8
|
+
const base = `https://raw.githubusercontent.com/t3foundry/tasra-releases/${revision}/networks/testnet/`
|
|
9
|
+
async function download(path: string): Promise<string> {
|
|
10
|
+
const response = await fetch(`${base}${path}`, {signal: AbortSignal.timeout(15_000)})
|
|
11
|
+
if (!response.ok) throw new Error(`Download ${path}: HTTP ${response.status}`)
|
|
12
|
+
return response.text()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const pointer = JSON.parse(await download('current.json')) as {
|
|
16
|
+
schemaVersion: number; network: string; chainId: number; status: string
|
|
17
|
+
manifest: string; sha256: string
|
|
18
|
+
}
|
|
19
|
+
if (pointer.schemaVersion !== 1 || pointer.network !== 'testnet' ||
|
|
20
|
+
pointer.chainId !== 43113 || pointer.status !== 'active' ||
|
|
21
|
+
typeof pointer.manifest !== 'string' || !/^deployments\/[a-z0-9.-]+\.json$/.test(pointer.manifest)) {
|
|
22
|
+
throw new Error('Expected an active Fuji deployment pointer')
|
|
23
|
+
}
|
|
24
|
+
const manifest = parsePinnedNetworkManifest(await download(pointer.manifest), pointer.sha256)
|
|
25
|
+
if (manifest.network !== 'testnet' || manifest.chainId !== 43113) {
|
|
26
|
+
throw new Error('Expected a Fuji manifest')
|
|
27
|
+
}
|
|
28
|
+
const addresses = addressBookFromManifest(manifest)
|
|
29
|
+
const chain = createTasraChainClient({
|
|
30
|
+
rpcUrl: NETWORKS.testnet.rpcUrl, chainId: manifest.chainId, addresses,
|
|
31
|
+
})
|
|
32
|
+
if (await chain.client.getChainId() !== manifest.chainId) {
|
|
33
|
+
throw new Error('RPC chain does not match the manifest')
|
|
34
|
+
}
|
|
35
|
+
const block = await chain.client.getBlockNumber()
|
|
36
|
+
const commitReveal = await chain.readers.keyRegistry.requiresCommitReveal()
|
|
37
|
+
console.log(`Connected to Fuji (${manifest.chainId})`)
|
|
38
|
+
console.log(`Deployment: ${manifest.deploymentId}`)
|
|
39
|
+
console.log(`Block: ${block}`)
|
|
40
|
+
console.log(`KeyRegistry: ${addresses.KeyRegistry}`)
|
|
41
|
+
console.log(`Slot creation: ${commitReveal ? 'commit/reveal' : 'direct'}`)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {loadNetwork} from './network.js'
|
|
2
|
+
import {TasraClient} from '@t3foundry/tasra-sdk/app'
|
|
3
|
+
|
|
4
|
+
// Verify the manifest downloaded from tasra-releases; no wallet is needed.
|
|
5
|
+
const network = loadNetwork()
|
|
6
|
+
const tasra = new TasraClient({manifest: network.deployment, verifierAgentUrl: network.verifierAgentUrl})
|
|
7
|
+
|
|
8
|
+
// Check the actual chain and configured registries before using the network.
|
|
9
|
+
const health = await tasra.check()
|
|
10
|
+
if (!health.ready) throw new Error('Configured registries are unavailable')
|
|
11
|
+
console.log(`Connected to Tasra (${health.chainId})`)
|
|
12
|
+
console.log(`Block: ${await tasra.chain.client.getBlockNumber()}`)
|
|
13
|
+
console.log(`Active registered nodes: ${await tasra.chain.readers.nodeRegistry.activeCount()}`)
|
|
14
|
+
console.log('Registry contracts: available')
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Two holder-bound credentials approve the same native FROST request. */
|
|
2
|
+
import {setApprovalPolicy, approveWithCredential, type ReadySlotJournal} from '@t3foundry/tasra-sdk/app'
|
|
3
|
+
import {createTutorial, stopped} from './tutorial-support.js'
|
|
4
|
+
const hex = (bytes: Uint8Array) => `0x${Buffer.from(bytes).toString('hex')}`
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
// 1. Create all identities locally and use the public network manifest.
|
|
8
|
+
const {tasra, awaitUsageCredit, wallet, users, store, directory, save, policy, authorize} =
|
|
9
|
+
await createTutorial('credential-approvals', 'DocumentSigner', 'document-signer')
|
|
10
|
+
const rule = policy(['alice', 'bob'])
|
|
11
|
+
const slot = await tasra.slots.create({name: 'credential-approvals', mode: 'frost', policy: rule,
|
|
12
|
+
threshold: {k: 2, n: 3}, verifiers: {committee: 3, quorum: 2}})
|
|
13
|
+
await awaitUsageCredit(slot.slotId)
|
|
14
|
+
|
|
15
|
+
// 2. Commit a two-holder approval policy, separate from the keeper threshold.
|
|
16
|
+
const transaction = await setApprovalPolicy(tasra, slot.slotId, {quorum: 2, credentialPolicy: rule}, {wallet, store})
|
|
17
|
+
await new Promise(resolve => setTimeout(resolve, 4000)) // Allow network event watchers to observe the confirmed policy.
|
|
18
|
+
const approvals = await slot.approvals({quorum: 2, credentialGated: true})
|
|
19
|
+
const message = new TextEncoder().encode('Approve exact synthetic document version 1')
|
|
20
|
+
const request = await approvals.create(message)
|
|
21
|
+
save('request.json', {requestId: request.requestId, coordinator: request.nodeUrl, slotId: slot.slotId, message: hex(message)})
|
|
22
|
+
|
|
23
|
+
// 3. The SDK binds each credential and approval signature to this exact request.
|
|
24
|
+
const approve = (name: string) => approveWithCredential(tasra, request, message, {
|
|
25
|
+
identity: users[name]!.identity, authorize: authorize(name), signal: AbortSignal.timeout(120_000),
|
|
26
|
+
})
|
|
27
|
+
const first = await approve('alice')
|
|
28
|
+
if (first.status !== 'pending' || first.have !== 1) throw new Error('One holder reached quorum unexpectedly')
|
|
29
|
+
try { await approve('alice') } catch (error) {
|
|
30
|
+
if (!(error instanceof Error) || !('status' in error) || ![400, 403, 409].includes(Number(error.status))) throw error
|
|
31
|
+
}
|
|
32
|
+
const duplicate = await request.status()
|
|
33
|
+
if (duplicate.status !== 'pending' || duplicate.have !== 1) throw new Error('Same holder counted twice')
|
|
34
|
+
await approve('bob')
|
|
35
|
+
const result = await request.wait({timeoutMs: 120_000})
|
|
36
|
+
const journal = await store.load<ReadySlotJournal>('slot-credential-approvals')
|
|
37
|
+
const {commitTx, revealTx, targetEpoch, seeded} = journal!.creation.result!
|
|
38
|
+
save('evidence.json', {chainId: tasra.deployment.chainId, addresses: tasra.deployment.addresses,
|
|
39
|
+
createdAt: new Date().toISOString(), slotId: slot.slotId,
|
|
40
|
+
creation: {slotId: slot.slotId, commitTx, revealTx, targetEpoch, seeded}, policyHash: transaction.hash,
|
|
41
|
+
requestId: request.requestId, mode: 'credential-gated', quorum: 2, duplicateHolderHave: duplicate.have,
|
|
42
|
+
verifiedSignature: {r: hex(result.signature.r), z: hex(result.signature.z), groupPublicKey: hex(result.groupPublicKey)}})
|
|
43
|
+
console.log(`PASS: Alice and Bob approved; duplicate holder added no vote. Evidence: ${directory}/evidence.json`)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
main().catch(stopped)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Tasra Sign
|
|
2
|
+
|
|
3
|
+
A TypeScript app for two people to sign the same document using separate FROST slots.
|
|
4
|
+
Each person authorizes their own signature. This is not one shared-signature quorum.
|
|
5
|
+
|
|
6
|
+
## Install and connect
|
|
7
|
+
|
|
8
|
+
Copy this directory into your application, rename `gitignore.template` to `.gitignore`,
|
|
9
|
+
then run:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @t3foundry/tasra-sdk@latest
|
|
13
|
+
cp node_modules/@t3foundry/tasra-sdk/examples/fund-slot.ts .
|
|
14
|
+
npm run build
|
|
15
|
+
npx tsx network.ts
|
|
16
|
+
npm run setup
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`network.ts` downloads the current testnet manifest from
|
|
20
|
+
[tasra-releases](https://github.com/t3foundry/tasra-releases/tree/main/networks),
|
|
21
|
+
verifies its SHA-256, and saves `network.json` and `network-pin.json`. Keep those files
|
|
22
|
+
together. The example explicitly selects the `lowest-operator-id` coordinator policy;
|
|
23
|
+
confirm that the chosen services use this policy before creating slots.
|
|
24
|
+
|
|
25
|
+
Setup saves a new creator wallet and prints its address. Fund that address with at
|
|
26
|
+
least 0.05 AVAX through the [official Fuji C-Chain faucet](https://core.app/tools/testnet-faucet/?subnet=c&token=c) or your own wallet, then rerun
|
|
27
|
+
`npm run setup`. The saved creator is reused. The network must support FROST slots,
|
|
28
|
+
credential authorization and creator-signed rule provisioning. After creation, buy TSRA with EURC from BondingCurve and deposit TSRA into each
|
|
29
|
+
slot's Settlement balance before starting the app. Use the printed status commands
|
|
30
|
+
with `fund-slot.ts`; change `status` to `mint-test-eurc 10000000` (test EURC only),
|
|
31
|
+
`buy 10000000 1000000000000000000` (spend 10 EURC, require at least 1 TSRA), then
|
|
32
|
+
`fund 1000000000000000000` (deposit 1 TSRA). Keep each command's `--slot` argument.
|
|
33
|
+
Repeat the deposit for both slots, acquiring enough TSRA first. These are example
|
|
34
|
+
budgets; actual charges vary. The commands report confirmed hashes and balances.
|
|
35
|
+
EURC uses 6 decimals and TSRA uses 18. Creator AVAX is gas, not slot usage credit.
|
|
36
|
+
Each explicit write submits new transactions; inspect hashes and balances after
|
|
37
|
+
an uncertain result before retrying.
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
npm start
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Open the private sender-console URL printed by the server. Create a request, save
|
|
44
|
+
`request.json`, then use separate browser profiles for Alice and Bob. Import their
|
|
45
|
+
generated wallet files, review the document, and sign. Download the document and
|
|
46
|
+
signature bundle after both signatures complete.
|
|
47
|
+
|
|
48
|
+
## Verify and test
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
npm run verify -- document.pdf request.json signatures.json
|
|
52
|
+
npm test
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Keep `request.json` independently of the downloaded bundle. Verification binds both
|
|
56
|
+
signatures to its document digest, signer slots, chain and request ID. Preserve `.tasra`
|
|
57
|
+
if an operation is interrupted; it contains private keys, credentials and recovery state.
|
|
58
|
+
Do not publish that directory. A manifest or successful contract read does not prove
|
|
59
|
+
that the network supports every authorization or signing operation.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { verifyFrostSignature, hexToBytes } from '@t3foundry/tasra-sdk'
|
|
4
|
+
import {
|
|
5
|
+
openVerifierAgentSession,
|
|
6
|
+
awaitVerifierAgentResult,
|
|
7
|
+
VerifierAgentSessionError,
|
|
8
|
+
type OpenedVerifierAgentSession,
|
|
9
|
+
type Jwk,
|
|
10
|
+
} from '@t3foundry/tasra-sdk/oid4vp'
|
|
11
|
+
import { chain, deployment, tasra, verifierAgentUrl, assertSameNetwork, type NetworkIdentity } from './config.js'
|
|
12
|
+
import { stateDirectory } from './store.js'
|
|
13
|
+
import { statement, toHex, type Hex, type Person, type Proof, type Manifest } from './model.js'
|
|
14
|
+
import type { SigningBackend, SessionRecord } from './workflow.js'
|
|
15
|
+
|
|
16
|
+
export type ServiceConfig = {
|
|
17
|
+
network: NetworkIdentity
|
|
18
|
+
creatorKey: Hex
|
|
19
|
+
slots: Record<Person, Hex>
|
|
20
|
+
holderKeys: Record<Person, Jwk>
|
|
21
|
+
senderToken: string
|
|
22
|
+
}
|
|
23
|
+
export function loadService(): ServiceConfig {
|
|
24
|
+
const service = JSON.parse(
|
|
25
|
+
readFileSync(join(stateDirectory, 'service.json'), 'utf8'),
|
|
26
|
+
) as ServiceConfig
|
|
27
|
+
assertSameNetwork(service.network)
|
|
28
|
+
return service
|
|
29
|
+
}
|
|
30
|
+
export function restoreSession(
|
|
31
|
+
saved: SessionRecord,
|
|
32
|
+
): OpenedVerifierAgentSession {
|
|
33
|
+
return {
|
|
34
|
+
...saved,
|
|
35
|
+
verifierAgentUrl,
|
|
36
|
+
requestHash: hexToBytes(saved.requestHash),
|
|
37
|
+
} as OpenedVerifierAgentSession
|
|
38
|
+
}
|
|
39
|
+
export async function readKey(id: Hex) {
|
|
40
|
+
if ((await chain.client.getChainId()) !== deployment.chainId)
|
|
41
|
+
throw new Error('RPC chain differs from deployment')
|
|
42
|
+
const key = await chain.readers.keyRegistry.getKeySlot(id)
|
|
43
|
+
if (!key.exists) throw new Error('Signer slot does not exist')
|
|
44
|
+
return {
|
|
45
|
+
publicKey: key.publicKey,
|
|
46
|
+
epoch: Number(key.epoch),
|
|
47
|
+
mode: Number(key.mode),
|
|
48
|
+
cancelled: key.cancelled,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export function liveBackend(config: ServiceConfig): SigningBackend {
|
|
52
|
+
assertSameNetwork(config.network)
|
|
53
|
+
const creator = tasra.wallets.create({ privateKey: config.creatorKey })
|
|
54
|
+
const verify = async (manifest: Manifest, proof: Proof) => {
|
|
55
|
+
const expected = manifest.signers.find((s) => s.name === proof.name)
|
|
56
|
+
if (!expected || expected.slotId !== proof.slotId)
|
|
57
|
+
throw new Error('Unassigned signer')
|
|
58
|
+
const key = await readKey(proof.slotId)
|
|
59
|
+
if (
|
|
60
|
+
key.cancelled ||
|
|
61
|
+
key.mode !== 0 ||
|
|
62
|
+
key.publicKey !== proof.publicKey ||
|
|
63
|
+
key.epoch !== proof.epoch ||
|
|
64
|
+
!verifyFrostSignature(hexToBytes(key.publicKey), statement(manifest), {
|
|
65
|
+
r: hexToBytes(proof.r),
|
|
66
|
+
z: hexToBytes(proof.z),
|
|
67
|
+
})
|
|
68
|
+
)
|
|
69
|
+
throw new Error('Signature verification failed')
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
async open(manifest, person) {
|
|
73
|
+
const session = await openVerifierAgentSession({
|
|
74
|
+
chainId: deployment.chainId,
|
|
75
|
+
keyRegistry: deployment.addresses.KeyRegistry!,
|
|
76
|
+
slotId: config.slots[person],
|
|
77
|
+
action: 'sign',
|
|
78
|
+
message: statement(manifest),
|
|
79
|
+
description: `${person}: sign ${manifest.title}, version ${manifest.version}`,
|
|
80
|
+
verifierAgentUrl,
|
|
81
|
+
signer: creator.signer,
|
|
82
|
+
})
|
|
83
|
+
return {
|
|
84
|
+
sessionId: session.sessionId,
|
|
85
|
+
pollSecret: session.pollSecret,
|
|
86
|
+
requestUri: session.requestUri,
|
|
87
|
+
qrPayload: session.qrPayload,
|
|
88
|
+
operation: { ...session.operation },
|
|
89
|
+
requestHash: toHex(session.requestHash),
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
async sign(manifest, person, saved, beforeSubmit) {
|
|
93
|
+
let grant
|
|
94
|
+
try {
|
|
95
|
+
grant = await awaitVerifierAgentResult(restoreSession(saved), {
|
|
96
|
+
timeoutMs: 45000,
|
|
97
|
+
intervalMs: 500,
|
|
98
|
+
})
|
|
99
|
+
} catch (e) {
|
|
100
|
+
if (e instanceof VerifierAgentSessionError && e.kind === 'refused') {
|
|
101
|
+
const denied = new Error('Credential refused')
|
|
102
|
+
denied.name = 'AuthorizationRefused'
|
|
103
|
+
throw denied
|
|
104
|
+
}
|
|
105
|
+
throw e
|
|
106
|
+
}
|
|
107
|
+
if (!grant.verifierProofs?.length)
|
|
108
|
+
throw new Error('Missing verifier membership proofs')
|
|
109
|
+
const slotId = config.slots[person],
|
|
110
|
+
handle = await tasra.slots.frost(slotId)
|
|
111
|
+
beforeSubmit()
|
|
112
|
+
const signed = await handle.sign(statement(manifest), {
|
|
113
|
+
requireReceipt: true,
|
|
114
|
+
signal: AbortSignal.timeout(120000),
|
|
115
|
+
authorize: async () => ({
|
|
116
|
+
token: grant.token,
|
|
117
|
+
verifierProofs: grant.verifierProofs!,
|
|
118
|
+
}),
|
|
119
|
+
})
|
|
120
|
+
return {
|
|
121
|
+
name: person,
|
|
122
|
+
slotId,
|
|
123
|
+
publicKey: toHex(signed.groupPublicKey),
|
|
124
|
+
epoch: signed.epoch,
|
|
125
|
+
r: toHex(signed.signature.r),
|
|
126
|
+
z: toHex(signed.signature.z),
|
|
127
|
+
receiptStatus: 'verified',
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
verify,
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { build } from 'esbuild'
|
|
2
|
+
import { cpSync, mkdirSync } from 'node:fs'
|
|
3
|
+
await build({
|
|
4
|
+
entryPoints: ['web/app.ts'],
|
|
5
|
+
bundle: true,
|
|
6
|
+
format: 'esm',
|
|
7
|
+
platform: 'browser',
|
|
8
|
+
target: 'es2022',
|
|
9
|
+
outfile: 'public/app.js',
|
|
10
|
+
})
|
|
11
|
+
mkdirSync('public/pdf-assets', { recursive: true })
|
|
12
|
+
cpSync(
|
|
13
|
+
'node_modules/pdfjs-dist/build/pdf.worker.mjs',
|
|
14
|
+
'public/pdf-assets/pdf.worker.mjs',
|
|
15
|
+
)
|
|
16
|
+
for (const dir of ['cmaps', 'standard_fonts', 'wasm'])
|
|
17
|
+
cpSync('node_modules/pdfjs-dist/' + dir, 'public/pdf-assets/' + dir, {
|
|
18
|
+
recursive: true,
|
|
19
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TasraClient } from '@t3foundry/tasra-sdk/app'
|
|
2
|
+
import { loadNetwork } from './network.js'
|
|
3
|
+
|
|
4
|
+
// Use the downloaded manifest after verifying its saved SHA-256 pin.
|
|
5
|
+
const network = loadNetwork()
|
|
6
|
+
if (!network.verifierAgentUrl) throw new Error('Manifest must name a verifier agent')
|
|
7
|
+
export const verifierAgentUrl = network.verifierAgentUrl
|
|
8
|
+
export const tasra = new TasraClient({manifest: network.deployment, verifierAgentUrl})
|
|
9
|
+
export const { deployment, chain } = tasra
|
|
10
|
+
|
|
11
|
+
const manifestSha256 = deployment.provenance?.manifestSha256
|
|
12
|
+
if (!manifestSha256) throw new Error('Downloaded manifest lacks its checksum pin')
|
|
13
|
+
export const networkIdentity = Object.freeze({
|
|
14
|
+
chainId: deployment.chainId,
|
|
15
|
+
keyRegistry: deployment.addresses.KeyRegistry!.toLowerCase(),
|
|
16
|
+
manifestSha256,
|
|
17
|
+
coordinator: deployment.coordinator,
|
|
18
|
+
verifierAgentUrl,
|
|
19
|
+
})
|
|
20
|
+
export type NetworkIdentity = typeof networkIdentity
|
|
21
|
+
|
|
22
|
+
/** Reject changed routing before reusing saved credentials or session secrets. */
|
|
23
|
+
export function assertSameNetwork(value: unknown): asserts value is NetworkIdentity {
|
|
24
|
+
const saved = value as Partial<NetworkIdentity> | undefined
|
|
25
|
+
if (!saved || typeof saved !== 'object' ||
|
|
26
|
+
saved.chainId !== networkIdentity.chainId ||
|
|
27
|
+
typeof saved.keyRegistry !== 'string' ||
|
|
28
|
+
saved.keyRegistry.toLowerCase() !== networkIdentity.keyRegistry ||
|
|
29
|
+
saved.manifestSha256 !== networkIdentity.manifestSha256 ||
|
|
30
|
+
saved.coordinator !== networkIdentity.coordinator ||
|
|
31
|
+
saved.verifierAgentUrl !== networkIdentity.verifierAgentUrl) {
|
|
32
|
+
throw new Error('Saved network configuration differs. Restore the original manifest and pin; preserve private state for reconciliation.')
|
|
33
|
+
}
|
|
34
|
+
}
|