@zanii/chain-bridge 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -51,3 +51,7 @@ first-come-first-served, not a trademark; and the ledger summary returned here i
51
51
  server's aggregate — full offline acceptance still means following `audit_bundle`
52
52
  with `verifyAuditBundle` (`resolveAndVerify`). Read-only: this package never holds
53
53
  keys or funds.
54
+
55
+ ## Changelog
56
+
57
+ - **0.1.2** — Off-chain settlement helpers: `settlementMemo` / `verifySettlementTx` (a payment provably for one receipt), STH `anchorData`, the same key's Solana / Sui / Aptos addresses (confirm with the chain's own SDK before moving funds), `chainEventReceipt`, `walletPolicyFromDelegation`, `taxLotExport`, two-party payment-channel states (`latestChannelState`), and `compactProof` / `verifyCompactProof` for contracts and counterparties.
package/dist/index.d.ts CHANGED
@@ -52,4 +52,5 @@ export declare function resolveChainAgent(nameOrAddress: string, opts?: {
52
52
  fetchImpl?: FetchLike;
53
53
  maxPages?: number;
54
54
  }): Promise<ResolvedChainAgent | null>;
55
+ export * from './settlement.js';
55
56
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGrE,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEjF,eAAO,MAAM,SAAS,QAAQ,CAAC;AAC/B,eAAO,MAAM,iBAAiB,oCAAoC,CAAC;AAEnE,wDAAwD;AACxD,MAAM,WAAW,eAAe;IAC9B,0FAA0F;IAC1F,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ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AE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GAChG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAuBpC;AACD,cAAc,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -110,4 +110,5 @@ export async function resolveChainAgent(nameOrAddress, opts = {}) {
110
110
  }
111
111
  return { chain: entry, binding, ledger };
112
112
  }
