@x1id/resolve 0.22.0 → 0.43.0
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 +71 -0
- package/dist/accounts.d.ts +6 -0
- package/dist/accounts.js +6 -1
- package/dist/agent.d.ts +184 -8
- package/dist/agent.js +351 -3
- package/dist/agentPolicy.d.ts +238 -0
- package/dist/agentPolicy.js +364 -0
- package/dist/attestation.d.ts +25 -0
- package/dist/attestation.js +25 -0
- package/dist/checkout.d.ts +216 -0
- package/dist/checkout.js +327 -0
- package/dist/credentials.d.ts +466 -0
- package/dist/credentials.js +669 -0
- package/dist/gate.d.ts +94 -4
- package/dist/gate.js +206 -7
- package/dist/gateClient.d.ts +12 -0
- package/dist/giftLink.d.ts +272 -0
- package/dist/giftLink.js +452 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +33 -0
- package/dist/loginButton.d.ts +69 -0
- package/dist/loginButton.js +207 -0
- package/dist/logo.d.ts +1 -0
- package/dist/logo.js +8 -0
- package/dist/messaging.d.ts +439 -0
- package/dist/messaging.js +979 -0
- package/dist/mintNft.d.ts +247 -0
- package/dist/mintNft.js +328 -0
- package/dist/nsGate.d.ts +98 -0
- package/dist/nsGate.js +172 -0
- package/dist/oidc.d.ts +272 -0
- package/dist/oidc.js +641 -0
- package/dist/pay.d.ts +513 -0
- package/dist/pay.js +756 -0
- package/dist/payment.d.ts +9 -2
- package/dist/payment.js +9 -2
- package/dist/recovery.d.ts +186 -0
- package/dist/recovery.js +276 -0
- package/dist/recoveryNft.d.ts +183 -0
- package/dist/recoveryNft.js +291 -0
- package/dist/shield.d.ts +373 -0
- package/dist/shield.js +695 -0
- package/dist/subscription.d.ts +439 -0
- package/dist/subscription.js +642 -0
- package/dist/textRecords.d.ts +52 -6
- package/dist/textRecords.js +80 -8
- package/dist/types.d.ts +3 -0
- package/dist/x402Receipt.d.ts +246 -0
- package/dist/x402Receipt.js +374 -0
- package/package.json +18 -1
- package/schema/agent-manifest.json +91 -8
package/dist/shield.d.ts
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shield: confidential zXNT / zUSDC.X on X1 (docs/specs/shield-confidential-tokens.md).
|
|
3
|
+
*
|
|
4
|
+
* What this module gives an integrator, with no dependencies and no proofs:
|
|
5
|
+
*
|
|
6
|
+
* - the Shield addresses, derived exactly like `programs/x1-shield`:
|
|
7
|
+
* z-mint `["z-mint", backing]`, `ShieldMint` `["shield-mint", z_mint]`, the
|
|
8
|
+
* reserve (the ShieldMint PDA's associated token account of the backing
|
|
9
|
+
* mint) and a holder's Shield account (their Token-2022 ATA of the z-mint);
|
|
10
|
+
* - the `shield` / `unshield` instruction builders (`buildShieldIx`,
|
|
11
|
+
* `buildUnshieldIx`);
|
|
12
|
+
* - decoders for a `ShieldMint` record and a Token-2022 account's
|
|
13
|
+
* `ConfidentialTransferAccount` extension, plus the "ready to receive
|
|
14
|
+
* privately" rule (spec §7);
|
|
15
|
+
* - {@link resolveShieldRecipient}: `@name` → the address to pay under the
|
|
16
|
+
* one payment rule (verified X1 record, else the current authority), its
|
|
17
|
+
* Shield account and whether it is ready, honouring the `x1.shield = off`
|
|
18
|
+
* opt-out text record and refusing reserved (treasury-held) names;
|
|
19
|
+
* - payment receipts (`x1receipt1…`): a strict bech32m codec, and
|
|
20
|
+
* {@link verifyShieldReceipt}, which finds the payment's proof data on chain
|
|
21
|
+
* and hands it to a commitment checker.
|
|
22
|
+
*
|
|
23
|
+
* Proof generation and the elliptic-curve check of a receipt stay in the
|
|
24
|
+
* separate `shield-proofs` WASM (spec §7: "so the SDK stays light"); this
|
|
25
|
+
* module takes that check as a function (`checkCommitments`), e.g.
|
|
26
|
+
* `(r, kind, data) => wasm.verifyReceiptAgainstProof(r, kind, data)`.
|
|
27
|
+
*
|
|
28
|
+
* PDAs come through an injected {@link PdaFinder}, like every other builder in
|
|
29
|
+
* this package: it never hand-rolls the ed25519 on-curve check.
|
|
30
|
+
*/
|
|
31
|
+
import { type RpcFn } from "./accounts.js";
|
|
32
|
+
import type { AddressLike, BuiltInstruction } from "./delegate.js";
|
|
33
|
+
import type { PdaFinder } from "./namespacePricing.js";
|
|
34
|
+
import { type PaymentBasis } from "./payment.js";
|
|
35
|
+
import type { WasmResolver } from "./wasm.js";
|
|
36
|
+
/** `programs/x1-shield` as deployed on X1 TESTNET (S1). Mainnet is not
|
|
37
|
+
* deployed yet (owner gate S5); a mainnet deploy may use its own id, so
|
|
38
|
+
* integrators should take the id from their network config. */
|
|
39
|
+
export declare const SHIELD_PROGRAM_ID_TESTNET = "7Kqs3Nu82F1NCoUgnKEBUyW2uiftRXQjc7vJ3D2Zdzxo";
|
|
40
|
+
export declare const TOKEN_2022_PROGRAM_ID = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
41
|
+
/** Classic SPL Token (p-token on X1) — the wrapped-native mint's program. */
|
|
42
|
+
export declare const SPL_TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
43
|
+
export declare const ASSOCIATED_TOKEN_PROGRAM_ID = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
44
|
+
export declare const ZK_ELGAMAL_PROOF_PROGRAM_ID = "ZkE1Gama1Proof11111111111111111111111111111";
|
|
45
|
+
/** Wrapped-native mint: the backing of zXNT. */
|
|
46
|
+
export declare const NATIVE_MINT = "So11111111111111111111111111111111111111112";
|
|
47
|
+
/** USDC.X on X1 mainnet: the backing of zUSDC.X there (spec §3). */
|
|
48
|
+
export declare const USDCX_MINT_MAINNET = "B69chRzqzDCmdB5WYB8NRu5Yv5ZA95ABiZcdzCgGm9Tq";
|
|
49
|
+
export declare const Z_MINT_SEED = "z-mint";
|
|
50
|
+
export declare const SHIELD_MINT_SEED = "shield-mint";
|
|
51
|
+
/** `sha256("global:shield")[0..8]`. */
|
|
52
|
+
export declare const SHIELD_DISCRIMINATOR: Uint8Array;
|
|
53
|
+
/** `sha256("global:unshield")[0..8]`. */
|
|
54
|
+
export declare const UNSHIELD_DISCRIMINATOR: Uint8Array;
|
|
55
|
+
/** `sha256("account:ShieldMint")[0..8]`. */
|
|
56
|
+
export declare const SHIELD_MINT_ACCOUNT_DISCRIMINATOR: Uint8Array;
|
|
57
|
+
/** Token-2022 caps one confidential Deposit at 2^48 − 1 base units, so one
|
|
58
|
+
* `shield` above that reverts (x1-shield FBL-0008): split it. */
|
|
59
|
+
export declare const MAX_SHIELD_AMOUNT: bigint;
|
|
60
|
+
/** The X1ID text record a name sets to `off` to opt out of being offered for
|
|
61
|
+
* private payments (spec §7). */
|
|
62
|
+
export declare const SHIELD_OPT_OUT_TEXT_KEY = "x1.shield";
|
|
63
|
+
declare function b64ToBytes(s: string): Uint8Array;
|
|
64
|
+
/** The canonical z-mint of `backingMint`: `["z-mint", backing]`. */
|
|
65
|
+
export declare function deriveZMint(find: PdaFinder, programId: AddressLike, backingMint: AddressLike): Promise<string>;
|
|
66
|
+
/** A z-mint's `ShieldMint` record (its mint authority and the reserve's
|
|
67
|
+
* owner): `["shield-mint", z_mint]`. */
|
|
68
|
+
export declare function deriveShieldMint(find: PdaFinder, programId: AddressLike, zMint: AddressLike): Promise<string>;
|
|
69
|
+
/** Associated token account of `owner` for `mint` under `tokenProgram`. */
|
|
70
|
+
export declare function deriveAssociatedTokenAccount(find: PdaFinder, owner: AddressLike, mint: AddressLike, tokenProgram: AddressLike): Promise<string>;
|
|
71
|
+
/** A holder's Shield account for `zMint`: their Token-2022 ATA of it. */
|
|
72
|
+
export declare function deriveShieldAccount(find: PdaFinder, owner: AddressLike, zMint: AddressLike): Promise<string>;
|
|
73
|
+
export interface ShieldTokenAccounts {
|
|
74
|
+
readonly zMint: string;
|
|
75
|
+
readonly shieldMint: string;
|
|
76
|
+
/** The ShieldMint PDA's ATA of the backing mint: the 1:1 reserve. */
|
|
77
|
+
readonly reserve: string;
|
|
78
|
+
}
|
|
79
|
+
export interface ShieldHolderAccounts extends ShieldTokenAccounts {
|
|
80
|
+
/** The holder's Shield account (Token-2022 ATA of the z-mint). */
|
|
81
|
+
readonly zAccount: string;
|
|
82
|
+
/** The holder's backing-token ATA (wrapped-native for zXNT): the source
|
|
83
|
+
* of a shield and the destination of an unshield. */
|
|
84
|
+
readonly backingAccount: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Derive every Shield address for `backingMint`, and for `owner` when given.
|
|
88
|
+
* `backingTokenProgram` is the backing mint's OWNER program (classic SPL Token
|
|
89
|
+
* for wrapped-native, Token-2022 for USDC.X); read it from chain for any other
|
|
90
|
+
* mint — x1-shield re-derives it and refuses a mismatch.
|
|
91
|
+
*/
|
|
92
|
+
export declare function deriveShieldAccounts(find: PdaFinder, p: {
|
|
93
|
+
programId: AddressLike;
|
|
94
|
+
backingMint: AddressLike;
|
|
95
|
+
backingTokenProgram: AddressLike;
|
|
96
|
+
}): Promise<ShieldTokenAccounts>;
|
|
97
|
+
export declare function deriveShieldAccounts(find: PdaFinder, p: {
|
|
98
|
+
programId: AddressLike;
|
|
99
|
+
backingMint: AddressLike;
|
|
100
|
+
backingTokenProgram: AddressLike;
|
|
101
|
+
owner: AddressLike;
|
|
102
|
+
}): Promise<ShieldHolderAccounts>;
|
|
103
|
+
export interface ShieldIxParams {
|
|
104
|
+
readonly programId: AddressLike;
|
|
105
|
+
/** The holder: signs, owns `zAccount` and `backingAccount`. */
|
|
106
|
+
readonly owner: AddressLike;
|
|
107
|
+
readonly shieldMint: AddressLike;
|
|
108
|
+
readonly zMint: AddressLike;
|
|
109
|
+
readonly backingMint: AddressLike;
|
|
110
|
+
/** shield: the backing SOURCE; unshield: the backing DESTINATION (owned by
|
|
111
|
+
* `owner` — the program refuses anything else). */
|
|
112
|
+
readonly backingAccount: AddressLike;
|
|
113
|
+
readonly reserve: AddressLike;
|
|
114
|
+
readonly zAccount: AddressLike;
|
|
115
|
+
readonly backingTokenProgram: AddressLike;
|
|
116
|
+
/** Base units of the backing token. */
|
|
117
|
+
readonly amount: bigint;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* `shield(amount)`: move backing into the reserve, mint exactly what arrived
|
|
121
|
+
* to the owner's Shield account and deposit it into its confidential PENDING
|
|
122
|
+
* balance. The owner's Shield account must already be configured for
|
|
123
|
+
* confidential balances. For zXNT, `backingAccount` is the owner's
|
|
124
|
+
* wrapped-native ATA, funded in the same transaction (create idempotent →
|
|
125
|
+
* system transfer → SyncNative → shield → CloseAccount; see
|
|
126
|
+
* programs/x1-shield/src/lib.rs "Client sequences").
|
|
127
|
+
*/
|
|
128
|
+
export declare function buildShieldIx(p: ShieldIxParams): BuiltInstruction;
|
|
129
|
+
/**
|
|
130
|
+
* `unshield(amount)`: burn `amount` from the owner's PUBLIC z-balance (put
|
|
131
|
+
* there by a Token-2022 confidential Withdraw earlier in the same
|
|
132
|
+
* transaction), verify the burn, release exactly that backing to
|
|
133
|
+
* `backingAccount`. Note the account order differs from `shield`.
|
|
134
|
+
*/
|
|
135
|
+
export declare function buildUnshieldIx(p: ShieldIxParams): BuiltInstruction;
|
|
136
|
+
/** Decoded `ShieldMint` record. */
|
|
137
|
+
export interface ShieldMintState {
|
|
138
|
+
readonly zMint: string;
|
|
139
|
+
readonly backingMint: string;
|
|
140
|
+
readonly reserve: string;
|
|
141
|
+
readonly backingTokenProgram: string;
|
|
142
|
+
readonly decimals: number;
|
|
143
|
+
/** Minted by shield minus burned by unshield (informational; the truth is
|
|
144
|
+
* z-mint supply vs reserve amount). */
|
|
145
|
+
readonly shieldedSupply: bigint;
|
|
146
|
+
}
|
|
147
|
+
/** `disc(8) z_mint(32) backing_mint(32) reserve(32) backing_token_program(32)
|
|
148
|
+
* decimals(1) shielded_supply(8) bump(1) z_mint_bump(1)`. Null when the bytes
|
|
149
|
+
* are not a ShieldMint. */
|
|
150
|
+
export declare function parseShieldMint(data: Uint8Array): ShieldMintState | null;
|
|
151
|
+
/** `ExtensionType::ConfidentialTransferAccount`. */
|
|
152
|
+
export declare const EXT_CONFIDENTIAL_TRANSFER_ACCOUNT = 5;
|
|
153
|
+
/** The `ConfidentialTransferAccount` extension: every encrypted balance. */
|
|
154
|
+
export interface ConfidentialAccountState {
|
|
155
|
+
readonly approved: boolean;
|
|
156
|
+
/** The account's ElGamal public key — what a payer encrypts to, and what a
|
|
157
|
+
* wallet's key derivation must reproduce (epoch lookup). */
|
|
158
|
+
readonly elgamalPubkey: Uint8Array;
|
|
159
|
+
readonly pendingLo: Uint8Array;
|
|
160
|
+
readonly pendingHi: Uint8Array;
|
|
161
|
+
/** Available balance ElGamal ciphertext (64 B). */
|
|
162
|
+
readonly available: Uint8Array;
|
|
163
|
+
/** Owner-decryptable AES ciphertext of the available balance (36 B). */
|
|
164
|
+
readonly decryptable: Uint8Array;
|
|
165
|
+
readonly allowConfidentialCredits: boolean;
|
|
166
|
+
readonly allowNonConfidentialCredits: boolean;
|
|
167
|
+
/** Credits since the last ApplyPendingBalance — the expected counter an
|
|
168
|
+
* apply must name. */
|
|
169
|
+
readonly pendingCreditCounter: bigint;
|
|
170
|
+
readonly maxPendingCreditCounter: bigint;
|
|
171
|
+
}
|
|
172
|
+
export interface DecodedTokenAccount {
|
|
173
|
+
readonly mint: string;
|
|
174
|
+
readonly owner: string;
|
|
175
|
+
/** Public (non-confidential) balance. */
|
|
176
|
+
readonly amount: bigint;
|
|
177
|
+
readonly ct: ConfidentialAccountState | null;
|
|
178
|
+
}
|
|
179
|
+
/** Decode a Token-2022 token account and its confidential extension. Null
|
|
180
|
+
* when the bytes are not a token account. Pure. */
|
|
181
|
+
export declare function decodeConfidentialTokenAccount(data: Uint8Array): DecodedTokenAccount | null;
|
|
182
|
+
export type ShieldReadiness = {
|
|
183
|
+
readonly kind: "ready";
|
|
184
|
+
readonly elgamalPubkey: Uint8Array;
|
|
185
|
+
}
|
|
186
|
+
/** No account at the derived Shield address yet. */
|
|
187
|
+
| {
|
|
188
|
+
readonly kind: "no-account";
|
|
189
|
+
}
|
|
190
|
+
/** The account exists but isn't set up for confidential balances. */
|
|
191
|
+
| {
|
|
192
|
+
readonly kind: "not-configured";
|
|
193
|
+
}
|
|
194
|
+
/** Configured, but not approved or refusing confidential credits. */
|
|
195
|
+
| {
|
|
196
|
+
readonly kind: "not-accepting";
|
|
197
|
+
}
|
|
198
|
+
/** The bytes at the derived address aren't this owner's account of this
|
|
199
|
+
* z-mint (or aren't a Token-2022 account at all). */
|
|
200
|
+
| {
|
|
201
|
+
readonly kind: "mismatch";
|
|
202
|
+
}
|
|
203
|
+
/** The name's owner opted out (`x1.shield = off`). */
|
|
204
|
+
| {
|
|
205
|
+
readonly kind: "opted-out";
|
|
206
|
+
};
|
|
207
|
+
/** True for the opt-out text record's value (`off`, any case/whitespace). */
|
|
208
|
+
export declare function isShieldOptOut(value: string | null | undefined): boolean;
|
|
209
|
+
/**
|
|
210
|
+
* Judge readiness to receive privately (spec §7) from the account at the
|
|
211
|
+
* derived Shield address: `account` is `{ data, owner }` as read from chain
|
|
212
|
+
* (null = no account). Pure.
|
|
213
|
+
*/
|
|
214
|
+
export declare function shieldReadiness(account: {
|
|
215
|
+
readonly data: Uint8Array;
|
|
216
|
+
readonly owner: string;
|
|
217
|
+
} | null, expected: {
|
|
218
|
+
readonly owner: string;
|
|
219
|
+
readonly zMint: string;
|
|
220
|
+
}, optedOut?: boolean): ShieldReadiness;
|
|
221
|
+
export interface ShieldRecipientConfig {
|
|
222
|
+
/** X1 RPC endpoint. */
|
|
223
|
+
readonly rpcUrl: string;
|
|
224
|
+
/** Account derivation + handle normalization (see {@link WasmResolver}). */
|
|
225
|
+
readonly wasm: WasmResolver;
|
|
226
|
+
/** `find_program_address` for the Shield-account (ATA) and config PDAs. */
|
|
227
|
+
readonly find: PdaFinder;
|
|
228
|
+
/** @handle registry program id (default: the canonical deployment). */
|
|
229
|
+
readonly handleProgramId: string;
|
|
230
|
+
/** The registry's `Config.treasury`. Omit to read it from chain. A name
|
|
231
|
+
* whose payment target is the treasury is a reserved name. */
|
|
232
|
+
readonly treasury?: string;
|
|
233
|
+
readonly fetchImpl?: typeof fetch;
|
|
234
|
+
}
|
|
235
|
+
export interface ShieldRecipient {
|
|
236
|
+
/** Canonical handle (no `@`). */
|
|
237
|
+
readonly name: string;
|
|
238
|
+
/** The registry `Handle` account (e.g. to check its lease). */
|
|
239
|
+
readonly handleAccount: string;
|
|
240
|
+
/** The wallet a private payment is for (the one payment rule, W16). */
|
|
241
|
+
readonly address: string;
|
|
242
|
+
/** Why `address`: a verified X1 record, or the current authority. Show it. */
|
|
243
|
+
readonly basis: PaymentBasis;
|
|
244
|
+
/** That wallet's Shield account for the z-mint. */
|
|
245
|
+
readonly zAccount: string;
|
|
246
|
+
/** True iff `zAccount` exists with confidential balances configured,
|
|
247
|
+
* approved and accepting confidential credits, AND the name has not opted
|
|
248
|
+
* out. Pay privately only when true. */
|
|
249
|
+
readonly ataReady: boolean;
|
|
250
|
+
readonly readiness: ShieldReadiness;
|
|
251
|
+
/** The recipient's ElGamal key (what a payment encrypts to) when ready. */
|
|
252
|
+
readonly elgamalPubkey: Uint8Array | null;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Resolve an @name for a private payment in `zMint` (spec §7):
|
|
256
|
+
*
|
|
257
|
+
* 1. the name's payment address under the one rule (`paymentAddressFor`): a
|
|
258
|
+
* live VERIFIED X1 record, else the current authority (`Handle.owner`, or
|
|
259
|
+
* the pNFT holder of a tokenized name);
|
|
260
|
+
* 2. a reserved name (its payment target is the registry treasury) is
|
|
261
|
+
* REFUSED — `ResolveError("reserved")`;
|
|
262
|
+
* 3. the recipient's Shield account (their Token-2022 ATA of `zMint`) is read
|
|
263
|
+
* from chain: `ataReady` iff it is configured for confidential balances;
|
|
264
|
+
* 4. a live `x1.shield = off` text record makes the name not ready
|
|
265
|
+
* (`readiness.kind === "opted-out"`), however its account looks.
|
|
266
|
+
*
|
|
267
|
+
* No X1ID record is needed to receive privately; readiness is chain state.
|
|
268
|
+
*/
|
|
269
|
+
export declare function resolveShieldRecipient(name: string, zMint: AddressLike, config: ShieldRecipientConfig): Promise<ShieldRecipient>;
|
|
270
|
+
/** bech32m-encode `bytes` under `hrp` (no 90-char limit: receipts are long). */
|
|
271
|
+
export declare function bech32mEncode(hrp: string, bytes: Uint8Array): string;
|
|
272
|
+
/** Strict bech32m decode: right checksum constant (not BIP-173 bech32), no
|
|
273
|
+
* mixed case, the expected `hrp`. Null on any failure. */
|
|
274
|
+
export declare function bech32mDecode(s: string, hrp: string): Uint8Array | null;
|
|
275
|
+
export declare const SHIELD_RECEIPT_HRP = "x1receipt";
|
|
276
|
+
/** A decoded `x1receipt1…`: `version 1 ‖ tx signature 64 ‖ mint 32 ‖ amount
|
|
277
|
+
* u64 LE ‖ opening lo 32 ‖ opening hi 32` (crates/shield-proofs receipt.rs). */
|
|
278
|
+
export interface ShieldReceipt {
|
|
279
|
+
/** The payment transaction id (base58). */
|
|
280
|
+
readonly txSignature: string;
|
|
281
|
+
/** The z-mint paid in (base58). */
|
|
282
|
+
readonly mint: string;
|
|
283
|
+
/** Base units. */
|
|
284
|
+
readonly amount: bigint;
|
|
285
|
+
/** Pedersen openings of the amount's lo/hi commitments. They prove only
|
|
286
|
+
* this payment's amount; they reveal nothing else about either account. */
|
|
287
|
+
readonly openingLo: Uint8Array;
|
|
288
|
+
readonly openingHi: Uint8Array;
|
|
289
|
+
}
|
|
290
|
+
export declare function encodeShieldReceipt(r: ShieldReceipt): string;
|
|
291
|
+
/** Decode a receipt string. Null when it isn't a valid v1 receipt. */
|
|
292
|
+
export declare function decodeShieldReceipt(s: string): ShieldReceipt | null;
|
|
293
|
+
/**
|
|
294
|
+
* Pull a receipt out of what someone pasted or scanned: the bare string,
|
|
295
|
+
* with whitespace or line breaks, or a `…/receipt?r=…` link. Returns the
|
|
296
|
+
* normalized lowercase receipt only when it decodes; null otherwise.
|
|
297
|
+
*/
|
|
298
|
+
export declare function extractShieldReceipt(input: string): string | null;
|
|
299
|
+
/** `ProofType` of the two proofs that carry a transfer's amount commitments. */
|
|
300
|
+
export declare const PROOF_TYPE_BATCHED_GROUPED_3_HANDLES_VALIDITY = 12;
|
|
301
|
+
export declare const PROOF_TYPE_BATCHED_RANGE_U128 = 7;
|
|
302
|
+
/** One confidential payment, as found on chain. */
|
|
303
|
+
export interface ShieldPayment {
|
|
304
|
+
readonly txSignature: string;
|
|
305
|
+
readonly slot: number;
|
|
306
|
+
readonly blockTime: number | null;
|
|
307
|
+
readonly zMint: string;
|
|
308
|
+
/** The paying wallet (the Transfer's signer). */
|
|
309
|
+
readonly sender: string;
|
|
310
|
+
readonly sourceAccount: string;
|
|
311
|
+
readonly destinationAccount: string;
|
|
312
|
+
/** The amount's Pedersen commitments (lo, hi) as the Transfer instruction
|
|
313
|
+
* itself carries them: the first 32 bytes of its auditor ciphertexts,
|
|
314
|
+
* which Token-2022 requires to equal the consumed validity proof's. */
|
|
315
|
+
readonly amountCommitmentLo: Uint8Array;
|
|
316
|
+
readonly amountCommitmentHi: Uint8Array;
|
|
317
|
+
/** `BatchedGroupedCiphertext3HandlesValidityProofData` (carries the amount
|
|
318
|
+
* ciphertexts and the source/destination ElGamal keys), only when one was
|
|
319
|
+
* found whose commitments equal the Transfer's own; null otherwise. */
|
|
320
|
+
readonly validityProof: Uint8Array | null;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Find a confidential payment and the proof data its amount lives in. The
|
|
324
|
+
* Transfer's accounts are decoded from its proof-offset bytes (an inline
|
|
325
|
+
* proof in the same transaction, or a context-state account plus the
|
|
326
|
+
* Instructions sysvar). For a context account the proof bytes come from the
|
|
327
|
+
* staging transaction that verified the 3-handle validity proof into it
|
|
328
|
+
* (crates/shield-proofs README, "S-2"), which depends on the RPC node still
|
|
329
|
+
* holding that transaction. Either way a proof is used only when its
|
|
330
|
+
* commitments equal the ones in the Transfer instruction, which Token-2022
|
|
331
|
+
* checked against the proof it consumed. Null when `txSignature` isn't a
|
|
332
|
+
* successful Token-2022 confidential transfer.
|
|
333
|
+
*/
|
|
334
|
+
export declare function findShieldPayment(rpc: RpcFn, txSignature: string): Promise<ShieldPayment | null>;
|
|
335
|
+
/**
|
|
336
|
+
* The amount ciphertexts of a payment as seen by one party (`"source"` or
|
|
337
|
+
* `"destination"`): 64-byte ElGamal ciphertexts `commitment ‖ that party's
|
|
338
|
+
* handle` for the amount's lo (16-bit) and hi (32-bit) parts. Decrypt with
|
|
339
|
+
* the party's keys as `lo + hi·2^16` (shield-proofs `decryptPending(lo, hi)`
|
|
340
|
+
* does exactly that). Also returns the party's ElGamal key from the proof so
|
|
341
|
+
* a caller can check it is theirs. Null on malformed data.
|
|
342
|
+
*/
|
|
343
|
+
export declare function paymentAmountCiphertexts(validityProof: Uint8Array, party: "source" | "destination"): {
|
|
344
|
+
readonly lo: Uint8Array;
|
|
345
|
+
readonly hi: Uint8Array;
|
|
346
|
+
readonly elgamalPubkey: Uint8Array;
|
|
347
|
+
} | null;
|
|
348
|
+
export type ShieldReceiptVerdict = {
|
|
349
|
+
readonly ok: true;
|
|
350
|
+
readonly amount: bigint;
|
|
351
|
+
readonly zMint: string;
|
|
352
|
+
readonly txSignature: string;
|
|
353
|
+
readonly blockTime: number | null;
|
|
354
|
+
readonly sender: string;
|
|
355
|
+
readonly recipientAccount: string;
|
|
356
|
+
} | {
|
|
357
|
+
readonly ok: false;
|
|
358
|
+
readonly reason: "malformed" | "not-found" | "not-a-payment" | "wrong-token" | "no-proof-history" | "mismatch";
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* Verify a receipt against the chain: decode it, find the payment
|
|
362
|
+
* ({@link findShieldPayment}), check the z-mint, and ask `checkCommitments`
|
|
363
|
+
* (the shield-proofs WASM's `verifyReceiptAgainstProof`) whether the
|
|
364
|
+
* receipt's amount and openings reproduce the commitments in the payment's
|
|
365
|
+
* own validity proof: the one whose commitments equal the Transfer
|
|
366
|
+
* instruction's (Sentinel FBL-0009). Anyone can run it; it needs no keys.
|
|
367
|
+
*/
|
|
368
|
+
export declare function verifyShieldReceipt(receipt: string, opts: {
|
|
369
|
+
readonly rpc: RpcFn;
|
|
370
|
+
readonly checkCommitments: (receipt: string, proofType: number, proofData: Uint8Array) => boolean | Promise<boolean>;
|
|
371
|
+
}): Promise<ShieldReceiptVerdict>;
|
|
372
|
+
/** Re-exported for callers that want to read account bytes the same way. */
|
|
373
|
+
export { b64ToBytes as shieldBase64ToBytes };
|