@toon-protocol/sdk 0.4.0 → 0.5.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/README.md +19 -19
- package/dist/chunk-XTHUXP63.js +1637 -0
- package/dist/chunk-XTHUXP63.js.map +1 -0
- package/dist/index.d.ts +747 -9
- package/dist/index.js +1189 -180
- package/dist/index.js.map +1 -1
- package/dist/swap-D4Ozr_BM.d.ts +484 -0
- package/dist/swap.d.ts +3 -0
- package/dist/swap.js +14 -0
- package/dist/swap.js.map +1 -0
- package/package.json +27 -18
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { ToonError, HandlePacketAcceptResponse, HandlePacketRejectResponse, ReputationScore, SkillDescriptor, EmbeddableConnectorLike, KnownPeer, SettlementConfig, ChainProviderConfigEntry, ConnectorChannelClient, BootstrapEventListener, BootstrapResult, DvmJobStatus, IlpSendResult, ParsedWorkflowDefinition } from '@toon-protocol/core';
|
|
2
|
-
export { BootstrapEvent, BootstrapEventListener, HandlePacketAcceptResponse, HandlePacketRejectResponse, SkillDescriptor } from '@toon-protocol/core';
|
|
3
|
-
import { NostrEvent } from 'nostr-tools/pure';
|
|
1
|
+
import { ToonError, HandlePacketAcceptResponse, HandlePacketRejectResponse, ReputationScore, SkillDescriptor, EmbeddableConnectorLike, KnownPeer, SettlementConfig, ChainProviderConfigEntry, ConnectorChannelClient, BootstrapEventListener, BootstrapResult, DvmJobStatus, IlpSendResult, ParsedWorkflowDefinition, SwapPair } from '@toon-protocol/core';
|
|
2
|
+
export { BootstrapEvent, BootstrapEventListener, HandlePacketAcceptResponse, HandlePacketRejectResponse, SkillDescriptor, balanceProofFieldsMina, balanceProofHashEvm, balanceProofHashSolana, bigintToBytes32BE, concatBytes, hexToBytes, minaHashToField } from '@toon-protocol/core';
|
|
3
|
+
import { NostrEvent, UnsignedEvent } from 'nostr-tools/pure';
|
|
4
4
|
import { ToonRoutingMeta } from '@toon-protocol/core/toon';
|
|
5
|
+
import { TransportConfig } from '@toon-protocol/connector';
|
|
6
|
+
export { TransportConfig } from '@toon-protocol/connector';
|
|
7
|
+
import { A as AccumulatedClaim } from './swap-D4Ozr_BM.js';
|
|
8
|
+
export { D as DecryptFulfillClaimParams, E as EncryptFulfillClaimParams, a as EncryptFulfillClaimResult, P as PacketProgress, R as RateMonitorCallback, S as StreamSwapController, b as StreamSwapParams, c as StreamSwapResult, U as UnwrapSwapPacketFromToonParams, d as UnwrapSwapPacketParams, e as UnwrapSwapPacketResult, W as WrapSwapPacketParams, f as WrapSwapPacketResult, g as WrapSwapPacketToToonParams, h as WrapSwapPacketToToonResult, _ as __streamSwapTesting, i as decryptFulfillClaim, j as encryptFulfillClaim, s as streamSwap, k as streamSwapControlled, u as unwrapSwapPacket, l as unwrapSwapPacketFromToon, w as wrapSwapPacket, m as wrapSwapPacketToToon } from './swap-D4Ozr_BM.js';
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* Unified identity module for @toon-protocol/sdk.
|
|
@@ -24,6 +28,34 @@ interface NodeIdentity {
|
|
|
24
28
|
/** The EIP-55 checksummed EVM address (0x-prefixed, 42 characters). */
|
|
25
29
|
evmAddress: string;
|
|
26
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Solana Ed25519 identity derived via SLIP-0010 from a BIP-39 mnemonic.
|
|
33
|
+
*/
|
|
34
|
+
interface SolanaIdentity {
|
|
35
|
+
/** 64-byte Ed25519 keypair (32-byte private key + 32-byte public key). */
|
|
36
|
+
secretKey: Uint8Array;
|
|
37
|
+
/** Base58-encoded Ed25519 public key (Solana address). */
|
|
38
|
+
publicKey: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Mina Pallas identity derived from a BIP-39 mnemonic via mina-signer.
|
|
42
|
+
*/
|
|
43
|
+
interface MinaIdentity {
|
|
44
|
+
/** Hex-encoded Pallas private key. */
|
|
45
|
+
privateKey: string;
|
|
46
|
+
/** Base58 Mina public key (B62 prefix). */
|
|
47
|
+
publicKey: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Full multi-chain identity derived from a single BIP-39 mnemonic.
|
|
51
|
+
* Extends NodeIdentity (Nostr + EVM) with Solana and optionally Mina.
|
|
52
|
+
*/
|
|
53
|
+
interface ToonIdentity extends NodeIdentity {
|
|
54
|
+
/** Solana Ed25519 identity (always populated from mnemonic derivation). */
|
|
55
|
+
solana: SolanaIdentity;
|
|
56
|
+
/** Mina Pallas identity (undefined when mina-signer is not installed). */
|
|
57
|
+
mina?: MinaIdentity;
|
|
58
|
+
}
|
|
27
59
|
/**
|
|
28
60
|
* Options for mnemonic-based key derivation.
|
|
29
61
|
*/
|
|
@@ -47,7 +79,7 @@ declare function generateMnemonic(): string;
|
|
|
47
79
|
* @returns The derived NodeIdentity with secretKey, pubkey, and evmAddress.
|
|
48
80
|
* @throws {IdentityError} If the mnemonic is invalid.
|
|
49
81
|
*/
|
|
50
|
-
declare function fromMnemonic(mnemonic: string, options?: FromMnemonicOptions):
|
|
82
|
+
declare function fromMnemonic(mnemonic: string, options?: FromMnemonicOptions): ToonIdentity;
|
|
51
83
|
/**
|
|
52
84
|
* Derives a complete NodeIdentity from an existing 32-byte secret key.
|
|
53
85
|
*
|
|
@@ -56,6 +88,42 @@ declare function fromMnemonic(mnemonic: string, options?: FromMnemonicOptions):
|
|
|
56
88
|
* @throws {IdentityError} If the secret key is not exactly 32 bytes.
|
|
57
89
|
*/
|
|
58
90
|
declare function fromSecretKey(secretKey: Uint8Array): NodeIdentity;
|
|
91
|
+
/**
|
|
92
|
+
* Derives a full multi-chain ToonIdentity from a BIP-39 mnemonic,
|
|
93
|
+
* including async Mina derivation (requires mina-signer).
|
|
94
|
+
*
|
|
95
|
+
* Chains derived:
|
|
96
|
+
* - Nostr (secp256k1): m/44'/1237'/0'/0/{accountIndex}
|
|
97
|
+
* - EVM (secp256k1): same key as Nostr, Keccak-256 for address
|
|
98
|
+
* - Solana (Ed25519): m/44'/501'/{accountIndex}'/0' (SLIP-0010)
|
|
99
|
+
* - Mina (Pallas): m/44'/12586'/{accountIndex}'/0/0 (optional, requires mina-signer)
|
|
100
|
+
*
|
|
101
|
+
* All four chains vary by `accountIndex`, so distinct indices yield fully
|
|
102
|
+
* distinct multi-chain identities from one seed. Index 0 is unchanged from the
|
|
103
|
+
* historical fixed paths.
|
|
104
|
+
*
|
|
105
|
+
* @param mnemonic - A valid BIP-39 mnemonic (12 or 24 words).
|
|
106
|
+
* @param options - Optional derivation options (accountIndex defaults to 0).
|
|
107
|
+
* @returns The derived ToonIdentity with all chain identities populated.
|
|
108
|
+
* @throws {IdentityError} If the mnemonic is invalid.
|
|
109
|
+
*/
|
|
110
|
+
declare function fromMnemonicFull(mnemonic: string, options?: FromMnemonicOptions): Promise<ToonIdentity>;
|
|
111
|
+
/**
|
|
112
|
+
* Generates a random Solana Ed25519 keypair (non-deterministic).
|
|
113
|
+
*
|
|
114
|
+
* For deterministic derivation from a mnemonic, use fromMnemonic() instead.
|
|
115
|
+
*
|
|
116
|
+
* @returns A SolanaIdentity with random keypair.
|
|
117
|
+
*/
|
|
118
|
+
declare function generateSolanaKeypair(): SolanaIdentity;
|
|
119
|
+
/**
|
|
120
|
+
* Encodes a byte array to a Base58 string (Bitcoin/Solana alphabet).
|
|
121
|
+
*/
|
|
122
|
+
declare function base58Encode(bytes: Uint8Array): string;
|
|
123
|
+
/**
|
|
124
|
+
* Decodes a Base58 string to a byte array (Bitcoin/Solana alphabet).
|
|
125
|
+
*/
|
|
126
|
+
declare function base58Decode(str: string): Uint8Array;
|
|
59
127
|
|
|
60
128
|
/**
|
|
61
129
|
* SDK-specific error classes for @toon-protocol/sdk.
|
|
@@ -97,6 +165,61 @@ declare class VerificationError extends ToonError {
|
|
|
97
165
|
declare class PricingError extends ToonError {
|
|
98
166
|
constructor(message: string, cause?: Error);
|
|
99
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Error thrown when NIP-59 gift wrap or NIP-44 FULFILL encryption operations fail.
|
|
170
|
+
* Used for wrap/unwrap failures, decryption errors, and malformed gift wrap events.
|
|
171
|
+
*/
|
|
172
|
+
declare class GiftWrapError extends ToonError {
|
|
173
|
+
constructor(message: string, cause?: Error);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Error thrown when Mill swap handler orchestration fails.
|
|
177
|
+
* Used for rate-conversion errors (invalid format, zero, overflow guards),
|
|
178
|
+
* unsupported pair lookups, and issuer-boundary failures that are NOT
|
|
179
|
+
* gift-wrap-specific. Gift-wrap failures continue to surface as `GiftWrapError`.
|
|
180
|
+
*/
|
|
181
|
+
declare class SwapHandlerError extends ToonError {
|
|
182
|
+
constructor(message: string, cause?: Error);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Error thrown by the sender-side `streamSwap()` API (Story 12.5).
|
|
186
|
+
*
|
|
187
|
+
* All failures are categorized by a narrow `code` so callers can branch on
|
|
188
|
+
* cause. `INVALID_*` codes are construction-time validation failures (thrown
|
|
189
|
+
* synchronously before any packet fires). `FULFILL_DECODE_FAILED` surfaces
|
|
190
|
+
* when the Mill returns `accepted: true` but the FULFILL data cannot be
|
|
191
|
+
* decoded — this is a non-fatal per-packet error and is captured in
|
|
192
|
+
* `StreamSwapResult.errors[]`.
|
|
193
|
+
*/
|
|
194
|
+
declare class StreamSwapError extends Error {
|
|
195
|
+
readonly code: 'INVALID_AMOUNT' | 'INVALID_CHUNKING' | 'INVALID_PAIR' | 'INVALID_STATE' | 'INVALID_CHAIN_RECIPIENT' | 'FULFILL_DECODE_FAILED';
|
|
196
|
+
readonly cause?: unknown;
|
|
197
|
+
constructor(code: StreamSwapError['code'], message: string, options?: {
|
|
198
|
+
cause?: unknown;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Error thrown by the sender-side `buildSettlementTx()` helper (Story 12.6).
|
|
203
|
+
*
|
|
204
|
+
* Settlement is a post-swap one-shot computation, so this error class is
|
|
205
|
+
* THROWN synchronously (unlike `streamSwap` which routes per-packet failures
|
|
206
|
+
* through `StreamSwapResult`). Callers are expected to wrap the call in
|
|
207
|
+
* `try/catch`.
|
|
208
|
+
*
|
|
209
|
+
* Narrow `code` union lets callers branch on cause — see
|
|
210
|
+
* `_bmad-output/implementation-artifacts/12-6-build-settlement-tx.md` AC-11
|
|
211
|
+
* for the per-code semantics.
|
|
212
|
+
*
|
|
213
|
+
* @since 12.6
|
|
214
|
+
* @stable — Epic 13 Chain Bridge DVM depends on this error shape.
|
|
215
|
+
*/
|
|
216
|
+
declare class SettlementTxError extends Error {
|
|
217
|
+
readonly code: 'INVALID_INPUT' | 'MISSING_SETTLEMENT_METADATA' | 'UNSUPPORTED_CHAIN' | 'MISSING_RECIPIENT' | 'RECIPIENT_MISMATCH' | 'MILL_SIGNER_MISMATCH' | 'DUPLICATE_NONCE' | 'NON_MONOTONIC_CUMULATIVE' | 'INVALID_SIGNATURE_LENGTH' | 'INVALID_SIGNATURE_V' | 'ENCODING_FAILED';
|
|
218
|
+
readonly cause?: unknown;
|
|
219
|
+
constructor(code: SettlementTxError['code'], message: string, options?: {
|
|
220
|
+
cause?: unknown;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
100
223
|
|
|
101
224
|
/**
|
|
102
225
|
* Handler context for @toon-protocol/sdk.
|
|
@@ -165,6 +288,11 @@ declare class HandlerRegistry {
|
|
|
165
288
|
* Returns all registered kind numbers, sorted ascending.
|
|
166
289
|
*/
|
|
167
290
|
getRegisteredKinds(): number[];
|
|
291
|
+
/**
|
|
292
|
+
* Returns the handler registered for `kind`, or `undefined` if none.
|
|
293
|
+
* Added for Story 12.7 AC-10 (handler-registration verification).
|
|
294
|
+
*/
|
|
295
|
+
get(kind: number): Handler | undefined;
|
|
168
296
|
/**
|
|
169
297
|
* Returns registered kinds in the DVM request range (5000-5999), sorted ascending.
|
|
170
298
|
* Uses JOB_REQUEST_KIND_BASE (5000) as the range start.
|
|
@@ -451,6 +579,12 @@ interface NodeConfig {
|
|
|
451
579
|
* Only used when auto-creating an embedded connector.
|
|
452
580
|
*/
|
|
453
581
|
chainProviders?: ChainProviderConfigEntry[];
|
|
582
|
+
/**
|
|
583
|
+
* Transport configuration for the embedded connector (ator/SOCKS5 privacy overlay).
|
|
584
|
+
* When provided, passed directly to ConnectorNode as `transport`.
|
|
585
|
+
* Only used when auto-creating an embedded connector.
|
|
586
|
+
*/
|
|
587
|
+
transport?: TransportConfig;
|
|
454
588
|
/**
|
|
455
589
|
* NIP-59 transport privacy configuration for the embedded connector.
|
|
456
590
|
* When enabled, per-packet claims are wrapped in three-layer encryption.
|
|
@@ -1034,12 +1168,16 @@ interface ArweaveUploadAdapter {
|
|
|
1034
1168
|
/**
|
|
1035
1169
|
* Turbo SDK upload adapter using @ardrive/turbo-sdk.
|
|
1036
1170
|
*
|
|
1037
|
-
* - Dev/free tier (<=100KB): pass no turboClient
|
|
1038
|
-
*
|
|
1171
|
+
* - Dev/free tier (<=100KB): pass no turboClient. getClient() lazily generates an
|
|
1172
|
+
* ephemeral RSA JWK and builds a TurboFactory.authenticated() client. The upload
|
|
1173
|
+
* service grants free small-data-item uploads to any valid signer regardless of
|
|
1174
|
+
* balance, so no deposit is required. NOTE: TurboFactory.unauthenticated() is NOT
|
|
1175
|
+
* usable here — in @ardrive/turbo-sdk >=1.40 uploadFile() exists only on the
|
|
1176
|
+
* authenticated client; the unauthenticated client exposes only uploadSignedDataItem().
|
|
1177
|
+
* - Prod (paid, uncapped): pass a TurboAuthenticatedClient from a funded wallet.
|
|
1039
1178
|
*
|
|
1040
1179
|
* The turboClient is typed as `unknown` to avoid importing @ardrive/turbo-sdk types
|
|
1041
|
-
* in this interface. The actual TurboAuthenticatedClient
|
|
1042
|
-
* is duck-typed at runtime.
|
|
1180
|
+
* in this interface. The actual TurboAuthenticatedClient is duck-typed at runtime.
|
|
1043
1181
|
*/
|
|
1044
1182
|
declare class TurboUploadAdapter implements ArweaveUploadAdapter {
|
|
1045
1183
|
private turboClient;
|
|
@@ -1210,4 +1348,604 @@ declare function uploadBlob(node: PublishableNode, blob: Buffer, destination: st
|
|
|
1210
1348
|
*/
|
|
1211
1349
|
declare function uploadBlobChunked(node: PublishableNode, blob: Buffer, destination: string, options: UploadBlobChunkedOptions): Promise<string>;
|
|
1212
1350
|
|
|
1213
|
-
|
|
1351
|
+
/**
|
|
1352
|
+
* Mill Swap Handler (Story 12.3)
|
|
1353
|
+
*
|
|
1354
|
+
* `createSwapHandler()` factory produces a kind:1059 `Handler` that:
|
|
1355
|
+
* 1. Unwraps an incoming NIP-59 gift-wrapped ILP swap packet (via Story 12.2).
|
|
1356
|
+
* 2. Identifies the requested `SwapPair` from inner-rumor `swap-from` / `swap-to` tags.
|
|
1357
|
+
* 3. Applies a per-packet exchange rate (pair.rate or live rateProvider hook).
|
|
1358
|
+
* 4. Delegates signed claim issuance to a pluggable `ClaimIssuer` (Story 12.4).
|
|
1359
|
+
* 5. NIP-44 encrypts the claim with an ephemeral key (Story 12.2) for return.
|
|
1360
|
+
*
|
|
1361
|
+
* The handler is a pure application-layer composition — no connector, routing,
|
|
1362
|
+
* or wallet code lives here. See `_bmad-output/epics/epic-12-token-swap-primitive.md`
|
|
1363
|
+
* for D12-001/D12-008/D12-009/D12-010 and the scope fence.
|
|
1364
|
+
*
|
|
1365
|
+
* Transport encoding: the `accept()` metadata emits `claim` as a base64-encoded
|
|
1366
|
+
* NIP-44 ciphertext, `ephemeralPubkey` as 64-char lowercase hex, and optional
|
|
1367
|
+
* `claimId`. The sender-side `streamSwap()` (Story 12.5) base64-decodes `claim`
|
|
1368
|
+
* before calling `decryptFulfillClaim`.
|
|
1369
|
+
*
|
|
1370
|
+
* @module
|
|
1371
|
+
*/
|
|
1372
|
+
|
|
1373
|
+
/** Parameters passed to a {@link ClaimIssuer.issueClaim} call. */
|
|
1374
|
+
interface IssueClaimParams {
|
|
1375
|
+
/** Source-asset amount received by the Mill (ILP packet amount, source micro-units). */
|
|
1376
|
+
sourceAmount: bigint;
|
|
1377
|
+
/** Target-asset amount owed to the sender (post-rate-conversion, target micro-units). */
|
|
1378
|
+
targetAmount: bigint;
|
|
1379
|
+
/** The `SwapPair` this packet is being priced against. */
|
|
1380
|
+
pair: SwapPair;
|
|
1381
|
+
/**
|
|
1382
|
+
* The sender's real Nostr pubkey (extracted from the unwrapped seal).
|
|
1383
|
+
*
|
|
1384
|
+
* Identity-layer key only: used by the Mill for inventory ledger keying and
|
|
1385
|
+
* the sender→channel sticky binding (`channelState.reserve()` /
|
|
1386
|
+
* `channelState.release()`). The Mill MUST NOT pass this to chain-layer
|
|
1387
|
+
* signers as the balance-proof `recipient` — use {@link chainRecipient}
|
|
1388
|
+
* for that (Story 12.9 D12-011).
|
|
1389
|
+
*/
|
|
1390
|
+
senderPubkey: string;
|
|
1391
|
+
/**
|
|
1392
|
+
* The sender's chain-specific payout address for `pair.to.chain`
|
|
1393
|
+
* (Story 12.9 AC-10). Extracted and format-validated from the rumor's
|
|
1394
|
+
* `chain-recipient` tag by the swap handler. REQUIRED. This is the
|
|
1395
|
+
* address the Mill's `PaymentChannelSigner` MUST use as the balance-proof
|
|
1396
|
+
* `recipient` (e.g., 20-byte EVM address, 32-byte Solana Ed25519 pubkey).
|
|
1397
|
+
*/
|
|
1398
|
+
chainRecipient: string;
|
|
1399
|
+
/** The inner rumor (for optional Mill-side context; may be ignored by the issuer). */
|
|
1400
|
+
rumor: UnsignedEvent;
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Result returned from {@link ClaimIssuer.issueClaim}.
|
|
1404
|
+
*
|
|
1405
|
+
* Story 12.6 extension: additive settlement-context fields let the sender
|
|
1406
|
+
* reconstruct the balance-proof message hash for signature verification and
|
|
1407
|
+
* on-chain settlement (see `buildSettlementTx()`).
|
|
1408
|
+
*/
|
|
1409
|
+
interface IssueClaimResult {
|
|
1410
|
+
/** Signed claim bytes ready for NIP-44 encryption (chain-specific format). */
|
|
1411
|
+
claim: Uint8Array;
|
|
1412
|
+
/** Optional Mill-side claim ID for logging/tracing. */
|
|
1413
|
+
claimId?: string;
|
|
1414
|
+
/** Channel identifier on the target chain. */
|
|
1415
|
+
channelId?: string;
|
|
1416
|
+
/** Balance-proof nonce (monotonically increasing per channel). */
|
|
1417
|
+
nonce?: bigint;
|
|
1418
|
+
/** Cumulative transferred amount on the channel (target micro-units). */
|
|
1419
|
+
cumulativeAmount?: bigint;
|
|
1420
|
+
/** Recipient address (the sender's target-asset address). */
|
|
1421
|
+
recipient?: string;
|
|
1422
|
+
/** Mill's on-chain signer address. */
|
|
1423
|
+
millSignerAddress?: string;
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Pluggable signed-claim issuer. Story 12.3 defines only the contract — the
|
|
1427
|
+
* concrete multi-chain implementation ships in Story 12.4.
|
|
1428
|
+
*
|
|
1429
|
+
* The issuer owns inventory accounting and signing-key material. The handler
|
|
1430
|
+
* relies on `issueClaim()` being atomic with inventory debit: if the call
|
|
1431
|
+
* resolves, the target-asset amount MUST be considered committed from the
|
|
1432
|
+
* Mill's reserves. If the call throws, no inventory change SHOULD have occurred.
|
|
1433
|
+
*/
|
|
1434
|
+
interface ClaimIssuer {
|
|
1435
|
+
/**
|
|
1436
|
+
* Produce a signed off-chain payment-channel claim in the target asset.
|
|
1437
|
+
*
|
|
1438
|
+
* @throws Error (or subclass) on insufficient reserves, unsupported pair,
|
|
1439
|
+
* or signing failure. Errors with `code === 'INSUFFICIENT_INVENTORY'` or
|
|
1440
|
+
* messages matching `/insufficient/i` are surfaced as ILP T04; all other
|
|
1441
|
+
* errors as T00.
|
|
1442
|
+
*/
|
|
1443
|
+
issueClaim(params: IssueClaimParams): Promise<IssueClaimResult>;
|
|
1444
|
+
}
|
|
1445
|
+
/** Parameters for {@link applyRate}. */
|
|
1446
|
+
interface ApplyRateParams {
|
|
1447
|
+
/** Source amount in source micro-units. */
|
|
1448
|
+
sourceAmount: bigint;
|
|
1449
|
+
/** `SwapPair.from.assetScale` (number of decimals on source side). */
|
|
1450
|
+
fromScale: number;
|
|
1451
|
+
/** `SwapPair.to.assetScale` (number of decimals on target side). */
|
|
1452
|
+
toScale: number;
|
|
1453
|
+
/** Decimal-string rate (target whole-units per source whole-unit). */
|
|
1454
|
+
rate: string;
|
|
1455
|
+
}
|
|
1456
|
+
/** Minimal pino-compatible logger interface. */
|
|
1457
|
+
interface SwapHandlerLogger {
|
|
1458
|
+
debug: (...args: unknown[]) => void;
|
|
1459
|
+
info: (...args: unknown[]) => void;
|
|
1460
|
+
warn: (...args: unknown[]) => void;
|
|
1461
|
+
error: (...args: unknown[]) => void;
|
|
1462
|
+
}
|
|
1463
|
+
/**
|
|
1464
|
+
* Minimal `Set`-like contract the handler requires from
|
|
1465
|
+
* `seenPacketIds`. Both the native `Set<string>` and
|
|
1466
|
+
* {@link BoundedSeenPacketIds} satisfy this; operators can swap in a
|
|
1467
|
+
* persistent/remote-backed replacement too.
|
|
1468
|
+
*/
|
|
1469
|
+
interface SeenPacketIdsLike {
|
|
1470
|
+
has(value: string): boolean;
|
|
1471
|
+
add(value: string): unknown;
|
|
1472
|
+
delete(value: string): boolean;
|
|
1473
|
+
}
|
|
1474
|
+
/** Configuration for {@link createSwapHandler}. */
|
|
1475
|
+
interface CreateSwapHandlerConfig {
|
|
1476
|
+
/** Mill's secp256k1 secret key for unwrapping gift-wrapped packets (32 bytes). */
|
|
1477
|
+
recipientSecretKey: Uint8Array;
|
|
1478
|
+
/** Swap pairs this Mill currently supports. */
|
|
1479
|
+
swapPairs: SwapPair[];
|
|
1480
|
+
/** Claim issuer delegate (Story 12.4 plugs in the multi-chain implementation). */
|
|
1481
|
+
claimIssuer: ClaimIssuer;
|
|
1482
|
+
/**
|
|
1483
|
+
* Optional live-rate override hook. When provided, the handler calls this per
|
|
1484
|
+
* packet instead of reading `pair.rate`. MUST return a decimal string matching
|
|
1485
|
+
* `SwapPair.rate` format: /^(0|[1-9]\d*)(\.\d+)?$/.
|
|
1486
|
+
*/
|
|
1487
|
+
rateProvider?: (pair: SwapPair) => string | Promise<string>;
|
|
1488
|
+
/**
|
|
1489
|
+
* Optional replay-protection set. When provided, the handler uses it
|
|
1490
|
+
* VERBATIM (operator-owned — bounding/persistence is the operator's
|
|
1491
|
+
* responsibility). When OMITTED (Story 12.8 AC-14), the handler
|
|
1492
|
+
* defaults to a {@link BoundedSeenPacketIds} with cap
|
|
1493
|
+
* {@link DEFAULT_SEEN_PACKET_IDS_CAP}. Any `Set`-shaped object with
|
|
1494
|
+
* `has`/`add`/`delete` (and a `size` getter for test introspection)
|
|
1495
|
+
* satisfies the contract.
|
|
1496
|
+
*/
|
|
1497
|
+
seenPacketIds?: SeenPacketIdsLike;
|
|
1498
|
+
/** Optional pino-compatible logger. Defaults to a no-op logger. */
|
|
1499
|
+
logger?: SwapHandlerLogger;
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* ILP REJECT codes emitted by `createSwapHandler()`.
|
|
1503
|
+
*
|
|
1504
|
+
* Exported as named constants so tests (Story 12.8 AC-3 forbids hardcoded
|
|
1505
|
+
* error-code strings) and downstream integrators can assert against the
|
|
1506
|
+
* same symbolic source the handler uses. Values follow RFC 27 / ILPv4
|
|
1507
|
+
* reject-code conventions (F01 = malformed, F02 = unreachable, F04 =
|
|
1508
|
+
* duplicate, F06 = unsupported pair, T00 = transient internal, T04 =
|
|
1509
|
+
* insufficient liquidity).
|
|
1510
|
+
*/
|
|
1511
|
+
declare const SWAP_HANDLER_REJECT_CODES: {
|
|
1512
|
+
/** Malformed / invalid PREPARE content — gift-wrap shape or amount invalid. */
|
|
1513
|
+
readonly INVALID_GIFT_WRAP: "F01";
|
|
1514
|
+
/** No route — the handler did not match a registered destination. */
|
|
1515
|
+
readonly UNREACHABLE: "F02";
|
|
1516
|
+
/** Duplicate packet — `seenPacketIds` replay hit. */
|
|
1517
|
+
readonly DUPLICATE_PACKET: "F04";
|
|
1518
|
+
/** Requested swap pair is not advertised by this Mill. */
|
|
1519
|
+
readonly UNSUPPORTED_PAIR: "F06";
|
|
1520
|
+
/** Transient internal failure — signing, rate provider, or unexpected. */
|
|
1521
|
+
readonly INTERNAL: "T00";
|
|
1522
|
+
/** Insufficient Mill inventory for the requested amount. */
|
|
1523
|
+
readonly INSUFFICIENT_LIQUIDITY: "T04";
|
|
1524
|
+
};
|
|
1525
|
+
/**
|
|
1526
|
+
* Human-readable reject messages emitted by `createSwapHandler()`.
|
|
1527
|
+
*
|
|
1528
|
+
* Tests may assert against these verbatim rather than matching regexes
|
|
1529
|
+
* (Story 12.8 AC-3 guidance).
|
|
1530
|
+
*/
|
|
1531
|
+
declare const SWAP_HANDLER_REJECT_MESSAGES: {
|
|
1532
|
+
readonly INVALID_GIFT_WRAP: "Invalid gift wrap";
|
|
1533
|
+
readonly INVALID_AMOUNT: "Invalid amount";
|
|
1534
|
+
readonly UNREACHABLE: "Unreachable";
|
|
1535
|
+
readonly DUPLICATE_PACKET: "Duplicate packet";
|
|
1536
|
+
readonly UNSUPPORTED_PAIR: "Unsupported swap pair";
|
|
1537
|
+
readonly INTERNAL: "Internal error";
|
|
1538
|
+
readonly INSUFFICIENT_LIQUIDITY: "Insufficient liquidity";
|
|
1539
|
+
readonly RATE_PROVIDER: "Rate provider error";
|
|
1540
|
+
readonly RATE_CONVERSION: "Rate conversion error";
|
|
1541
|
+
};
|
|
1542
|
+
/**
|
|
1543
|
+
* Apply a decimal-string exchange rate to a source amount across asset scales.
|
|
1544
|
+
* Uses BigInt arithmetic throughout — never coerces to `Number` — to preserve
|
|
1545
|
+
* 18-decimal EVM precision (Epic 11 retro MAX_SAFE_INTEGER guard).
|
|
1546
|
+
*
|
|
1547
|
+
* Rounds toward zero (integer division), which economically favors the Mill
|
|
1548
|
+
* (standard market-maker convention).
|
|
1549
|
+
*
|
|
1550
|
+
* @throws {SwapHandlerError} If rate format is invalid, rate is zero, or
|
|
1551
|
+
* sourceAmount is not positive.
|
|
1552
|
+
*/
|
|
1553
|
+
declare function applyRate(params: ApplyRateParams): bigint;
|
|
1554
|
+
/**
|
|
1555
|
+
* Find the `SwapPair` identified by the rumor's `swap-from` / `swap-to` tags.
|
|
1556
|
+
*
|
|
1557
|
+
* Each tag value is parsed as `<assetCode>:<chain>`, split on the FIRST `:`
|
|
1558
|
+
* so multi-segment chain IDs like `evm:base:8453` remain intact as the chain
|
|
1559
|
+
* portion. Returns `null` for any malformed/missing tag — the handler
|
|
1560
|
+
* interprets `null` as "unsupported pair" and rejects via ILP F06.
|
|
1561
|
+
*/
|
|
1562
|
+
declare function findSwapPair(rumor: UnsignedEvent, pairs: SwapPair[]): SwapPair | null;
|
|
1563
|
+
/**
|
|
1564
|
+
* Construct a kind:1059 Mill inbound-swap handler.
|
|
1565
|
+
*
|
|
1566
|
+
* The returned `Handler` is a pure closure over `config`; two calls with the
|
|
1567
|
+
* same config yield two independent-but-equivalent handlers. Register via
|
|
1568
|
+
* `node.handlers.on(1059, handler)` (Story 12.7).
|
|
1569
|
+
*
|
|
1570
|
+
* @throws {SwapHandlerError} At construction time if config is malformed.
|
|
1571
|
+
*/
|
|
1572
|
+
declare function createSwapHandler(config: CreateSwapHandlerConfig): Handler;
|
|
1573
|
+
|
|
1574
|
+
/**
|
|
1575
|
+
* Mina-specific settlement: balance-proof signature verification +
|
|
1576
|
+
* settlement-bundle construction (Story 12.8 follow-up to 12.6 AC-9).
|
|
1577
|
+
*
|
|
1578
|
+
* ## What is implemented (and unit-tested)
|
|
1579
|
+
*
|
|
1580
|
+
* - {@link verifyMinaSignature}: verifies the Mill's off-chain balance-proof
|
|
1581
|
+
* signature using `mina-signer` (`verifyFields`). This is the EXACT inverse
|
|
1582
|
+
* of the Mill's {@link MinaPaymentChannelSigner} (`packages/mill/src/payment-channel-signer.ts`),
|
|
1583
|
+
* which signs `balanceProofFieldsMina(channelId, cumulativeAmount, nonce, recipient)`
|
|
1584
|
+
* via `mina-signer`'s `signFields` and emits the base58 signature string as
|
|
1585
|
+
* the claim's `claimBytes` (UTF-8). The field-element derivation lives in
|
|
1586
|
+
* `hashes.ts` so signer and verifier cannot drift (same single-source-of-
|
|
1587
|
+
* truth pattern as EVM/Solana).
|
|
1588
|
+
* - {@link buildMinaSettlementTx}: constructs a {@link SettlementBundle}
|
|
1589
|
+
* envelope (chain metadata + the verified balance proof bytes) so a Chain
|
|
1590
|
+
* Bridge DVM / direct sender has everything needed to drive the on-chain
|
|
1591
|
+
* claim. The signature is re-emitted verbatim in `unsignedTxBytes`.
|
|
1592
|
+
*
|
|
1593
|
+
* ## What remains (documented gap — NOT silently stubbed)
|
|
1594
|
+
*
|
|
1595
|
+
* The final on-chain step — submitting a Mina zkApp `claimFromChannel`
|
|
1596
|
+
* transaction that settles the channel — requires **o1js circuit compilation
|
|
1597
|
+
* + zk-SNARK proof generation** (Poseidon balance-commitment, zkApp method
|
|
1598
|
+
* proving). The connector already implements this in
|
|
1599
|
+
* `MinaPaymentChannelSDK.claimFromChannel()` (o1js, heavyweight). That proof
|
|
1600
|
+
* generation is intentionally NOT done here: o1js circuit compilation is far
|
|
1601
|
+
* too heavy for a unit-testable SDK helper and would pull a multi-hundred-MB
|
|
1602
|
+
* WASM dependency into every SDK consumer. Instead, the bundle carries the
|
|
1603
|
+
* verified balance proof so a Mina-capable settler (the connector's
|
|
1604
|
+
* `MinaPaymentChannelProvider`, or a future o1js-backed Chain Bridge DVM) can
|
|
1605
|
+
* generate the proof + broadcast. See the on-chain settlement note below
|
|
1606
|
+
* (connector 3.8.1 wires the dual-party claim path — connector#84).
|
|
1607
|
+
*
|
|
1608
|
+
* Note also: the Mill↔sender wire proof here (a Schnorr signature over four
|
|
1609
|
+
* field elements) is a DIFFERENT object than the connector's on-chain
|
|
1610
|
+
* `MinaPaymentChannelSDK` Poseidon-commitment proof shape
|
|
1611
|
+
* (`{ commitment, signature, nonce }`). The verifier matches the Mill's
|
|
1612
|
+
* actual emitted format (`MinaPaymentChannelSigner`), which is what a sender
|
|
1613
|
+
* receives on-wire.
|
|
1614
|
+
*
|
|
1615
|
+
* @module
|
|
1616
|
+
* @since 12.8
|
|
1617
|
+
*/
|
|
1618
|
+
|
|
1619
|
+
/**
|
|
1620
|
+
* Minimal structural type for the slice of the `mina-signer` `Client` we use.
|
|
1621
|
+
* Declared locally so the SDK does not hard-depend on the optional peer dep's
|
|
1622
|
+
* full type surface (the ambient `mina-signer.d.ts` only declares
|
|
1623
|
+
* `derivePublicKey`). `verifyFields` is synchronous.
|
|
1624
|
+
*/
|
|
1625
|
+
interface MinaSignerClientLike {
|
|
1626
|
+
verifyFields(input: {
|
|
1627
|
+
data: bigint[];
|
|
1628
|
+
signature: string;
|
|
1629
|
+
publicKey: string;
|
|
1630
|
+
}): boolean;
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Lazily load `mina-signer` (optional peer dep) and instantiate a `Client`
|
|
1634
|
+
* bound to {@link MINA_NETWORK}. Returns `undefined` when the peer dep is not
|
|
1635
|
+
* installed — callers MUST treat that as "cannot verify Mina claims" rather
|
|
1636
|
+
* than "claim is valid".
|
|
1637
|
+
*
|
|
1638
|
+
* Mirrors the dynamic-import pattern in `identity.ts` (`deriveMinaIdentity`).
|
|
1639
|
+
*
|
|
1640
|
+
* @since 12.8
|
|
1641
|
+
*/
|
|
1642
|
+
declare function loadMinaSignerClient(): Promise<MinaSignerClientLike | undefined>;
|
|
1643
|
+
/**
|
|
1644
|
+
* Verify a Mina balance-proof Schnorr signature carried in an
|
|
1645
|
+
* `AccumulatedClaim`.
|
|
1646
|
+
*
|
|
1647
|
+
* Re-derives the signed field-element message via {@link balanceProofFieldsMina}
|
|
1648
|
+
* (identical to the Mill signer), decodes the claim's `claimBytes` to the
|
|
1649
|
+
* base58 signature string the Mill emitted, and verifies it against
|
|
1650
|
+
* `expectedSignerAddress` using a `mina-signer` `Client`.
|
|
1651
|
+
*
|
|
1652
|
+
* `client` MUST be a pre-loaded `mina-signer` `Client` (see
|
|
1653
|
+
* {@link loadMinaSignerClient}). It is injected (rather than imported inline)
|
|
1654
|
+
* so the synchronous `buildSettlementTx()` pipeline can verify Mina claims
|
|
1655
|
+
* without becoming async.
|
|
1656
|
+
*
|
|
1657
|
+
* @returns `true` iff the signature is valid for the given signer address.
|
|
1658
|
+
* @throws {SettlementTxError} on missing settlement metadata or a malformed
|
|
1659
|
+
* (non-UTF-8 / empty) signature payload.
|
|
1660
|
+
* @since 12.8
|
|
1661
|
+
*/
|
|
1662
|
+
declare function verifyMinaSignature(claim: AccumulatedClaim, expectedSignerAddress: string, client: MinaSignerClientLike): boolean;
|
|
1663
|
+
|
|
1664
|
+
/**
|
|
1665
|
+
* Public types for `buildSettlementTx()` (Story 12.6).
|
|
1666
|
+
*
|
|
1667
|
+
* @module
|
|
1668
|
+
* @since 12.6
|
|
1669
|
+
* @see _bmad-output/implementation-artifacts/12-6-build-settlement-tx.md
|
|
1670
|
+
*/
|
|
1671
|
+
|
|
1672
|
+
/**
|
|
1673
|
+
* Chain-specific raw settlement transaction bundle, produced by
|
|
1674
|
+
* `buildSettlementTx()`. Contains everything a Chain Bridge DVM
|
|
1675
|
+
* (Epic 13, kind:5260) or a direct sender needs to submit the settlement
|
|
1676
|
+
* on-chain.
|
|
1677
|
+
*
|
|
1678
|
+
* @stable — Epic 13 Chain Bridge DVM depends on this shape.
|
|
1679
|
+
* @since 12.6
|
|
1680
|
+
*/
|
|
1681
|
+
interface SettlementBundle {
|
|
1682
|
+
/** Target chain identifier (e.g., `'evm:8453'`, `'evm:42161'`, `'solana:mainnet'`, `'mina:mainnet'`). */
|
|
1683
|
+
chain: string;
|
|
1684
|
+
/** Chain family — drives per-chain parsing. */
|
|
1685
|
+
chainKind: 'evm' | 'solana' | 'mina';
|
|
1686
|
+
/** Channel identifier on the target chain (lowercase hex with 0x prefix for EVM; base58 for Solana). */
|
|
1687
|
+
channelId: string;
|
|
1688
|
+
/** Cumulative transferred amount settled by this tx (target micro-units, decimal string). */
|
|
1689
|
+
cumulativeAmount: string;
|
|
1690
|
+
/** Balance-proof nonce settled by this tx (decimal string). */
|
|
1691
|
+
nonce: string;
|
|
1692
|
+
/** Recipient address (the sender's target-asset address — the one that will receive funds). */
|
|
1693
|
+
recipient: string;
|
|
1694
|
+
/** Mill's on-chain signer address (expected signer of the balance-proof signature). */
|
|
1695
|
+
millSignerAddress: string;
|
|
1696
|
+
/**
|
|
1697
|
+
* Raw UNSIGNED transaction bytes ready for the caller to sign (or for a
|
|
1698
|
+
* Chain Bridge DVM to gas-sponsor + sign). EVM: RLP-encoded tx with
|
|
1699
|
+
* placeholder gas fields (tx nonce / gasPrice / gasLimit = 0) per EIP-155.
|
|
1700
|
+
* Solana: serialized Message (not Transaction — Transaction requires signatures).
|
|
1701
|
+
* Mina: the verified balance-proof signature bytes (envelope). The final
|
|
1702
|
+
* on-chain `claimFromChannel` zkApp tx requires o1js proof generation and is
|
|
1703
|
+
* produced by a Mina-capable settler — see the on-chain settlement note in
|
|
1704
|
+
* `packages/sdk/src/settlement/mina.ts` (connector 3.8.1 wires the dual-party
|
|
1705
|
+
* claim path — connector#84).
|
|
1706
|
+
*/
|
|
1707
|
+
unsignedTxBytes: Uint8Array;
|
|
1708
|
+
/**
|
|
1709
|
+
* Expected on-chain event signature (hex, 0x-prefixed keccak256 for EVM)
|
|
1710
|
+
* so a Chain Bridge DVM can watch for confirmation. Optional for
|
|
1711
|
+
* non-EVM chains that lack topic-based event signatures.
|
|
1712
|
+
*/
|
|
1713
|
+
expectedEventSignature?: string;
|
|
1714
|
+
/**
|
|
1715
|
+
* Number of `AccumulatedClaim` inputs in THIS bundle's `(chain, channelId)`
|
|
1716
|
+
* group that survived signature verification.
|
|
1717
|
+
*/
|
|
1718
|
+
claimsMerged: number;
|
|
1719
|
+
/** Index of the winning claim in the ORIGINAL input array (`BuildSettlementTxParams.claims`). */
|
|
1720
|
+
selectedClaimIndex: number;
|
|
1721
|
+
/** Source-asset chain of the SwapPair (for Chain Bridge bill-back). */
|
|
1722
|
+
sourceChain: string;
|
|
1723
|
+
/** Source-asset code of the SwapPair (for Chain Bridge bill-back). */
|
|
1724
|
+
sourceAssetCode: string;
|
|
1725
|
+
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Per-chain Mill signer configuration.
|
|
1728
|
+
*
|
|
1729
|
+
* @since 12.6
|
|
1730
|
+
*/
|
|
1731
|
+
interface MillSignerConfig {
|
|
1732
|
+
/**
|
|
1733
|
+
* Expected on-chain signer address for the Mill. EVM: 0x + 40 lowercase
|
|
1734
|
+
* hex chars. Solana: base58-encoded 32-byte Ed25519 pubkey. Mina: base58 pubkey.
|
|
1735
|
+
*/
|
|
1736
|
+
address: string;
|
|
1737
|
+
/**
|
|
1738
|
+
* On-chain payment-channel contract address (EVM-only).
|
|
1739
|
+
*/
|
|
1740
|
+
contractAddress?: string;
|
|
1741
|
+
/**
|
|
1742
|
+
* Solana on-chain program ID. Required for Solana claims.
|
|
1743
|
+
*/
|
|
1744
|
+
programId?: string;
|
|
1745
|
+
/**
|
|
1746
|
+
* EVM chain-id (decimal). Required for EVM claims — baked into RLP per EIP-155.
|
|
1747
|
+
*/
|
|
1748
|
+
chainId?: number;
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Parameters for `buildSettlementTx()`.
|
|
1752
|
+
*
|
|
1753
|
+
* @stable — Epic 13 Chain Bridge DVM depends on this shape.
|
|
1754
|
+
* @since 12.6
|
|
1755
|
+
*/
|
|
1756
|
+
interface BuildSettlementTxParams {
|
|
1757
|
+
/** Claims to settle. Typically `streamSwapResult.claims`. MUST be non-empty. */
|
|
1758
|
+
claims: readonly AccumulatedClaim[];
|
|
1759
|
+
/** Per-chain Mill signer configuration. Keyed by `claim.pair.to.chain`. */
|
|
1760
|
+
signers: Record<string, MillSignerConfig>;
|
|
1761
|
+
/** Sender's target-asset address per chain. Keyed by `claim.pair.to.chain`. */
|
|
1762
|
+
recipients: Record<string, string>;
|
|
1763
|
+
/** When `true` (default), verify every claim's signature against `signers[chain].address`. */
|
|
1764
|
+
verifySignatures?: boolean;
|
|
1765
|
+
/**
|
|
1766
|
+
* Pre-loaded `mina-signer` `Client` (optional peer dep). REQUIRED to verify
|
|
1767
|
+
* `mina:*` claims when `verifySignatures` is on: `buildSettlementTx()` is
|
|
1768
|
+
* synchronous and `mina-signer` only loads via async `import()`, so the
|
|
1769
|
+
* caller must load it up front (see `loadMinaSignerClient()`) and inject it
|
|
1770
|
+
* here. When a `mina:*` claim is present and this is absent, that claim is
|
|
1771
|
+
* rejected with `MINA_VERIFICATION_UNSUPPORTED` rather than passed through
|
|
1772
|
+
* unverified. Ignored for EVM/Solana claims.
|
|
1773
|
+
*/
|
|
1774
|
+
minaSignerClient?: MinaSignerClientLike;
|
|
1775
|
+
/** When `true`, include superseded claims in `result.superseded[]`. Default false. */
|
|
1776
|
+
includeSuperseded?: boolean;
|
|
1777
|
+
/** Optional pino-compatible logger. */
|
|
1778
|
+
logger?: {
|
|
1779
|
+
debug: (...a: unknown[]) => void;
|
|
1780
|
+
info: (...a: unknown[]) => void;
|
|
1781
|
+
warn: (...a: unknown[]) => void;
|
|
1782
|
+
error: (...a: unknown[]) => void;
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Result of `buildSettlementTx()`.
|
|
1787
|
+
*
|
|
1788
|
+
* @stable — Epic 13 Chain Bridge DVM depends on this shape.
|
|
1789
|
+
* @since 12.6
|
|
1790
|
+
*/
|
|
1791
|
+
interface BuildSettlementTxResult {
|
|
1792
|
+
/** One bundle per unique (chain, channelId) group that had at least one surviving claim. */
|
|
1793
|
+
bundles: SettlementBundle[];
|
|
1794
|
+
/** Claims rejected during signature verification. */
|
|
1795
|
+
rejected: {
|
|
1796
|
+
claim: AccumulatedClaim;
|
|
1797
|
+
reason: 'SIGNATURE_INVALID' | 'SIGNER_MISMATCH' | 'MINA_VERIFICATION_UNSUPPORTED';
|
|
1798
|
+
details?: string;
|
|
1799
|
+
}[];
|
|
1800
|
+
/** Claims superseded by a higher-nonce claim in the same group (only populated if params.includeSuperseded). */
|
|
1801
|
+
superseded: AccumulatedClaim[];
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
/**
|
|
1805
|
+
* EVM-specific settlement tx construction + signature verification
|
|
1806
|
+
* (Story 12.6 AC-7).
|
|
1807
|
+
*
|
|
1808
|
+
* @module
|
|
1809
|
+
* @since 12.6
|
|
1810
|
+
* @see _bmad-output/implementation-artifacts/12-6-build-settlement-tx.md
|
|
1811
|
+
*/
|
|
1812
|
+
|
|
1813
|
+
/**
|
|
1814
|
+
* Re-encode an EVM settlement bundle's RLP with real tx-nonce / gasPrice /
|
|
1815
|
+
* gasLimit values. The `to`, `value`, `data`, `chainId` fields are preserved
|
|
1816
|
+
* from the original bundle.
|
|
1817
|
+
*
|
|
1818
|
+
* @stable
|
|
1819
|
+
* @since 12.6
|
|
1820
|
+
*/
|
|
1821
|
+
declare function fillEvmSettlementTxGas(bundle: SettlementBundle, gas: {
|
|
1822
|
+
nonce: bigint;
|
|
1823
|
+
gasPrice: bigint;
|
|
1824
|
+
gasLimit: bigint;
|
|
1825
|
+
}, signer: MillSignerConfig): Uint8Array;
|
|
1826
|
+
|
|
1827
|
+
/**
|
|
1828
|
+
* `buildSettlementTx()` — public entrypoint for Story 12.6.
|
|
1829
|
+
*
|
|
1830
|
+
* Takes the output `claims` array from `streamSwap()` + per-chain signer
|
|
1831
|
+
* config + per-chain recipient addresses, and produces one
|
|
1832
|
+
* {@link SettlementBundle} per unique `(chain, channelId)` group.
|
|
1833
|
+
*
|
|
1834
|
+
* @module
|
|
1835
|
+
* @since 12.6
|
|
1836
|
+
* @see _bmad-output/implementation-artifacts/12-6-build-settlement-tx.md
|
|
1837
|
+
*/
|
|
1838
|
+
|
|
1839
|
+
/**
|
|
1840
|
+
* Build raw unsigned settlement transactions from a bag of accumulated
|
|
1841
|
+
* swap claims.
|
|
1842
|
+
*
|
|
1843
|
+
* Algorithm:
|
|
1844
|
+
* 1. Validate params (synchronous throws on malformed input).
|
|
1845
|
+
* 2. Optionally verify each claim's signature. Rejected claims land in
|
|
1846
|
+
* `result.rejected[]` and are dropped from further processing.
|
|
1847
|
+
* 3. Group surviving claims by `(chain, channelId)`. Within each group,
|
|
1848
|
+
* assert recipient + millSignerAddress consensus, unique nonces, and
|
|
1849
|
+
* non-decreasing cumulativeAmount with nonce.
|
|
1850
|
+
* 4. Pick the winning claim per group (highest nonce).
|
|
1851
|
+
* 5. Dispatch each winner to its chain-specific tx builder.
|
|
1852
|
+
*
|
|
1853
|
+
* @stable
|
|
1854
|
+
* @since 12.6
|
|
1855
|
+
* @throws {SettlementTxError} Synchronously on malformed input, group-level
|
|
1856
|
+
* inconsistency, or chain dispatch failures.
|
|
1857
|
+
*
|
|
1858
|
+
* @example
|
|
1859
|
+
* ```ts
|
|
1860
|
+
* const result = await streamSwap({ ... });
|
|
1861
|
+
* const { bundles } = buildSettlementTx({
|
|
1862
|
+
* claims: result.claims,
|
|
1863
|
+
* signers: {
|
|
1864
|
+
* 'evm:base:8453': {
|
|
1865
|
+
* address: '0xmill...',
|
|
1866
|
+
* contractAddress: '0xtokennetwork...',
|
|
1867
|
+
* chainId: 8453,
|
|
1868
|
+
* },
|
|
1869
|
+
* },
|
|
1870
|
+
* recipients: { 'evm:base:8453': '0xsender...' },
|
|
1871
|
+
* });
|
|
1872
|
+
* // Feed bundles[0].unsignedTxBytes into fillEvmSettlementTxGas → sign → eth_sendRawTransaction.
|
|
1873
|
+
* ```
|
|
1874
|
+
*/
|
|
1875
|
+
declare function buildSettlementTx(params: BuildSettlementTxParams): BuildSettlementTxResult;
|
|
1876
|
+
/**
|
|
1877
|
+
* Standalone utility: verify a single `AccumulatedClaim`'s signature against
|
|
1878
|
+
* a `MillSignerConfig` without running the full grouping/winner pipeline.
|
|
1879
|
+
*
|
|
1880
|
+
* Useful inside a `streamSwap()` `onPacket` callback for mid-stream claim
|
|
1881
|
+
* validation.
|
|
1882
|
+
*
|
|
1883
|
+
* For `mina:*` claims, pass a pre-loaded `mina-signer` `Client` as
|
|
1884
|
+
* `minaSignerClient` (see `loadMinaSignerClient()`); without it, Mina claims
|
|
1885
|
+
* return `MINA_VERIFICATION_UNSUPPORTED` (same contract as
|
|
1886
|
+
* `buildSettlementTx`).
|
|
1887
|
+
*
|
|
1888
|
+
* @stable
|
|
1889
|
+
* @since 12.6
|
|
1890
|
+
*/
|
|
1891
|
+
declare function verifyAccumulatedClaim(claim: AccumulatedClaim, signer: MillSignerConfig, minaSignerClient?: MinaSignerClientLike): {
|
|
1892
|
+
valid: true;
|
|
1893
|
+
} | {
|
|
1894
|
+
valid: false;
|
|
1895
|
+
reason: string;
|
|
1896
|
+
};
|
|
1897
|
+
|
|
1898
|
+
/**
|
|
1899
|
+
* Solana-specific settlement tx construction + signature verification
|
|
1900
|
+
* (Story 12.6 AC-9).
|
|
1901
|
+
*
|
|
1902
|
+
* @module
|
|
1903
|
+
* @since 12.6
|
|
1904
|
+
* @see _bmad-output/implementation-artifacts/12-6-build-settlement-tx.md
|
|
1905
|
+
*/
|
|
1906
|
+
|
|
1907
|
+
/**
|
|
1908
|
+
* Verify a Solana Ed25519 balance-proof signature.
|
|
1909
|
+
*
|
|
1910
|
+
* @since 12.6
|
|
1911
|
+
*/
|
|
1912
|
+
declare function verifyEd25519Signature(claim: AccumulatedClaim, expectedSignerAddress: string): boolean;
|
|
1913
|
+
|
|
1914
|
+
/**
|
|
1915
|
+
* DvmHealthResponse — canonical type for the DVM BLS health endpoint.
|
|
1916
|
+
* Exported from @toon-protocol/sdk so Townhouse and the entrypoint share
|
|
1917
|
+
* the same definition (mirrors MillHealthResponse from @toon-protocol/mill).
|
|
1918
|
+
*/
|
|
1919
|
+
/** Per-kind job count for jobsRecent.byKind */
|
|
1920
|
+
interface DvmJobsByKindEntry {
|
|
1921
|
+
kind: number;
|
|
1922
|
+
count: number;
|
|
1923
|
+
}
|
|
1924
|
+
/** Per-status job counts for the sliding window */
|
|
1925
|
+
interface DvmJobsByStatus {
|
|
1926
|
+
processing: number;
|
|
1927
|
+
success: number;
|
|
1928
|
+
error: number;
|
|
1929
|
+
partial: number;
|
|
1930
|
+
}
|
|
1931
|
+
/** Windowed recent-jobs telemetry (default window: 5 min) */
|
|
1932
|
+
interface DvmJobsRecent {
|
|
1933
|
+
total: number;
|
|
1934
|
+
byKind: DvmJobsByKindEntry[];
|
|
1935
|
+
byStatus: DvmJobsByStatus;
|
|
1936
|
+
}
|
|
1937
|
+
/** Response shape for GET /health on the DVM BLS server (port 3400). */
|
|
1938
|
+
interface DvmHealthResponse {
|
|
1939
|
+
status: 'starting' | 'ok' | 'stopping' | 'stopped' | 'error';
|
|
1940
|
+
version: string;
|
|
1941
|
+
nodePubkey: string;
|
|
1942
|
+
uptimeSec: number;
|
|
1943
|
+
/** Registered handler event kinds (e.g. [5094, 5250]). */
|
|
1944
|
+
handlerKinds: number[];
|
|
1945
|
+
/** Per-kind pricing in string-encoded bigint (e.g. { "5094": "10", "5250": "10000" }). */
|
|
1946
|
+
kindPricing: Record<string, string>;
|
|
1947
|
+
basePricePerByte: string;
|
|
1948
|
+
jobsRecent: DvmJobsRecent;
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
export { AccumulatedClaim, type AddChunkResult, type ApplyRateParams, type ArweaveDvmConfig, type ArweaveUploadAdapter, type BuildSettlementTxParams, type BuildSettlementTxResult, type BuildSkillDescriptorConfig, ChunkManager, type ChunkManagerConfig, type ClaimIssuer, type CreateHandlerContextOptions, type CreateSwapHandlerConfig, type DvmHealthResponse, type DvmJobsByKindEntry, type DvmJobsByStatus, type DvmJobsRecent, type FromMnemonicOptions, GiftWrapError, type Handler, type HandlerContext, HandlerError, HandlerRegistry, type HandlerResponse, IdentityError, type IssueClaimParams, type IssueClaimResult, type MillSignerConfig, type MinaIdentity, type MinaSignerClientLike, type NodeConfig, NodeError, type NodeIdentity, type PaymentHandlerBridgeConfig, type PaymentRequest, type PaymentResponse, type PrefixClaimHandlerOptions, PricingError, type PricingValidationResult, type PricingValidatorConfig, type PublishEventResult, type PublishableNode, SWAP_HANDLER_REJECT_CODES, SWAP_HANDLER_REJECT_MESSAGES, type ServiceNode, type SettlementBundle, SettlementTxError, type SolanaIdentity, type StartResult, StreamSwapError, SwapHandlerError, type SwapHandlerLogger, SwarmCoordinator, type SwarmCoordinatorOptions, type SwarmState, type ToonIdentity, TurboUploadAdapter, type UploadBlobChunkedOptions, type UploadBlobOptions, VerificationError, type VerificationPipelineConfig, type VerificationResult, type WorkflowEventStore, WorkflowOrchestrator, type WorkflowOrchestratorOptions, type WorkflowState, applyRate, base58Decode, base58Encode, buildSettlementTx, buildSkillDescriptor, createArweaveDvmHandler, createEventStorageHandler, createHandlerContext, createNode, createPaymentHandlerBridge, createPrefixClaimHandler, createPricingValidator, createSwapHandler, createVerificationPipeline, fillEvmSettlementTxGas, findSwapPair, fromMnemonic, fromMnemonicFull, fromSecretKey, generateMnemonic, generateSolanaKeypair, loadMinaSignerClient, uploadBlob, uploadBlobChunked, verifyAccumulatedClaim, verifyEd25519Signature, verifyMinaSignature };
|