@invisi-labs/primitives 1.2.1 → 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/index.cjs +39 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +42 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- /package/dist/{chunk-3SEC7POH.js.map → chunk-C5QNE2WF.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -2,8 +2,8 @@ import { ReceivingAddress } from './address.cjs';
|
|
|
2
2
|
export { DecodedAddress, ReceivingKeyLookup, decodeAddress } from './address.cjs';
|
|
3
3
|
import { N as NoteBytes, a as NoteDecryptionContext, C as CreditStateDecryptionContext } from './encryption-P2HJ89FQ.cjs';
|
|
4
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 } from './types-CEAuh35C.cjs';
|
|
6
|
-
export { e as CreditStateRecovery, M as MAX_MEMO_BYTES, f as Memo,
|
|
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. */
|
|
@@ -488,7 +488,7 @@ declare class DeliveryDecryptionError extends Error {
|
|
|
488
488
|
constructor(cause: unknown);
|
|
489
489
|
}
|
|
490
490
|
/** Bind untrusted App plaintext to the requested wallet, deployment, token and commitment. */
|
|
491
|
-
declare function authenticatedDecryptor(
|
|
491
|
+
declare function authenticatedDecryptor(owner: `0x${string}`, decryptor: DeliveryDecryptor, expectedKeys?: ReceivingKeys): {
|
|
492
492
|
ownerAddress: `0x${string}`;
|
|
493
493
|
detectCandidates(candidates: readonly DeliveryDetectionCandidate[]): Promise<any[]>;
|
|
494
494
|
decryptNote(envelope: NoteBytes, context: Omit<NoteDecryptionContext, "ownerAddress">): Promise<{
|
|
@@ -508,4 +508,4 @@ declare class DeliveryAuthenticationError extends Error {
|
|
|
508
508
|
constructor(cause?: unknown);
|
|
509
509
|
}
|
|
510
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, 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 };
|
|
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
|
@@ -2,8 +2,8 @@ import { ReceivingAddress } from './address.js';
|
|
|
2
2
|
export { DecodedAddress, ReceivingKeyLookup, decodeAddress } from './address.js';
|
|
3
3
|
import { N as NoteBytes, a as NoteDecryptionContext, C as CreditStateDecryptionContext } from './encryption-Bzsl9VQk.js';
|
|
4
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 } from './types-CEAuh35C.js';
|
|
6
|
-
export { e as CreditStateRecovery, M as MAX_MEMO_BYTES, f as Memo,
|
|
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. */
|
|
@@ -488,7 +488,7 @@ declare class DeliveryDecryptionError extends Error {
|
|
|
488
488
|
constructor(cause: unknown);
|
|
489
489
|
}
|
|
490
490
|
/** Bind untrusted App plaintext to the requested wallet, deployment, token and commitment. */
|
|
491
|
-
declare function authenticatedDecryptor(
|
|
491
|
+
declare function authenticatedDecryptor(owner: `0x${string}`, decryptor: DeliveryDecryptor, expectedKeys?: ReceivingKeys): {
|
|
492
492
|
ownerAddress: `0x${string}`;
|
|
493
493
|
detectCandidates(candidates: readonly DeliveryDetectionCandidate[]): Promise<any[]>;
|
|
494
494
|
decryptNote(envelope: NoteBytes, context: Omit<NoteDecryptionContext, "ownerAddress">): Promise<{
|
|
@@ -508,4 +508,4 @@ declare class DeliveryAuthenticationError extends Error {
|
|
|
508
508
|
constructor(cause?: unknown);
|
|
509
509
|
}
|
|
510
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, 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 };
|
|
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
|
@@ -54,8 +54,9 @@ import {
|
|
|
54
54
|
import {
|
|
55
55
|
MissingCapabilityError,
|
|
56
56
|
ReceivingAddress,
|
|
57
|
-
decodeAddress
|
|
58
|
-
|
|
57
|
+
decodeAddress,
|
|
58
|
+
encodeLongAddress
|
|
59
|
+
} from "./chunk-C5QNE2WF.js";
|
|
59
60
|
import {
|
|
60
61
|
createClue,
|
|
61
62
|
createClueFromSeed,
|
|
@@ -774,35 +775,34 @@ var WalletAuthorization = class _WalletAuthorization {
|
|
|
774
775
|
|
|
775
776
|
// src/wallet/wallet-object.ts
|
|
776
777
|
var WalletAddress = class {
|
|
777
|
-
#
|
|
778
|
+
#ownerAddress;
|
|
779
|
+
#receivingKeys;
|
|
778
780
|
constructor(address) {
|
|
779
|
-
this.#
|
|
781
|
+
this.#receivingKeys = address.getReceivingKeys();
|
|
782
|
+
this.#ownerAddress = address.ownerAddress;
|
|
780
783
|
}
|
|
781
784
|
get ownerAddress() {
|
|
782
|
-
return this.#
|
|
785
|
+
return this.#ownerAddress;
|
|
783
786
|
}
|
|
784
787
|
get viewingPublicKey() {
|
|
785
|
-
return this.#
|
|
788
|
+
return this.#receivingKeys.viewingPublicKey.slice();
|
|
786
789
|
}
|
|
787
790
|
get clueKey() {
|
|
788
|
-
return this.#
|
|
791
|
+
return this.#receivingKeys.clueKey.slice();
|
|
789
792
|
}
|
|
790
|
-
/**
|
|
793
|
+
/** Encode the complete public receiving material on demand. */
|
|
791
794
|
getAddress() {
|
|
792
|
-
|
|
793
|
-
throw new MissingCapabilityError("resolved receiving keys");
|
|
794
|
-
}
|
|
795
|
-
return this.#address.toString();
|
|
795
|
+
return encodeLongAddress({ ownerAddress: this.#ownerAddress, ...this.#receivingKeys });
|
|
796
796
|
}
|
|
797
797
|
getReceivingAddress() {
|
|
798
|
-
return this.#
|
|
798
|
+
return ReceivingAddress.from({ ownerAddress: this.#ownerAddress, ...this.#receivingKeys });
|
|
799
799
|
}
|
|
800
800
|
/** Nullifiers derive from public identity and do not grant spending authority. */
|
|
801
801
|
exportNullifier() {
|
|
802
802
|
return NullifierCapability.fromIdentity(this.ownerAddress);
|
|
803
803
|
}
|
|
804
804
|
toJSON() {
|
|
805
|
-
return { ownerAddress: this.ownerAddress, address: this
|
|
805
|
+
return { ownerAddress: this.ownerAddress, address: this.getAddress() };
|
|
806
806
|
}
|
|
807
807
|
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
808
808
|
return this.toJSON();
|
|
@@ -813,7 +813,7 @@ var Wallet = class _Wallet extends WalletAddress {
|
|
|
813
813
|
super(address);
|
|
814
814
|
Object.freeze(this);
|
|
815
815
|
}
|
|
816
|
-
/** Parse
|
|
816
|
+
/** Parse complete 0i receiving material without network access. */
|
|
817
817
|
static fromAddress(address) {
|
|
818
818
|
if (typeof address !== "string" && !(address instanceof ReceivingAddress)) {
|
|
819
819
|
throw new TypeError("expected a validated receiving address");
|
|
@@ -912,8 +912,12 @@ function checkedPlaintext(plaintext, codec) {
|
|
|
912
912
|
throw new Error("invalid plaintext length");
|
|
913
913
|
return plaintext.slice();
|
|
914
914
|
}
|
|
915
|
-
function authenticatedDecryptor(
|
|
916
|
-
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;
|
|
917
921
|
return {
|
|
918
922
|
ownerAddress,
|
|
919
923
|
async detectCandidates(candidates) {
|
|
@@ -969,9 +973,9 @@ function authenticatedDecryptor(wallet, decryptor) {
|
|
|
969
973
|
const identity2 = context2.role === "owner" ? state.note.ownerWalletIdentity : state.note.spenderWalletIdentity;
|
|
970
974
|
if (BigInt(identity2) !== BigInt(ownerAddress) || state.note.tokenAddress !== context2.tokenAddress)
|
|
971
975
|
throw new Error("decrypted credit context mismatch");
|
|
972
|
-
if (
|
|
976
|
+
if (receivingKeys) {
|
|
973
977
|
const keys = context2.role === "owner" ? state.ownerReceivingKeys : state.spenderReceivingKeys;
|
|
974
|
-
if (bytesToHex4(keys.viewingPublicKey) !== bytesToHex4(
|
|
978
|
+
if (bytesToHex4(keys.viewingPublicKey) !== bytesToHex4(receivingKeys.viewingPublicKey))
|
|
975
979
|
throw new Error("decrypted credit receiving key mismatch");
|
|
976
980
|
}
|
|
977
981
|
await creditCommitment(full, state.note);
|
|
@@ -1088,17 +1092,24 @@ function validateWalletRequest(request) {
|
|
|
1088
1092
|
}
|
|
1089
1093
|
var retainedWallets = /* @__PURE__ */ new WeakMap();
|
|
1090
1094
|
function prepareWalletRequest(wallet, id, method, params) {
|
|
1091
|
-
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;
|
|
1092
1100
|
const request = structuredClone({
|
|
1093
1101
|
version: 1,
|
|
1094
1102
|
id,
|
|
1095
|
-
ownerAddress
|
|
1103
|
+
ownerAddress,
|
|
1096
1104
|
method,
|
|
1097
1105
|
params
|
|
1098
1106
|
});
|
|
1099
1107
|
validateWalletRequest(request);
|
|
1100
1108
|
const prepared = freeze({ request });
|
|
1101
|
-
retainedWallets.set(
|
|
1109
|
+
retainedWallets.set(
|
|
1110
|
+
prepared,
|
|
1111
|
+
wallet instanceof Wallet ? { ownerAddress, viewingPublicKey: wallet.viewingPublicKey, clueKey: wallet.clueKey } : { ownerAddress }
|
|
1112
|
+
);
|
|
1102
1113
|
return prepared;
|
|
1103
1114
|
}
|
|
1104
1115
|
async function acceptWalletResponse(prepared, response) {
|
|
@@ -1125,7 +1136,7 @@ async function acceptResponse(prepared, response) {
|
|
|
1125
1136
|
walletBytes(result.clueKey, 32);
|
|
1126
1137
|
if (await computeOwnerAddress(result.spendingPublicKey) !== request.ownerAddress)
|
|
1127
1138
|
throw new Error("wallet public identity mismatch");
|
|
1128
|
-
if (wallet.
|
|
1139
|
+
if (wallet.viewingPublicKey && wallet.clueKey && (walletHex(wallet.viewingPublicKey) !== result.viewingPublicKey || walletHex(wallet.clueKey) !== result.clueKey))
|
|
1129
1140
|
throw new Error("wallet receiving key mismatch");
|
|
1130
1141
|
ReceivingAddress.from({
|
|
1131
1142
|
ownerAddress: request.ownerAddress,
|
|
@@ -1154,10 +1165,14 @@ async function acceptResponse(prepared, response) {
|
|
|
1154
1165
|
const typed = request;
|
|
1155
1166
|
const context2 = walletDecryptionContext(typed);
|
|
1156
1167
|
const plaintext = walletBytes(result.plaintext);
|
|
1157
|
-
const viewing = authenticatedDecryptor(
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
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
|
+
);
|
|
1161
1176
|
return typed.method === "wallet.decryptNote" ? viewing.decryptNote(typed.params.envelope, context2) : viewing.decryptCredit(typed.params.envelope, context2);
|
|
1162
1177
|
}
|
|
1163
1178
|
return result;
|