@invisi-labs/primitives 1.2.0 → 1.2.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/dist/address.js +1 -1
- package/dist/{chunk-3SEC7POH.js → chunk-C5QNE2WF.js} +2 -1
- package/dist/{chunk-PRUUPDVD.js → chunk-QAC5T4S5.js} +15 -2
- package/dist/chunk-QAC5T4S5.js.map +1 -0
- package/dist/{chunk-TJYV6KTQ.js → chunk-XM4B6K37.js} +2 -2
- package/dist/credit.cjs +13 -1
- package/dist/credit.cjs.map +1 -1
- package/dist/credit.d.cts +1 -1
- package/dist/credit.d.ts +1 -1
- package/dist/credit.js +1 -1
- package/dist/{encryption-D06YBTW0.d.ts → encryption-Bzsl9VQk.d.ts} +2 -0
- package/dist/{encryption-0HQXc3tT.d.cts → encryption-P2HJ89FQ.d.cts} +2 -0
- package/dist/index.cjs +77 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -12
- package/dist/index.d.ts +31 -12
- package/dist/index.js +69 -29
- package/dist/index.js.map +1 -1
- package/dist/note.cjs +13 -1
- package/dist/note.cjs.map +1 -1
- package/dist/note.d.cts +1 -1
- package/dist/note.d.ts +1 -1
- package/dist/note.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-PRUUPDVD.js.map +0 -1
- /package/dist/{chunk-3SEC7POH.js.map → chunk-C5QNE2WF.js.map} +0 -0
- /package/dist/{chunk-TJYV6KTQ.js.map → chunk-XM4B6K37.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ReceivingAddress } from './address.cjs';
|
|
2
2
|
export { DecodedAddress, ReceivingKeyLookup, decodeAddress } from './address.cjs';
|
|
3
|
-
import { N as NoteBytes, a as NoteDecryptionContext, C as CreditStateDecryptionContext } from './encryption-
|
|
4
|
-
export { b as CreditStateEncryptionContext, c as NoteEncryptionContext, d as decryptCreditState, e as decryptPrivateTransferNote, f as encryptCreditState, g as encryptPrivateTransferNote } from './encryption-
|
|
5
|
-
import { a as CreditState, b as CreditPolicy, c as CreditUsage, N as Note, P as ProtocolContext, C as CreditDeliveryState, d as CreditDataV1, F as FundsDataV1 } from './types-CEAuh35C.cjs';
|
|
6
|
-
export { e as CreditStateRecovery, M as MAX_MEMO_BYTES, f as Memo,
|
|
3
|
+
import { N as NoteBytes, a as NoteDecryptionContext, C as CreditStateDecryptionContext } from './encryption-P2HJ89FQ.cjs';
|
|
4
|
+
export { b as CreditStateEncryptionContext, c as NoteEncryptionContext, d as decryptCreditState, e as decryptPrivateTransferNote, f as encryptCreditState, g as encryptPrivateTransferNote } from './encryption-P2HJ89FQ.cjs';
|
|
5
|
+
import { a as CreditState, b as CreditPolicy, c as CreditUsage, N as Note, P as ProtocolContext, C as CreditDeliveryState, d as CreditDataV1, F as FundsDataV1, R as ReceivingKeys } from './types-CEAuh35C.cjs';
|
|
6
|
+
export { e as CreditStateRecovery, M as MAX_MEMO_BYTES, f as Memo, g as decodeMemoText, h as encodeMemo } from './types-CEAuh35C.cjs';
|
|
7
7
|
export { computeNoteCommitment, computeNoteIdentity, computeNoteNullifier } from './note.cjs';
|
|
8
8
|
export { CREDIT_POLICY_FIELDS, CREDIT_USAGE_FIELDS, CreditUpdateChanges, applyCreditDrawUsage, computeCreditCommitment, computeCreditNullifier, computeCreditRecoveryPad, computeCreditSharedKeyHash, creditPeriods, deriveCreditState, deriveCreditStateNonce, deriveCreditUpdate, normalizeCreditDeliveryState, normalizeCreditPolicy, normalizeCreditState, normalizeCreditUsage, recoverCreditState } from './credit.cjs';
|
|
9
9
|
import { TypedDataField, TypedDataDomain, BytesLike } from 'ethers';
|
|
@@ -268,7 +268,7 @@ declare class WalletAddress {
|
|
|
268
268
|
get ownerAddress(): `0x${string}`;
|
|
269
269
|
get viewingPublicKey(): Uint8Array;
|
|
270
270
|
get clueKey(): Uint8Array;
|
|
271
|
-
/**
|
|
271
|
+
/** Encode the complete public receiving material on demand. */
|
|
272
272
|
getAddress(): string;
|
|
273
273
|
getReceivingAddress(): ReceivingAddress;
|
|
274
274
|
/** Nullifiers derive from public identity and do not grant spending authority. */
|
|
@@ -278,10 +278,10 @@ declare class WalletAddress {
|
|
|
278
278
|
address: string;
|
|
279
279
|
};
|
|
280
280
|
}
|
|
281
|
-
/**
|
|
281
|
+
/** Complete public wallet. Contains no private keys or private capability methods. */
|
|
282
282
|
declare class Wallet extends WalletAddress {
|
|
283
283
|
private constructor();
|
|
284
|
-
/** Parse
|
|
284
|
+
/** Parse complete 0i receiving material without network access. */
|
|
285
285
|
static fromAddress(address: ReceivingAddress | string): Wallet;
|
|
286
286
|
}
|
|
287
287
|
|
|
@@ -449,7 +449,7 @@ type WalletResponse<M extends WalletMethod = WalletMethod> = {
|
|
|
449
449
|
interface PreparedWalletRequest<M extends WalletMethod = WalletMethod> {
|
|
450
450
|
readonly request: WalletRequest<M>;
|
|
451
451
|
}
|
|
452
|
-
declare function prepareWalletRequest<M extends WalletMethod>(wallet: Wallet, id: string, method: M, params: WalletParams[M]): PreparedWalletRequest<M>;
|
|
452
|
+
declare function prepareWalletRequest<M extends WalletMethod>(wallet: Wallet | WalletHex, id: string, method: M, params: WalletParams[M]): PreparedWalletRequest<M>;
|
|
453
453
|
/** Validate native output against the retained request before using it in business state. */
|
|
454
454
|
declare function acceptWalletResponse<M extends WalletMethod>(prepared: PreparedWalletRequest<M>, response: WalletResponse<M>): Promise<WalletAcceptedResults[M]>;
|
|
455
455
|
/** Native errors contain machine-readable codes only. */
|
|
@@ -465,18 +465,32 @@ declare function acceptWalletResponses(prepared: readonly PreparedWalletRequest[
|
|
|
465
465
|
|
|
466
466
|
declare function provenanceIntentHash(originalRequestHash: string): string;
|
|
467
467
|
|
|
468
|
+
type DeliveryDecryptionResult = Uint8Array | null | {
|
|
469
|
+
status: "authentication-failed";
|
|
470
|
+
};
|
|
471
|
+
interface DeliveryDetectionCandidate extends NoteDecryptionContext {
|
|
472
|
+
role: "funds" | "owner" | "spender";
|
|
473
|
+
clue: `0x${string}`;
|
|
474
|
+
ciphertext: `0x${string}`;
|
|
475
|
+
}
|
|
476
|
+
interface DeliveryDetectionBatch {
|
|
477
|
+
ownerAddress: `0x${string}`;
|
|
478
|
+
results: readonly ("candidate" | "not-recipient" | "unresolved")[];
|
|
479
|
+
}
|
|
468
480
|
/** App-owned decryption. Only null means nonrecipient; operational failures must reject. */
|
|
469
481
|
interface DeliveryDecryptor {
|
|
470
|
-
|
|
471
|
-
|
|
482
|
+
detect?(candidates: readonly DeliveryDetectionCandidate[]): Promise<DeliveryDetectionBatch>;
|
|
483
|
+
decryptNote(envelope: NoteBytes, context: NoteDecryptionContext): Promise<DeliveryDecryptionResult>;
|
|
484
|
+
decryptCredit(envelope: NoteBytes, context: CreditStateDecryptionContext): Promise<DeliveryDecryptionResult>;
|
|
472
485
|
}
|
|
473
486
|
/** Keeps App failures and invalid plaintext distinct from unrelated local scan candidates. */
|
|
474
487
|
declare class DeliveryDecryptionError extends Error {
|
|
475
488
|
constructor(cause: unknown);
|
|
476
489
|
}
|
|
477
490
|
/** Bind untrusted App plaintext to the requested wallet, deployment, token and commitment. */
|
|
478
|
-
declare function authenticatedDecryptor(
|
|
491
|
+
declare function authenticatedDecryptor(owner: `0x${string}`, decryptor: DeliveryDecryptor, expectedKeys?: ReceivingKeys): {
|
|
479
492
|
ownerAddress: `0x${string}`;
|
|
493
|
+
detectCandidates(candidates: readonly DeliveryDetectionCandidate[]): Promise<any[]>;
|
|
480
494
|
decryptNote(envelope: NoteBytes, context: Omit<NoteDecryptionContext, "ownerAddress">): Promise<{
|
|
481
495
|
chainId: bigint;
|
|
482
496
|
protocolAddress: bigint;
|
|
@@ -489,4 +503,9 @@ declare function authenticatedDecryptor(wallet: Wallet, decryptor: DeliveryDecry
|
|
|
489
503
|
decryptCredit(envelope: NoteBytes, context: Omit<CreditStateDecryptionContext, "ownerAddress">): Promise<CreditDeliveryState | null>;
|
|
490
504
|
};
|
|
491
505
|
|
|
492
|
-
|
|
506
|
+
/** AEAD failure is ambiguous: wrong recipient key, wrong context or damaged ciphertext. */
|
|
507
|
+
declare class DeliveryAuthenticationError extends Error {
|
|
508
|
+
constructor(cause?: unknown);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export { type Address, AuthorizedStatement, CreditDataV1, CreditDeliveryState, type CreditOpening, CreditPolicy, CreditState, CreditStateDecryptionContext, CreditUsage, D_CNULL, D_CREDIT, D_CREDIT_KEY_HASH, D_CREDIT_RECOVERY, D_CREDIT_STATE_NONCE, D_IDENT, D_NOTE, D_NULL, DeliveryAuthenticationError, DeliveryDecryptionError, type DeliveryDecryptionResult, type DeliveryDecryptor, type DeliveryDetectionBatch, type DeliveryDetectionCandidate, type DeliveryKind, Detector, Disclosure, type DisclosureExport, type DisclosureOutput, type DisclosureResult, FIELD_MODULUS, FundsDataV1, type Hex, MAX_CIPHERTEXT_BYTES, MAX_WALLET_BATCH_BYTES, MissingCapabilityError, NativeWalletError, Note, NoteBytes, NoteDecryptionContext, NullifierCapability, type PreparedWalletRequest, ProtocolContext, ReceivingAddress, ReceivingKeys, type SigningRequest, TREE_DEPTH, ViewingCapability, WALLET_AUTHORIZATION_TYPES, Wallet, type WalletAcceptedResults, type WalletAuthorizationRequest, type WalletAuthorizationWitness, type WalletBytes, type WalletDecryptContext, type WalletHex, type WalletMethod, type WalletOperation, type WalletParams, type WalletRequest, type WalletResponse, type WalletResults, type WalletWireContext, acceptWalletResponse, acceptWalletResponses, authenticatedDecryptor, computeOwnerAddress, computeWalletAuthorizationDigest, createClue, createClueFromSeed, createSigningRequest, creditV1, decodeDeliveryHeader, deliveryCodec, deliveryHeader, deriveClueKey, fundsV1, generateCreditSharedKey, generateNonce, poseidonHash, prepareWalletRequest, provenanceIntentHash, validateClueKey, validateDeliveryCiphertext, validateWalletBatch, validateWalletResponses, verifyWalletAuthorization, viewingPublicKey, walletAuthorizationTypedData };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ReceivingAddress } from './address.js';
|
|
2
2
|
export { DecodedAddress, ReceivingKeyLookup, decodeAddress } from './address.js';
|
|
3
|
-
import { N as NoteBytes, a as NoteDecryptionContext, C as CreditStateDecryptionContext } from './encryption-
|
|
4
|
-
export { b as CreditStateEncryptionContext, c as NoteEncryptionContext, d as decryptCreditState, e as decryptPrivateTransferNote, f as encryptCreditState, g as encryptPrivateTransferNote } from './encryption-
|
|
5
|
-
import { a as CreditState, b as CreditPolicy, c as CreditUsage, N as Note, P as ProtocolContext, C as CreditDeliveryState, d as CreditDataV1, F as FundsDataV1 } from './types-CEAuh35C.js';
|
|
6
|
-
export { e as CreditStateRecovery, M as MAX_MEMO_BYTES, f as Memo,
|
|
3
|
+
import { N as NoteBytes, a as NoteDecryptionContext, C as CreditStateDecryptionContext } from './encryption-Bzsl9VQk.js';
|
|
4
|
+
export { b as CreditStateEncryptionContext, c as NoteEncryptionContext, d as decryptCreditState, e as decryptPrivateTransferNote, f as encryptCreditState, g as encryptPrivateTransferNote } from './encryption-Bzsl9VQk.js';
|
|
5
|
+
import { a as CreditState, b as CreditPolicy, c as CreditUsage, N as Note, P as ProtocolContext, C as CreditDeliveryState, d as CreditDataV1, F as FundsDataV1, R as ReceivingKeys } from './types-CEAuh35C.js';
|
|
6
|
+
export { e as CreditStateRecovery, M as MAX_MEMO_BYTES, f as Memo, g as decodeMemoText, h as encodeMemo } from './types-CEAuh35C.js';
|
|
7
7
|
export { computeNoteCommitment, computeNoteIdentity, computeNoteNullifier } from './note.js';
|
|
8
8
|
export { CREDIT_POLICY_FIELDS, CREDIT_USAGE_FIELDS, CreditUpdateChanges, applyCreditDrawUsage, computeCreditCommitment, computeCreditNullifier, computeCreditRecoveryPad, computeCreditSharedKeyHash, creditPeriods, deriveCreditState, deriveCreditStateNonce, deriveCreditUpdate, normalizeCreditDeliveryState, normalizeCreditPolicy, normalizeCreditState, normalizeCreditUsage, recoverCreditState } from './credit.js';
|
|
9
9
|
import { TypedDataField, TypedDataDomain, BytesLike } from 'ethers';
|
|
@@ -268,7 +268,7 @@ declare class WalletAddress {
|
|
|
268
268
|
get ownerAddress(): `0x${string}`;
|
|
269
269
|
get viewingPublicKey(): Uint8Array;
|
|
270
270
|
get clueKey(): Uint8Array;
|
|
271
|
-
/**
|
|
271
|
+
/** Encode the complete public receiving material on demand. */
|
|
272
272
|
getAddress(): string;
|
|
273
273
|
getReceivingAddress(): ReceivingAddress;
|
|
274
274
|
/** Nullifiers derive from public identity and do not grant spending authority. */
|
|
@@ -278,10 +278,10 @@ declare class WalletAddress {
|
|
|
278
278
|
address: string;
|
|
279
279
|
};
|
|
280
280
|
}
|
|
281
|
-
/**
|
|
281
|
+
/** Complete public wallet. Contains no private keys or private capability methods. */
|
|
282
282
|
declare class Wallet extends WalletAddress {
|
|
283
283
|
private constructor();
|
|
284
|
-
/** Parse
|
|
284
|
+
/** Parse complete 0i receiving material without network access. */
|
|
285
285
|
static fromAddress(address: ReceivingAddress | string): Wallet;
|
|
286
286
|
}
|
|
287
287
|
|
|
@@ -449,7 +449,7 @@ type WalletResponse<M extends WalletMethod = WalletMethod> = {
|
|
|
449
449
|
interface PreparedWalletRequest<M extends WalletMethod = WalletMethod> {
|
|
450
450
|
readonly request: WalletRequest<M>;
|
|
451
451
|
}
|
|
452
|
-
declare function prepareWalletRequest<M extends WalletMethod>(wallet: Wallet, id: string, method: M, params: WalletParams[M]): PreparedWalletRequest<M>;
|
|
452
|
+
declare function prepareWalletRequest<M extends WalletMethod>(wallet: Wallet | WalletHex, id: string, method: M, params: WalletParams[M]): PreparedWalletRequest<M>;
|
|
453
453
|
/** Validate native output against the retained request before using it in business state. */
|
|
454
454
|
declare function acceptWalletResponse<M extends WalletMethod>(prepared: PreparedWalletRequest<M>, response: WalletResponse<M>): Promise<WalletAcceptedResults[M]>;
|
|
455
455
|
/** Native errors contain machine-readable codes only. */
|
|
@@ -465,18 +465,32 @@ declare function acceptWalletResponses(prepared: readonly PreparedWalletRequest[
|
|
|
465
465
|
|
|
466
466
|
declare function provenanceIntentHash(originalRequestHash: string): string;
|
|
467
467
|
|
|
468
|
+
type DeliveryDecryptionResult = Uint8Array | null | {
|
|
469
|
+
status: "authentication-failed";
|
|
470
|
+
};
|
|
471
|
+
interface DeliveryDetectionCandidate extends NoteDecryptionContext {
|
|
472
|
+
role: "funds" | "owner" | "spender";
|
|
473
|
+
clue: `0x${string}`;
|
|
474
|
+
ciphertext: `0x${string}`;
|
|
475
|
+
}
|
|
476
|
+
interface DeliveryDetectionBatch {
|
|
477
|
+
ownerAddress: `0x${string}`;
|
|
478
|
+
results: readonly ("candidate" | "not-recipient" | "unresolved")[];
|
|
479
|
+
}
|
|
468
480
|
/** App-owned decryption. Only null means nonrecipient; operational failures must reject. */
|
|
469
481
|
interface DeliveryDecryptor {
|
|
470
|
-
|
|
471
|
-
|
|
482
|
+
detect?(candidates: readonly DeliveryDetectionCandidate[]): Promise<DeliveryDetectionBatch>;
|
|
483
|
+
decryptNote(envelope: NoteBytes, context: NoteDecryptionContext): Promise<DeliveryDecryptionResult>;
|
|
484
|
+
decryptCredit(envelope: NoteBytes, context: CreditStateDecryptionContext): Promise<DeliveryDecryptionResult>;
|
|
472
485
|
}
|
|
473
486
|
/** Keeps App failures and invalid plaintext distinct from unrelated local scan candidates. */
|
|
474
487
|
declare class DeliveryDecryptionError extends Error {
|
|
475
488
|
constructor(cause: unknown);
|
|
476
489
|
}
|
|
477
490
|
/** Bind untrusted App plaintext to the requested wallet, deployment, token and commitment. */
|
|
478
|
-
declare function authenticatedDecryptor(
|
|
491
|
+
declare function authenticatedDecryptor(owner: `0x${string}`, decryptor: DeliveryDecryptor, expectedKeys?: ReceivingKeys): {
|
|
479
492
|
ownerAddress: `0x${string}`;
|
|
493
|
+
detectCandidates(candidates: readonly DeliveryDetectionCandidate[]): Promise<any[]>;
|
|
480
494
|
decryptNote(envelope: NoteBytes, context: Omit<NoteDecryptionContext, "ownerAddress">): Promise<{
|
|
481
495
|
chainId: bigint;
|
|
482
496
|
protocolAddress: bigint;
|
|
@@ -489,4 +503,9 @@ declare function authenticatedDecryptor(wallet: Wallet, decryptor: DeliveryDecry
|
|
|
489
503
|
decryptCredit(envelope: NoteBytes, context: Omit<CreditStateDecryptionContext, "ownerAddress">): Promise<CreditDeliveryState | null>;
|
|
490
504
|
};
|
|
491
505
|
|
|
492
|
-
|
|
506
|
+
/** AEAD failure is ambiguous: wrong recipient key, wrong context or damaged ciphertext. */
|
|
507
|
+
declare class DeliveryAuthenticationError extends Error {
|
|
508
|
+
constructor(cause?: unknown);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export { type Address, AuthorizedStatement, CreditDataV1, CreditDeliveryState, type CreditOpening, CreditPolicy, CreditState, CreditStateDecryptionContext, CreditUsage, D_CNULL, D_CREDIT, D_CREDIT_KEY_HASH, D_CREDIT_RECOVERY, D_CREDIT_STATE_NONCE, D_IDENT, D_NOTE, D_NULL, DeliveryAuthenticationError, DeliveryDecryptionError, type DeliveryDecryptionResult, type DeliveryDecryptor, type DeliveryDetectionBatch, type DeliveryDetectionCandidate, type DeliveryKind, Detector, Disclosure, type DisclosureExport, type DisclosureOutput, type DisclosureResult, FIELD_MODULUS, FundsDataV1, type Hex, MAX_CIPHERTEXT_BYTES, MAX_WALLET_BATCH_BYTES, MissingCapabilityError, NativeWalletError, Note, NoteBytes, NoteDecryptionContext, NullifierCapability, type PreparedWalletRequest, ProtocolContext, ReceivingAddress, ReceivingKeys, type SigningRequest, TREE_DEPTH, ViewingCapability, WALLET_AUTHORIZATION_TYPES, Wallet, type WalletAcceptedResults, type WalletAuthorizationRequest, type WalletAuthorizationWitness, type WalletBytes, type WalletDecryptContext, type WalletHex, type WalletMethod, type WalletOperation, type WalletParams, type WalletRequest, type WalletResponse, type WalletResults, type WalletWireContext, acceptWalletResponse, acceptWalletResponses, authenticatedDecryptor, computeOwnerAddress, computeWalletAuthorizationDigest, createClue, createClueFromSeed, createSigningRequest, creditV1, decodeDeliveryHeader, deliveryCodec, deliveryHeader, deriveClueKey, fundsV1, generateCreditSharedKey, generateNonce, poseidonHash, prepareWalletRequest, provenanceIntentHash, validateClueKey, validateDeliveryCiphertext, validateWalletBatch, validateWalletResponses, verifyWalletAuthorization, viewingPublicKey, walletAuthorizationTypedData };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
computeNoteNullifier
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XM4B6K37.js";
|
|
4
4
|
import {
|
|
5
5
|
CREDIT_POLICY_FIELDS,
|
|
6
6
|
CREDIT_USAGE_FIELDS,
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
D_IDENT,
|
|
13
13
|
D_NOTE,
|
|
14
14
|
D_NULL,
|
|
15
|
+
DeliveryAuthenticationError,
|
|
15
16
|
FIELD_MODULUS,
|
|
16
17
|
MAX_CIPHERTEXT_BYTES,
|
|
17
18
|
TREE_DEPTH,
|
|
@@ -49,12 +50,13 @@ import {
|
|
|
49
50
|
validateContext,
|
|
50
51
|
validateDeliveryCiphertext,
|
|
51
52
|
viewingPublicKey
|
|
52
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-QAC5T4S5.js";
|
|
53
54
|
import {
|
|
54
55
|
MissingCapabilityError,
|
|
55
56
|
ReceivingAddress,
|
|
56
|
-
decodeAddress
|
|
57
|
-
|
|
57
|
+
decodeAddress,
|
|
58
|
+
encodeLongAddress
|
|
59
|
+
} from "./chunk-C5QNE2WF.js";
|
|
58
60
|
import {
|
|
59
61
|
createClue,
|
|
60
62
|
createClueFromSeed,
|
|
@@ -773,35 +775,34 @@ var WalletAuthorization = class _WalletAuthorization {
|
|
|
773
775
|
|
|
774
776
|
// src/wallet/wallet-object.ts
|
|
775
777
|
var WalletAddress = class {
|
|
776
|
-
#
|
|
778
|
+
#ownerAddress;
|
|
779
|
+
#receivingKeys;
|
|
777
780
|
constructor(address) {
|
|
778
|
-
this.#
|
|
781
|
+
this.#receivingKeys = address.getReceivingKeys();
|
|
782
|
+
this.#ownerAddress = address.ownerAddress;
|
|
779
783
|
}
|
|
780
784
|
get ownerAddress() {
|
|
781
|
-
return this.#
|
|
785
|
+
return this.#ownerAddress;
|
|
782
786
|
}
|
|
783
787
|
get viewingPublicKey() {
|
|
784
|
-
return this.#
|
|
788
|
+
return this.#receivingKeys.viewingPublicKey.slice();
|
|
785
789
|
}
|
|
786
790
|
get clueKey() {
|
|
787
|
-
return this.#
|
|
791
|
+
return this.#receivingKeys.clueKey.slice();
|
|
788
792
|
}
|
|
789
|
-
/**
|
|
793
|
+
/** Encode the complete public receiving material on demand. */
|
|
790
794
|
getAddress() {
|
|
791
|
-
|
|
792
|
-
throw new MissingCapabilityError("resolved receiving keys");
|
|
793
|
-
}
|
|
794
|
-
return this.#address.toString();
|
|
795
|
+
return encodeLongAddress({ ownerAddress: this.#ownerAddress, ...this.#receivingKeys });
|
|
795
796
|
}
|
|
796
797
|
getReceivingAddress() {
|
|
797
|
-
return this.#
|
|
798
|
+
return ReceivingAddress.from({ ownerAddress: this.#ownerAddress, ...this.#receivingKeys });
|
|
798
799
|
}
|
|
799
800
|
/** Nullifiers derive from public identity and do not grant spending authority. */
|
|
800
801
|
exportNullifier() {
|
|
801
802
|
return NullifierCapability.fromIdentity(this.ownerAddress);
|
|
802
803
|
}
|
|
803
804
|
toJSON() {
|
|
804
|
-
return { ownerAddress: this.ownerAddress, address: this
|
|
805
|
+
return { ownerAddress: this.ownerAddress, address: this.getAddress() };
|
|
805
806
|
}
|
|
806
807
|
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
807
808
|
return this.toJSON();
|
|
@@ -812,7 +813,7 @@ var Wallet = class _Wallet extends WalletAddress {
|
|
|
812
813
|
super(address);
|
|
813
814
|
Object.freeze(this);
|
|
814
815
|
}
|
|
815
|
-
/** Parse
|
|
816
|
+
/** Parse complete 0i receiving material without network access. */
|
|
816
817
|
static fromAddress(address) {
|
|
817
818
|
if (typeof address !== "string" && !(address instanceof ReceivingAddress)) {
|
|
818
819
|
throw new TypeError("expected a validated receiving address");
|
|
@@ -911,10 +912,25 @@ function checkedPlaintext(plaintext, codec) {
|
|
|
911
912
|
throw new Error("invalid plaintext length");
|
|
912
913
|
return plaintext.slice();
|
|
913
914
|
}
|
|
914
|
-
function authenticatedDecryptor(
|
|
915
|
-
const ownerAddress =
|
|
915
|
+
function authenticatedDecryptor(owner2, decryptor, expectedKeys) {
|
|
916
|
+
const ownerAddress = ReceivingAddress.fromIdentity(owner2).ownerAddress;
|
|
917
|
+
const receivingKeys = expectedKeys ? {
|
|
918
|
+
viewingPublicKey: expectedKeys.viewingPublicKey.slice(),
|
|
919
|
+
clueKey: expectedKeys.clueKey.slice()
|
|
920
|
+
} : void 0;
|
|
916
921
|
return {
|
|
917
922
|
ownerAddress,
|
|
923
|
+
async detectCandidates(candidates) {
|
|
924
|
+
if (!decryptor.detect) return candidates.map(() => "candidate");
|
|
925
|
+
const result = await decryptor.detect(structuredClone(candidates));
|
|
926
|
+
if (!result || BigInt(result.ownerAddress) !== BigInt(ownerAddress) || !Array.isArray(result.results) || result.results.length !== candidates.length || result.results.some(
|
|
927
|
+
(value) => !["candidate", "not-recipient", "unresolved"].includes(value)
|
|
928
|
+
))
|
|
929
|
+
throw new DeliveryDecryptionError(
|
|
930
|
+
new Error("invalid detection batch or wrong account")
|
|
931
|
+
);
|
|
932
|
+
return [...result.results];
|
|
933
|
+
},
|
|
918
934
|
async decryptNote(envelope, context2) {
|
|
919
935
|
context2 = { ...context2 };
|
|
920
936
|
try {
|
|
@@ -922,6 +938,11 @@ function authenticatedDecryptor(wallet, decryptor) {
|
|
|
922
938
|
const full = { ...context2, ownerAddress };
|
|
923
939
|
const plaintext = await decryptor.decryptNote(bytes2.slice(), { ...full });
|
|
924
940
|
if (plaintext === null) return null;
|
|
941
|
+
if (!(plaintext instanceof Uint8Array)) {
|
|
942
|
+
if (plaintext?.status === "authentication-failed")
|
|
943
|
+
throw new DeliveryAuthenticationError();
|
|
944
|
+
throw new Error("invalid decryption result");
|
|
945
|
+
}
|
|
925
946
|
const codec = deliveryCodec(bytes2[0]);
|
|
926
947
|
if (codec.kind !== "funds") throw new Error("unexpected envelope kind");
|
|
927
948
|
const note = codec.decode(checkedPlaintext(plaintext, codec), full);
|
|
@@ -930,6 +951,7 @@ function authenticatedDecryptor(wallet, decryptor) {
|
|
|
930
951
|
await noteCommitment(full, note);
|
|
931
952
|
return note;
|
|
932
953
|
} catch (cause) {
|
|
954
|
+
if (cause instanceof DeliveryAuthenticationError) throw cause;
|
|
933
955
|
throw new DeliveryDecryptionError(cause);
|
|
934
956
|
}
|
|
935
957
|
},
|
|
@@ -940,20 +962,26 @@ function authenticatedDecryptor(wallet, decryptor) {
|
|
|
940
962
|
const full = { ...context2, ownerAddress };
|
|
941
963
|
const plaintext = await decryptor.decryptCredit(bytes2.slice(), { ...full });
|
|
942
964
|
if (plaintext === null) return null;
|
|
965
|
+
if (!(plaintext instanceof Uint8Array)) {
|
|
966
|
+
if (plaintext?.status === "authentication-failed")
|
|
967
|
+
throw new DeliveryAuthenticationError();
|
|
968
|
+
throw new Error("invalid decryption result");
|
|
969
|
+
}
|
|
943
970
|
const codec = deliveryCodec(bytes2[0]);
|
|
944
971
|
if (codec.kind !== "credit") throw new Error("unexpected envelope kind");
|
|
945
972
|
const state = codec.decode(checkedPlaintext(plaintext, codec), full);
|
|
946
973
|
const identity2 = context2.role === "owner" ? state.note.ownerWalletIdentity : state.note.spenderWalletIdentity;
|
|
947
974
|
if (BigInt(identity2) !== BigInt(ownerAddress) || state.note.tokenAddress !== context2.tokenAddress)
|
|
948
975
|
throw new Error("decrypted credit context mismatch");
|
|
949
|
-
if (
|
|
976
|
+
if (receivingKeys) {
|
|
950
977
|
const keys = context2.role === "owner" ? state.ownerReceivingKeys : state.spenderReceivingKeys;
|
|
951
|
-
if (bytesToHex4(keys.viewingPublicKey) !== bytesToHex4(
|
|
978
|
+
if (bytesToHex4(keys.viewingPublicKey) !== bytesToHex4(receivingKeys.viewingPublicKey))
|
|
952
979
|
throw new Error("decrypted credit receiving key mismatch");
|
|
953
980
|
}
|
|
954
981
|
await creditCommitment(full, state.note);
|
|
955
982
|
return state;
|
|
956
983
|
} catch (cause) {
|
|
984
|
+
if (cause instanceof DeliveryAuthenticationError) throw cause;
|
|
957
985
|
throw new DeliveryDecryptionError(cause);
|
|
958
986
|
}
|
|
959
987
|
}
|
|
@@ -1064,17 +1092,24 @@ function validateWalletRequest(request) {
|
|
|
1064
1092
|
}
|
|
1065
1093
|
var retainedWallets = /* @__PURE__ */ new WeakMap();
|
|
1066
1094
|
function prepareWalletRequest(wallet, id, method, params) {
|
|
1067
|
-
if (!(wallet instanceof Wallet)
|
|
1095
|
+
if (!(wallet instanceof Wallet) && typeof wallet !== "string")
|
|
1096
|
+
throw new TypeError("ownerAddress or public Wallet required");
|
|
1097
|
+
const ownerAddress = ReceivingAddress.fromIdentity(
|
|
1098
|
+
typeof wallet === "string" ? wallet : wallet.ownerAddress
|
|
1099
|
+
).ownerAddress;
|
|
1068
1100
|
const request = structuredClone({
|
|
1069
1101
|
version: 1,
|
|
1070
1102
|
id,
|
|
1071
|
-
ownerAddress
|
|
1103
|
+
ownerAddress,
|
|
1072
1104
|
method,
|
|
1073
1105
|
params
|
|
1074
1106
|
});
|
|
1075
1107
|
validateWalletRequest(request);
|
|
1076
1108
|
const prepared = freeze({ request });
|
|
1077
|
-
retainedWallets.set(
|
|
1109
|
+
retainedWallets.set(
|
|
1110
|
+
prepared,
|
|
1111
|
+
wallet instanceof Wallet ? { ownerAddress, viewingPublicKey: wallet.viewingPublicKey, clueKey: wallet.clueKey } : { ownerAddress }
|
|
1112
|
+
);
|
|
1078
1113
|
return prepared;
|
|
1079
1114
|
}
|
|
1080
1115
|
async function acceptWalletResponse(prepared, response) {
|
|
@@ -1101,7 +1136,7 @@ async function acceptResponse(prepared, response) {
|
|
|
1101
1136
|
walletBytes(result.clueKey, 32);
|
|
1102
1137
|
if (await computeOwnerAddress(result.spendingPublicKey) !== request.ownerAddress)
|
|
1103
1138
|
throw new Error("wallet public identity mismatch");
|
|
1104
|
-
if (wallet.
|
|
1139
|
+
if (wallet.viewingPublicKey && wallet.clueKey && (walletHex(wallet.viewingPublicKey) !== result.viewingPublicKey || walletHex(wallet.clueKey) !== result.clueKey))
|
|
1105
1140
|
throw new Error("wallet receiving key mismatch");
|
|
1106
1141
|
ReceivingAddress.from({
|
|
1107
1142
|
ownerAddress: request.ownerAddress,
|
|
@@ -1130,10 +1165,14 @@ async function acceptResponse(prepared, response) {
|
|
|
1130
1165
|
const typed = request;
|
|
1131
1166
|
const context2 = walletDecryptionContext(typed);
|
|
1132
1167
|
const plaintext = walletBytes(result.plaintext);
|
|
1133
|
-
const viewing = authenticatedDecryptor(
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1168
|
+
const viewing = authenticatedDecryptor(
|
|
1169
|
+
request.ownerAddress,
|
|
1170
|
+
{
|
|
1171
|
+
decryptNote: async () => plaintext,
|
|
1172
|
+
decryptCredit: async () => plaintext
|
|
1173
|
+
},
|
|
1174
|
+
wallet.viewingPublicKey && wallet.clueKey ? { viewingPublicKey: wallet.viewingPublicKey, clueKey: wallet.clueKey } : void 0
|
|
1175
|
+
);
|
|
1137
1176
|
return typed.method === "wallet.decryptNote" ? viewing.decryptNote(typed.params.envelope, context2) : viewing.decryptCredit(typed.params.envelope, context2);
|
|
1138
1177
|
}
|
|
1139
1178
|
return result;
|
|
@@ -1242,6 +1281,7 @@ export {
|
|
|
1242
1281
|
D_IDENT,
|
|
1243
1282
|
D_NOTE,
|
|
1244
1283
|
D_NULL,
|
|
1284
|
+
DeliveryAuthenticationError,
|
|
1245
1285
|
DeliveryDecryptionError,
|
|
1246
1286
|
Detector,
|
|
1247
1287
|
Disclosure,
|