113
+ export * from './settlement.js';
113
114
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAmB,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAIjE,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC;AAC/B,MAAM,CAAC,MAAM,iBAAiB,GAAG,iCAAiC,CAAC;AAYnE,+FAA+F;AAC/F,MAAM,UAAU,yBAAyB,CAAC,SAAqB;IAC7D,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AAClF,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC7C,MAAM,GAAG,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,GAAG,CAAC,CAAC,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACrD,CAAC;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,CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAC9B,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,EAAE,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC3C,CAAC;AACD,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,120 @@
1
+ import { type BundledReceipt, type DelegationCert, type SignedObject, type SignedTreeHead } from '@zanii/core';
2
+ /** The memo a payment carries so it is provably for one receipt: `zanii:<receipt hash>`. */
3
+ export declare function settlementMemo(receiptHash: string): string;
4
+ export declare function parseSettlementMemo(memo: string): string | null;
5
+ /** Does this transaction pay `amount` (integer base units) to `to` for exactly this receipt? */
6
+ export declare function verifySettlementTx(tx: {
7
+ memo?: string;
8
+ to: string;
9
+ amount: string | number | bigint;
10
+ status?: string;
11
+ }, expect: {
12
+ receiptHash: string;
13
+ to: string;
14
+ amount: bigint;
15
+ }): {
16
+ ok: boolean;
17
+ reasons: string[];
18
+ };
19
+ /** Transaction data that anchors a signed tree head: `zanii-sth:<size>:<root hex>`. */
20
+ export declare function anchorData(sth: SignedTreeHead): string;
21
+ /** Does this transaction's data anchor this (validly signed) tree head? */
22
+ export declare function verifyAnchorData(data: string, sth: SignedTreeHead): boolean;
23
+ /** The Solana address of the same key: base58 of the Ed25519 public key. */
24
+ export declare function solanaAddressFromDid(did: string): string;
25
+ /** The Sui address of the same key: BLAKE2b-256(0x00 flag || public key). */
26
+ export declare function suiAddressFromDid(did: string): string;
27
+ /** The Aptos address of the same key (single-signer Ed25519): SHA3-256(public key || 0x00). */
28
+ export declare function aptosAddressFromDid(did: string): string;
29
+ /** A registry record for an on-chain agent registry: the DID and a hash of its metadata. */
30
+ export declare function registryRecord(did: string, metadata: Record<string, unknown>): {
31
+ did: string;
32
+ metadataHash: string;
33
+ address: string | undefined;
34
+ };
35
+ /** Turn an on-chain transaction by the agent into a receipt to record on the ledger. */
36
+ export declare function chainEventReceipt(tx: {
37
+ hash: string;
38
+ chain: string;
39
+ from: string;
40
+ to?: string;
41
+ amount?: string;
42
+ method?: string;
43
+ ts: string;
44
+ }): {
45
+ target: string;
46
+ payload: {
47
+ hash: string;
48
+ chain: string;
49
+ from: string;
50
+ to?: string;
51
+ amount?: string;
52
+ method?: string;
53
+ ts: string;
54
+ v: number;
55
+ type: string;
56
+ };
57
+ };
58
+ /**
59
+ * The spending rules a smart wallet should enforce, mirrored from the agent's delegation:
60
+ * which targets it may pay for, until when. The chain enforces; the ledger proves.
61
+ */
62
+ export declare function walletPolicyFromDelegation(chain: DelegationCert[], opts?: {
63
+ maxAmount?: string;
64
+ }): {
65
+ agent: string;
66
+ owner: string;
67
+ allowedTargets: string[];
68
+ expires: string;
69
+ maxAmount: string | null;
70
+ delegation: string;
71
+ };
72
+ /** Rows for tax reporting: each on-chain movement matched to the receipt it settled, or flagged. */
73
+ export declare function taxLotExport(txs: Array<{
74
+ hash: string;
75
+ memo?: string;
76
+ amount: string;
77
+ asset: string;
78
+ ts: string;
79
+ }>, receipts: Array<{
80
+ hash: string;
81
+ target: string;
82
+ }>): {
83
+ tx: string;
84
+ ts: string;
85
+ asset: string;
86
+ amount: string;
87
+ receipt: string | null;
88
+ purpose: string | null;
89
+ matched: boolean;
90
+ }[];
91
+ export type ChannelState = SignedObject<{
92
+ v: 1;
93
+ type: 'chain.channel';
94
+ channel: string;
95
+ nonce: number;
96
+ balanceA: string;
97
+ balanceB: string;
98
+ }>;
99
+ /** An off-chain payment-channel state; both parties sign each one. The highest nonce both signed wins. */
100
+ export declare function channelState(input: {
101
+ channel: string;
102
+ nonce: number;
103
+ balanceA: bigint;
104
+ balanceB: bigint;
105
+ }, privateKey: Uint8Array): ChannelState;
106
+ /** The latest state signed by both parties, with the total conserved across states. */
107
+ export declare function latestChannelState(states: ChannelState[], parties: [string, string]): {
108
+ nonce: number;
109
+ balanceA: bigint;
110
+ balanceB: bigint;
111
+ } | null;
112
+ /** A compact, self-contained proof that one receipt is in the log: what a contract or counterparty checks. */
113
+ export declare function compactProof(entry: BundledReceipt, sth: SignedTreeHead): {
114
+ receipt: import("@zanii/core").Receipt | import("@zanii/core").A2AReceipt;
115
+ index: number;
116
+ path: string[];
117
+ sth: SignedTreeHead;
118
+ };
119
+ export declare function verifyCompactProof(p: ReturnType<typeof compactProof>): boolean;
120
+ //# sourceMappingURL=settlement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settlement.d.ts","sourceRoot":"","sources":["../src/settlement.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,EACjF,MAAM,aAAa,CAAC;AAErB,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG/D;AAED,gGAAgG;AAChG,wBAAgB,kBAAkB,CAAC,EAAE,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE;;;EAOnL;AAED,uFAAuF;AACvF,wBAAgB,UAAU,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM,CAEtD;AAED,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAE3E;AAQD,4EAA4E;AAC5E,wBAAgB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IAOrK;AAED,MAAM,MAAM,YAAY,GAAG,YAAY,CAAC;IAAE,CAAC,EAAE,CAAC,CAAC;IAAC,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE7I,0GAA0G;AAC1G,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,UAAU,EAAE,UAAU,GAAG,YAAY,CAGhJ;AAED,uFAAuF;AACvF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAOlJ;AAED,8GAA8G;AAC9G,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,cAAc;;;;;EAEtE;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,GAAG,OAAO,CAM9E"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Settlement and cross-chain helpers that work off-chain today: payments that name the
3
+ * receipt they pay for, STH anchors as transaction data, the same Ed25519 key's address on
4
+ * other Ed25519 chains, wallet policy mirrored from a delegation, tax reconciliation,
5
+ * payment-channel states, and compact proofs a contract or a counterparty can check.
6
+ *
7
+ * On-chain enforcement (staking, slashing, registry contracts) needs contracts deployed on
8
+ * the chain; these functions produce and check the data those contracts would consume.
9
+ */
10
+ import { blake2b } from '@noble/hashes/blake2b';
11
+ import { sha3_256 } from '@noble/hashes/sha3';
12
+ import { bytesToHex, concatBytes, hexToBytes } from '@noble/hashes/utils';
13
+ import { base58 } from '@scure/base';
14
+ import { canonicalBytes, jcsHash, leafHash, publicKeyFromDid, signObject, verifyInclusion, verifySignedObject, verifySTH, } from '@zanii/core';
15
+ /** The memo a payment carries so it is provably for one receipt: `zanii:<receipt hash>`. */
16
+ export function settlementMemo(receiptHash) {
17
+ if (!/^sha256:[0-9a-f]{64}$/.test(receiptHash))
18
+ throw new Error('chain-bridge: not a receipt hash');
19
+ return `zanii:${receiptHash}`;
20
+ }
21
+ export function parseSettlementMemo(memo) {
22
+ const m = memo.match(/^zanii:(sha256:[0-9a-f]{64})$/);
23
+ return m ? m[1] : null;
24
+ }
25
+ /** Does this transaction pay `amount` (integer base units) to `to` for exactly this receipt? */
26
+ export function verifySettlementTx(tx, expect) {
27
+ const reasons = [];
28
+ if (parseSettlementMemo(tx.memo ?? '') !== expect.receiptHash)
29
+ reasons.push('memo does not name this receipt');
30
+ if (tx.to !== expect.to)
31
+ reasons.push(`paid ${tx.to}, expected ${expect.to}`);
32
+ if (BigInt(tx.amount) < expect.amount)
33
+ reasons.push(`paid ${tx.amount}, expected ${expect.amount}`);
34
+ if (tx.status !== undefined && tx.status !== 'success' && tx.status !== 'confirmed')
35
+ reasons.push(`transaction status ${tx.status}`);
36
+ return { ok: reasons.length === 0, reasons };
37
+ }
38
+ /** Transaction data that anchors a signed tree head: `zanii-sth:<size>:<root hex>`. */
39
+ export function anchorData(sth) {
40
+ return `zanii-sth:${sth.size}:${sth.root.replace('sha256:', '')}`;
41
+ }
42
+ /** Does this transaction's data anchor this (validly signed) tree head? */
43
+ export function verifyAnchorData(data, sth) {
44
+ return verifySTH(sth) && data === anchorData(sth);
45
+ }
46
+ const pub = (did) => {
47
+ const p = publicKeyFromDid(did);
48
+ if (!p)
49
+ throw new Error('chain-bridge: not an Ed25519 did:key');
50
+ return p;
51
+ };
52
+ /** The Solana address of the same key: base58 of the Ed25519 public key. */
53
+ export function solanaAddressFromDid(did) {
54
+ return base58.encode(pub(did));
55
+ }
56
+ /** The Sui address of the same key: BLAKE2b-256(0x00 flag || public key). */
57
+ export function suiAddressFromDid(did) {
58
+ return '0x' + bytesToHex(blake2b(concatBytes(new Uint8Array([0x00]), pub(did)), { dkLen: 32 }));
59
+ }
60
+ /** The Aptos address of the same key (single-signer Ed25519): SHA3-256(public key || 0x00). */
61
+ export function aptosAddressFromDid(did) {
62
+ return '0x' + bytesToHex(sha3_256(concatBytes(pub(did), new Uint8Array([0x00]))));
63
+ }
64
+ /** A registry record for an on-chain agent registry: the DID and a hash of its metadata. */
65
+ export function registryRecord(did, metadata) {
66
+ return { did, metadataHash: jcsHash(metadata), address: undefined };
67
+ }
68
+ /** Turn an on-chain transaction by the agent into a receipt to record on the ledger. */
69
+ export function chainEventReceipt(tx) {
70
+ return { target: `chain.${tx.chain}.${tx.method ?? 'transfer'}`, payload: { v: 1, type: 'chain.event', ...tx } };
71
+ }
72
+ /**
73
+ * The spending rules a smart wallet should enforce, mirrored from the agent's delegation:
74
+ * which targets it may pay for, until when. The chain enforces; the ledger proves.
75
+ */
76
+ export function walletPolicyFromDelegation(chain, opts = {}) {
77
+ const last = chain[chain.length - 1];
78
+ if (!last)
79
+ throw new Error('chain-bridge: empty delegation');
80
+ return { agent: last.subject, owner: chain[0].issuer, allowedTargets: last.scopes.filter((s) => s.startsWith('payment') || s === '*'), expires: last.exp, maxAmount: opts.maxAmount ?? null, delegation: jcsHash(chain) };
81
+ }
82
+ /** Rows for tax reporting: each on-chain movement matched to the receipt it settled, or flagged. */
83
+ export function taxLotExport(txs, receipts) {
84
+ const byHash = new Map(receipts.map((r) => [r.hash, r]));
85
+ return txs.map((t) => {
86
+ const rh = parseSettlementMemo(t.memo ?? '');
87
+ const r = rh ? byHash.get(rh) : undefined;
88
+ return { tx: t.hash, ts: t.ts, asset: t.asset, amount: t.amount, receipt: rh, purpose: r?.target ?? null, matched: !!r };
89
+ });
90
+ }
91
+ /** An off-chain payment-channel state; both parties sign each one. The highest nonce both signed wins. */
92
+ export function channelState(input, privateKey) {
93
+ if (!Number.isSafeInteger(input.nonce) || input.nonce < 0)
94
+ throw new Error('chain-bridge: nonce must be a non-negative integer');
95
+ return signObject({ v: 1, type: 'chain.channel', channel: input.channel, nonce: input.nonce, balanceA: input.balanceA.toString(), balanceB: input.balanceB.toString() }, privateKey);
96
+ }
97
+ /** The latest state signed by both parties, with the total conserved across states. */
98
+ export function latestChannelState(states, parties) {
99
+ const byNonce = new Map();
100
+ for (const s of states)
101
+ if (verifySignedObject(s) && parties.includes(s.signer))
102
+ byNonce.set(s.nonce, [...(byNonce.get(s.nonce) ?? []), s]);
103
+ const agreed = [...byNonce].filter(([, ss]) => new Set(ss.map((s) => s.signer)).size === 2 && ss.every((s) => s.balanceA === ss[0].balanceA && s.balanceB === ss[0].balanceB));
104
+ if (!agreed.length)
105
+ return null;
106
+ const [nonce, [s]] = agreed.sort((a, b) => b[0] - a[0])[0];
107
+ return { nonce, balanceA: BigInt(s.balanceA), balanceB: BigInt(s.balanceB) };
108
+ }
109
+ /** A compact, self-contained proof that one receipt is in the log: what a contract or counterparty checks. */
110
+ export function compactProof(entry, sth) {
111
+ return { receipt: entry.receipt, index: entry.index, path: entry.proof, sth };
112
+ }
113
+ export function verifyCompactProof(p) {
114
+ try {
115
+ return verifySTH(p.sth) && verifyInclusion(leafHash(canonicalBytes(p.receipt)), p.index, p.sth.size, p.path.map(hexToBytes), hexToBytes(p.sth.root.replace('sha256:', '')));
116
+ }
117
+ catch {
118
+ return false;
119
+ }
120
+ }
121
+ //# sourceMappingURL=settlement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settlement.js","sourceRoot":"","sources":["../src/settlement.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OA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AAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAA8B,CAAC;IACxF,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;AACjF,CAAC;AAED,8GAA8G;AAC9G,MAAM,UAAU,YAAY,CAAC,KAAqB,EAAE,GAAmB;IACrE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,CAAkC;IACnE,IAAI,CAAC;QACH,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAC9K,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zanii/chain-bridge",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "One keypair, two products: bridge the Zanii L1 (blockchain.zanii.agency) to the Zanii transparency ledger. A chain wallet's Ed25519 pubkey IS a ledger did:key, so the bridge PROVES a registered chain agent's claimed DID controls its wallet (address = bech32 zan + blake3(pubkey)[:20]) and resolves it to its verified ledger history - the agent paying you on-chain is provably the agent whose actions you can audit.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://ledger.zanii.agency",
@@ -33,8 +33,8 @@
33
33
  "dependencies": {
34
34
  "@noble/hashes": "^1.7.1",
35
35
  "@scure/base": "^1.2.1",
36
- "@zanii/core": "^0.5.2",
37
- "@zanii/a2a-directory": "^0.1.2"
36
+ "@zanii/core": "^0.5.4",
37
+ "@zanii/a2a-directory": "^0.1.3"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsc -p tsconfig.build.json",
package/src/index.ts CHANGED
@@ -145,3 +145,4 @@ export async function resolveChainAgent(
145
145
  }
146
146
  return { chain: entry, binding, ledger };
147
147
  }
148
+ export * from './settlement.js';
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Settlement and cross-chain helpers that work off-chain today: payments that name the
3
+ * receipt they pay for, STH anchors as transaction data, the same Ed25519 key's address on
4
+ * other Ed25519 chains, wallet policy mirrored from a delegation, tax reconciliation,
5
+ * payment-channel states, and compact proofs a contract or a counterparty can check.
6
+ *
7
+ * On-chain enforcement (staking, slashing, registry contracts) needs contracts deployed on
8
+ * the chain; these functions produce and check the data those contracts would consume.
9
+ */
10
+ import { blake2b } from '@noble/hashes/blake2b';
11
+ import { sha3_256 } from '@noble/hashes/sha3';
12
+ import { bytesToHex, concatBytes, hexToBytes } from '@noble/hashes/utils';
13
+ import { base58 } from '@scure/base';
14
+ import {
15
+ canonicalBytes, jcsHash, leafHash, publicKeyFromDid, signObject, verifyInclusion, verifySignedObject, verifySTH,
16
+ type BundledReceipt, type DelegationCert, type SignedObject, type SignedTreeHead,
17
+ } from '@zanii/core';
18
+
19
+ /** The memo a payment carries so it is provably for one receipt: `zanii:<receipt hash>`. */
20
+ export function settlementMemo(receiptHash: string): string {
21
+ if (!/^sha256:[0-9a-f]{64}$/.test(receiptHash)) throw new Error('chain-bridge: not a receipt hash');
22
+ return `zanii:${receiptHash}`;
23
+ }
24
+
25
+ export function parseSettlementMemo(memo: string): string | null {
26
+ const m = memo.match(/^zanii:(sha256:[0-9a-f]{64})$/);
27
+ return m ? m[1]! : null;
28
+ }
29
+
30
+ /** Does this transaction pay `amount` (integer base units) to `to` for exactly this receipt? */
31
+ export function verifySettlementTx(tx: { memo?: string; to: string; amount: string | number | bigint; status?: string }, expect: { receiptHash: string; to: string; amount: bigint }) {
32
+ const reasons: string[] = [];
33
+ if (parseSettlementMemo(tx.memo ?? '') !== expect.receiptHash) reasons.push('memo does not name this receipt');
34
+ if (tx.to !== expect.to) reasons.push(`paid ${tx.to}, expected ${expect.to}`);
35
+ if (BigInt(tx.amount) < expect.amount) reasons.push(`paid ${tx.amount}, expected ${expect.amount}`);
36
+ if (tx.status !== undefined && tx.status !== 'success' && tx.status !== 'confirmed') reasons.push(`transaction status ${tx.status}`);
37
+ return { ok: reasons.length === 0, reasons };
38
+ }
39
+
40
+ /** Transaction data that anchors a signed tree head: `zanii-sth:<size>:<root hex>`. */
41
+ export function anchorData(sth: SignedTreeHead): string {
42
+ return `zanii-sth:${sth.size}:${sth.root.replace('sha256:', '')}`;
43
+ }
44
+
45
+ /** Does this transaction's data anchor this (validly signed) tree head? */
46
+ export function verifyAnchorData(data: string, sth: SignedTreeHead): boolean {
47
+ return verifySTH(sth) && data === anchorData(sth);
48
+ }
49
+
50
+ const pub = (did: string) => {
51
+ const p = publicKeyFromDid(did);
52
+ if (!p) throw new Error('chain-bridge: not an Ed25519 did:key');
53
+ return p;
54
+ };
55
+
56
+ /** The Solana address of the same key: base58 of the Ed25519 public key. */
57
+ export function solanaAddressFromDid(did: string): string {
58
+ return base58.encode(pub(did));
59
+ }
60
+
61
+ /** The Sui address of the same key: BLAKE2b-256(0x00 flag || public key). */
62
+ export function suiAddressFromDid(did: string): string {
63
+ return '0x' + bytesToHex(blake2b(concatBytes(new Uint8Array([0x00]), pub(did)), { dkLen: 32 }));
64
+ }
65
+
66
+ /** The Aptos address of the same key (single-signer Ed25519): SHA3-256(public key || 0x00). */
67
+ export function aptosAddressFromDid(did: string): string {
68
+ return '0x' + bytesToHex(sha3_256(concatBytes(pub(did), new Uint8Array([0x00]))));
69
+ }
70
+
71
+ /** A registry record for an on-chain agent registry: the DID and a hash of its metadata. */
72
+ export function registryRecord(did: string, metadata: Record<string, unknown>) {
73
+ return { did, metadataHash: jcsHash(metadata), address: undefined as string | undefined };
74
+ }
75
+
76
+ /** Turn an on-chain transaction by the agent into a receipt to record on the ledger. */
77
+ export function chainEventReceipt(tx: { hash: string; chain: string; from: string; to?: string; amount?: string; method?: string; ts: string }) {
78
+ return { target: `chain.${tx.chain}.${tx.method ?? 'transfer'}`, payload: { v: 1, type: 'chain.event', ...tx } };
79
+ }
80
+
81
+ /**
82
+ * The spending rules a smart wallet should enforce, mirrored from the agent's delegation:
83
+ * which targets it may pay for, until when. The chain enforces; the ledger proves.
84
+ */
85
+ export function walletPolicyFromDelegation(chain: DelegationCert[], opts: { maxAmount?: string } = {}) {
86
+ const last = chain[chain.length - 1];
87
+ if (!last) throw new Error('chain-bridge: empty delegation');
88
+ return { agent: last.subject, owner: chain[0]!.issuer, allowedTargets: last.scopes.filter((s) => s.startsWith('payment') || s === '*'), expires: last.exp, maxAmount: opts.maxAmount ?? null, delegation: jcsHash(chain) };
89
+ }
90
+
91
+ /** Rows for tax reporting: each on-chain movement matched to the receipt it settled, or flagged. */
92
+ export function taxLotExport(txs: Array<{ hash: string; memo?: string; amount: string; asset: string; ts: string }>, receipts: Array<{ hash: string; target: string }>) {
93
+ const byHash = new Map(receipts.map((r) => [r.hash, r]));
94
+ return txs.map((t) => {
95
+ const rh = parseSettlementMemo(t.memo ?? '');
96
+ const r = rh ? byHash.get(rh) : undefined;
97
+ return { tx: t.hash, ts: t.ts, asset: t.asset, amount: t.amount, receipt: rh, purpose: r?.target ?? null, matched: !!r };
98
+ });
99
+ }
100
+
101
+ export type ChannelState = SignedObject<{ v: 1; type: 'chain.channel'; channel: string; nonce: number; balanceA: string; balanceB: string }>;
102
+
103
+ /** An off-chain payment-channel state; both parties sign each one. The highest nonce both signed wins. */
104
+ export function channelState(input: { channel: string; nonce: number; balanceA: bigint; balanceB: bigint }, privateKey: Uint8Array): ChannelState {
105
+ if (!Number.isSafeInteger(input.nonce) || input.nonce < 0) throw new Error('chain-bridge: nonce must be a non-negative integer');
106
+ return signObject({ v: 1 as const, type: 'chain.channel' as const, channel: input.channel, nonce: input.nonce, balanceA: input.balanceA.toString(), balanceB: input.balanceB.toString() }, privateKey);
107
+ }
108
+
109
+ /** The latest state signed by both parties, with the total conserved across states. */
110
+ export function latestChannelState(states: ChannelState[], parties: [string, string]): { nonce: number; balanceA: bigint; balanceB: bigint } | null {
111
+ const byNonce = new Map<number, ChannelState[]>();
112
+ for (const s of states) if (verifySignedObject(s) && parties.includes(s.signer)) byNonce.set(s.nonce, [...(byNonce.get(s.nonce) ?? []), s]);
113
+ const agreed = [...byNonce].filter(([, ss]) => new Set(ss.map((s) => s.signer)).size === 2 && ss.every((s) => s.balanceA === ss[0]!.balanceA && s.balanceB === ss[0]!.balanceB));
114
+ if (!agreed.length) return null;
115
+ const [nonce, [s]] = agreed.sort((a, b) => b[0] - a[0])[0]! as [number, ChannelState[]];
116
+ return { nonce, balanceA: BigInt(s!.balanceA), balanceB: BigInt(s!.balanceB) };
117
+ }
118
+
119
+ /** A compact, self-contained proof that one receipt is in the log: what a contract or counterparty checks. */
120
+ export function compactProof(entry: BundledReceipt, sth: SignedTreeHead) {
121
+ return { receipt: entry.receipt, index: entry.index, path: entry.proof, sth };
122
+ }
123
+
124
+ export function verifyCompactProof(p: ReturnType<typeof compactProof>): boolean {
125
+ try {
126
+ return verifySTH(p.sth) && verifyInclusion(leafHash(canonicalBytes(p.receipt)), p.index, p.sth.size, p.path.map(hexToBytes), hexToBytes(p.sth.root.replace('sha256:', '')));
127
+ } catch {
128
+ return false;
129
+ }
130
+ }