@orbinum/sdk 0.20.1 → 0.21.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/dist/index.d.mts +48 -10
- package/dist/index.d.ts +48 -10
- package/dist/index.js +22 -2
- package/dist/index.mjs +21 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -721,6 +721,13 @@ type ZkNote = {
|
|
|
721
721
|
spendingKey: bigint;
|
|
722
722
|
/** Circuit version this note was created under (see `CURRENT_CIRCUIT_VERSION`). Required. */
|
|
723
723
|
circuitVersion: number;
|
|
724
|
+
/**
|
|
725
|
+
* Global Merkle leaf index, when known. Optional so pre-forest vaults
|
|
726
|
+
* need no migration: notes without it predate the first tree seal and
|
|
727
|
+
* belong to tree 0. Populated on shield and on scan; used only to derive
|
|
728
|
+
* the forest tree for same-tree coin selection (`treeIdOf`).
|
|
729
|
+
*/
|
|
730
|
+
leafIndex?: number;
|
|
724
731
|
/** Whether the note has been spent/nullified on-chain. */
|
|
725
732
|
spent: boolean;
|
|
726
733
|
/** Local timestamp when this note was marked spent, or null if still active/unknown. */
|
|
@@ -1095,6 +1102,7 @@ type RpcV2MerkleProof = {
|
|
|
1095
1102
|
path: string[];
|
|
1096
1103
|
leafIndex: number;
|
|
1097
1104
|
treeDepth: number;
|
|
1105
|
+
treeId?: number | undefined;
|
|
1098
1106
|
};
|
|
1099
1107
|
type PrivacyMerkleProof = RpcV2MerkleProof & {
|
|
1100
1108
|
root: string;
|
|
@@ -2301,22 +2309,52 @@ declare function generateTransferProof(params: PrivateTransferProofInputs, optio
|
|
|
2301
2309
|
verbose?: boolean;
|
|
2302
2310
|
}): Promise<ProofResult>;
|
|
2303
2311
|
|
|
2312
|
+
/**
|
|
2313
|
+
* Forest tree a note belongs to.
|
|
2314
|
+
*
|
|
2315
|
+
* Falls back to tree 0 for a missing or malformed `leafIndex`. Both cases are
|
|
2316
|
+
* expected rather than defensive noise:
|
|
2317
|
+
*
|
|
2318
|
+
* - Notes persisted before the forest upgrade carry no index, and they all
|
|
2319
|
+
* predate the first seal, so tree 0 is the correct answer.
|
|
2320
|
+
* - The index originates in an indexer scan hint, which is untrusted. A
|
|
2321
|
+
* `NaN` reaching this function would make every same-tree comparison
|
|
2322
|
+
* false — no pair would ever be selectable and the whole balance would
|
|
2323
|
+
* look unspendable.
|
|
2324
|
+
*/
|
|
2325
|
+
declare function treeIdOf(note: Pick<ZkNote, 'leafIndex'>): number;
|
|
2326
|
+
/**
|
|
2327
|
+
* Outcome of {@link selectNotes}.
|
|
2328
|
+
*
|
|
2329
|
+
* - `[noteA, noteB | null]` — a spendable selection; a `null` second slot
|
|
2330
|
+
* means the transfer runs with a dummy input.
|
|
2331
|
+
* - `{ needsConsolidation: true }` — the balance covers the amount, but only
|
|
2332
|
+
* by pairing notes from different forest trees, which no single proof can
|
|
2333
|
+
* do. The caller should offer a consolidation, not an insufficient-funds
|
|
2334
|
+
* error.
|
|
2335
|
+
* - `null` — no combination covers the amount.
|
|
2336
|
+
*/
|
|
2337
|
+
type CoinSelection = [ZkNote, ZkNote | null] | {
|
|
2338
|
+
needsConsolidation: true;
|
|
2339
|
+
} | null;
|
|
2304
2340
|
/**
|
|
2305
2341
|
* Selects up to 2 unspent notes that together cover `needed` planck.
|
|
2306
2342
|
*
|
|
2307
|
-
*
|
|
2308
|
-
*
|
|
2309
|
-
*
|
|
2310
|
-
*
|
|
2343
|
+
* Both inputs of a transfer are proven together against ONE circuit VK and ONE
|
|
2344
|
+
* public `merkle_root`, so a pair must agree on two things: mixing circuit
|
|
2345
|
+
* versions produces an invalid proof, and notes in different forest trees
|
|
2346
|
+
* anchor to different roots that can never converge. A single note needs
|
|
2347
|
+
* neither check.
|
|
2311
2348
|
*
|
|
2312
|
-
*
|
|
2313
|
-
*
|
|
2314
|
-
*
|
|
2315
|
-
*
|
|
2349
|
+
* Resolution order:
|
|
2350
|
+
* 1. One note that alone covers `needed` → `[note, null]`.
|
|
2351
|
+
* 2. Smallest same-version, same-tree pair whose sum covers it → `[a, b]`.
|
|
2352
|
+
* 3. A cross-tree pair would cover it → `{ needsConsolidation: true }`.
|
|
2353
|
+
* 4. Nothing covers it → `null`.
|
|
2316
2354
|
*
|
|
2317
2355
|
* Only unspent notes with value > 0 are considered.
|
|
2318
2356
|
*/
|
|
2319
|
-
declare function selectNotes(notes: ZkNote[], needed: bigint):
|
|
2357
|
+
declare function selectNotes(notes: ZkNote[], needed: bigint): CoinSelection;
|
|
2320
2358
|
/**
|
|
2321
2359
|
* Builds a dummy `TransferInputNote` for use as the second input in a single-note transfer.
|
|
2322
2360
|
*
|
|
@@ -4453,4 +4491,4 @@ interface ExtrinsicFailedData {
|
|
|
4453
4491
|
dispatch_info: DispatchInfo;
|
|
4454
4492
|
}
|
|
4455
4493
|
|
|
4456
|
-
export { type AccountListing, type AccountMappedData, type AccountMappedEvent, type AccountMappingCall, type AccountMappingEvent, AccountMappingModule, AccountMappingPrecompile, type AccountMetadata, type AccountUnmappedEvent, type ActiveVersionSetEvent, type AddChainLinkArgs, type AddChainLinkParams, type AddSupportedChainArgs, type AliasFullIdentity, type AliasInfo, type AliasListedForSaleEvent, type AliasOnSaleData, type AliasRegisteredData, type AliasRegisteredEvent, type AliasReleasedEvent, type AliasSaleCancelledEvent, type AliasSoldData, type AliasSoldEvent, type AliasTransferredData, type AliasTransferredEvent, type AssetRegisteredEvent, type AssetUnverifiedEvent, type AssetVerifiedEvent, BABYJUB_SUBORDER, BN254_R, type BatchRegisterVerificationKeysArgs, type BatchVerificationKeysRegisteredEvent, type BlockInfo, type BuyAliasArgs, type Bytes32, CURRENT_CIRCUIT_VERSION, type ChainInfo, type ChainLink, type ChainLinkAddedEvent, type ChainLinkRemovedEvent, CircuitId, CircuitId as CircuitIdType, CircuitVersionResolver, type ClaimShieldedFeesParams, type ClientProviderConfig, type CommitmentsInsertedEvent, type CommitmentsInsertedEventData, type ConnectionStatus, CryptoPrecompiles, type DecodedAddChainLinkArgs, type DecodedBatchArgs, type DecodedDispatchAsPrivateLinkArgs, type DecodedEthereumTransactArgs, type DecodedEvmCallArgs, type DecodedPrecompile, type DecodedPrivateTransferArgs, type DecodedPutAliasForSaleArgs, type DecodedRegisterAliasArgs, type DecodedRemarkArgs, type DecodedRevealPrivateLinkArgs, type DecodedSetAccountMetadataArgs, type DecodedShieldArgs, type DecodedShieldBatchArgs, type DecodedShieldBatchOperation, type DecodedSudoArgs, type DecodedTransferAllArgs, type DecodedTransferArgs, type DecodedTransferKeepAliveArgs, type DecodedUnshieldArgs, type DecryptedMemo, type DispatchAsLinkedAccountArgs, type DispatchAsLinkedParams, type DispatchAsPrivateLinkArgs, type DispatchError, type DispatchInfo, type DynamicBuilder, ENCRYPTED_MEMO_SIZE, EncryptedMemo, type EncryptedNoteRecord, type EndowedEventData, type EthereumExecutedData, type EventData, type EventPhase, type EventRecord, type EvmAddressInfo, type EvmBlock, EvmClient, type EvmExecutedData, type EvmExitReason, EvmExplorer, type EvmLog, type EvmSigner, type EvmTransaction, type EvmTxRequest, type EvmTxSummary, type ExtrinsicDecoder, type ExtrinsicFailedData, type ExtrinsicSuccessData, type FeeClaimProofInputs, type FormatOptions, KNOWN_PRECOMPILES, type KnownPrecompileInfo, type ListingInfo, MIN_SIGNATURE_BYTES, type MerkleRootUpdatedData, type MerkleRootUpdatedEvent, type MerkleTreeInfo, type MetadataUpdatedEvent, NoteBuilder, type NoteDisclosure, type NoteInput, type NoteStatusUpdate, type NullifiersSpentEvent, type NullifiersSpentEventData, OrbinumClient, type OrbinumClientConfig, OrbinumClientProvider, PRECOMPILE_ADDR, PrivacyKeyManager, type PrivacyMerkleProof, PrivacyModule, type PrivateChainLinkAddedEvent, type PrivateChainLinkRemovedEvent, type PrivateChainLinkRevealedEvent, type PrivateLink, type PrivateLinkDispatchExecutedEvent, type PrivateTransferArgs, type PrivateTransferInput, type PrivateTransferOutput, type PrivateTransferParams, type PrivateTransferProofInputs, type ProofVerificationFailedEvent, type ProofVerifiedEvent, type ProxyCallExecutedEvent, type PutAliasOnSaleArgs, type PutOnSaleParams, type RawBlock, type RawBlockHeader, type RawTransferInput, type RawTransferOutput, type RegisterAliasArgs, type RegisterAssetArgs, type RegisterPrivateLinkArgs, type RegisterVerificationKeyArgs, type RelayerInfo, RelayerStatusModule, type RemoveChainLinkArgs, type RemovePrivateLinkArgs, type RemoveSupportedChainArgs, type RemoveVerificationKeyArgs, type ReservedEventData, type ResolvedAlias, type ResolvedSpendVersion, type RevealPrivateLinkArgs, type RpcV2MerkleProof, type RpcV2NullifierStatus, type RpcV2PoolAssetBalance, type RpcV2PoolStats, SLIP0044_NAMESPACE, SPENDING_KEY_VERIFYING_CONTRACT, SPENDING_KEY_WARNING, type ScanCommitment, type SelfEphWindowEntry, type SetAccountMetadataArgs, type SetActiveVersionArgs, type SetMetadataParams, type ShieldArgs, type ShieldBatchArgs, type ShieldBatchItem, type ShieldBatchParams, type ShieldOperation, type ShieldParams, type ShieldedEvent, type ShieldedEventData, type ShieldedPoolCall, type ShieldedPoolEvent, ShieldedPoolModule, ShieldedPoolPrecompile, SignatureScheme, type SpendingKeyTypedData, type StatusChangeEvent, type StatusListener, SubstrateClient, type SupportedChain, type SupportedChainAddedEvent, type SupportedChainRemovedEvent, type SystemHealth, type TokenInfo, type TokenTransfer, type TransferAliasArgs, type TransferEventData, type TransferInputNote, type TransferOutputNote, type TryDecryptOptions, type TxResult, type UnsafeTxOptions, type UnshieldArgs, type UnshieldParams, type UnshieldProofInputs, type UnshieldedEvent, type UnshieldedEventData, type UnverifyAssetArgs, VaultLockedError, type VerificationKeyRegisteredEvent, type VerificationKeyRemovedEvent, type VerifyAssetArgs, type VerifyProofArgs, type VkEntry, type ZkNote, type ZkVerifierCall, type ZkVerifierCircuitVersionInfo, type ZkVerifierEvent, type ZkVerifierHistoricalVersion, ZkVerifierModule, type ZkVerifierVersionStats, type ZkVerifierVkHash, accountIdHexToSs58, addressToAccountIdHex, applyNoteStatus, bigintTo32Be, bigintTo32Le, bigintTo32LeArr, blindTag, buildDummyTransferInput, bytesToBigintLE, canonicalAccountId, computeNoteCommitment, computeNullifier, computePathIndices, createNoteDisclosureKey, decodeNoteDisclosureKey, decodePrecompileCalldata, decryptJson, decryptNoteRecord, deriveMasterKeyBytes, deriveOwnerPk, deriveSelfEphSk, deriveSpendingKeyFromSignature, deriveSpendingKeyMessageV2, deriveSpendingKeyTypedData, deriveStealthOwnerPk, deriveStealthSk, deriveVaultBlindKey, deriveVaultKey, deriveViewTag, deriveViewingPublicKey, deriveViewingSecretKey, encryptJson, encryptNote, ensureHexPrefix, evmAddressToAccountId, evmToImplicitSubstrate, evmToMappedAccountHex, evmToSubstrate, formatBalance, formatORB, fromBase64, fromHex, generateFeeClaimProof, generateTransferProof, generateUnshieldProof, getPrecompileLabel, hexToBigint, hexToNumber, implicitSubstrateToEvm, isEvmAddress, isImplicitEvmAccount, isSs58, isSubstrateAddress, isUnifiedAddress, leHexToBigint, mapExtrinsicArgs, mapZkEventData, normalizeEvmAddress, noteBlindTag, randomBlinding, recoverOwnerPkPoint, selectNotes, selfEphWindow, shortHash, substrateSs58ToAccountIdHex, substrateToEvm, toBase64, toHex, toTxResult, truncateMiddle, tryDecryptNote, tryDecryptNoteVerbose, vaultReplacer, vaultReviver };
|
|
4494
|
+
export { type AccountListing, type AccountMappedData, type AccountMappedEvent, type AccountMappingCall, type AccountMappingEvent, AccountMappingModule, AccountMappingPrecompile, type AccountMetadata, type AccountUnmappedEvent, type ActiveVersionSetEvent, type AddChainLinkArgs, type AddChainLinkParams, type AddSupportedChainArgs, type AliasFullIdentity, type AliasInfo, type AliasListedForSaleEvent, type AliasOnSaleData, type AliasRegisteredData, type AliasRegisteredEvent, type AliasReleasedEvent, type AliasSaleCancelledEvent, type AliasSoldData, type AliasSoldEvent, type AliasTransferredData, type AliasTransferredEvent, type AssetRegisteredEvent, type AssetUnverifiedEvent, type AssetVerifiedEvent, BABYJUB_SUBORDER, BN254_R, type BatchRegisterVerificationKeysArgs, type BatchVerificationKeysRegisteredEvent, type BlockInfo, type BuyAliasArgs, type Bytes32, CURRENT_CIRCUIT_VERSION, type ChainInfo, type ChainLink, type ChainLinkAddedEvent, type ChainLinkRemovedEvent, CircuitId, CircuitId as CircuitIdType, CircuitVersionResolver, type ClaimShieldedFeesParams, type ClientProviderConfig, type CommitmentsInsertedEvent, type CommitmentsInsertedEventData, type ConnectionStatus, CryptoPrecompiles, type DecodedAddChainLinkArgs, type DecodedBatchArgs, type DecodedDispatchAsPrivateLinkArgs, type DecodedEthereumTransactArgs, type DecodedEvmCallArgs, type DecodedPrecompile, type DecodedPrivateTransferArgs, type DecodedPutAliasForSaleArgs, type DecodedRegisterAliasArgs, type DecodedRemarkArgs, type DecodedRevealPrivateLinkArgs, type DecodedSetAccountMetadataArgs, type DecodedShieldArgs, type DecodedShieldBatchArgs, type DecodedShieldBatchOperation, type DecodedSudoArgs, type DecodedTransferAllArgs, type DecodedTransferArgs, type DecodedTransferKeepAliveArgs, type DecodedUnshieldArgs, type DecryptedMemo, type DispatchAsLinkedAccountArgs, type DispatchAsLinkedParams, type DispatchAsPrivateLinkArgs, type DispatchError, type DispatchInfo, type DynamicBuilder, ENCRYPTED_MEMO_SIZE, EncryptedMemo, type EncryptedNoteRecord, type EndowedEventData, type EthereumExecutedData, type EventData, type EventPhase, type EventRecord, type EvmAddressInfo, type EvmBlock, EvmClient, type EvmExecutedData, type EvmExitReason, EvmExplorer, type EvmLog, type EvmSigner, type EvmTransaction, type EvmTxRequest, type EvmTxSummary, type ExtrinsicDecoder, type ExtrinsicFailedData, type ExtrinsicSuccessData, type FeeClaimProofInputs, type FormatOptions, KNOWN_PRECOMPILES, type KnownPrecompileInfo, type ListingInfo, MIN_SIGNATURE_BYTES, type MerkleRootUpdatedData, type MerkleRootUpdatedEvent, type MerkleTreeInfo, type MetadataUpdatedEvent, NoteBuilder, type NoteDisclosure, type NoteInput, type NoteStatusUpdate, type NullifiersSpentEvent, type NullifiersSpentEventData, OrbinumClient, type OrbinumClientConfig, OrbinumClientProvider, PRECOMPILE_ADDR, PrivacyKeyManager, type PrivacyMerkleProof, PrivacyModule, type PrivateChainLinkAddedEvent, type PrivateChainLinkRemovedEvent, type PrivateChainLinkRevealedEvent, type PrivateLink, type PrivateLinkDispatchExecutedEvent, type PrivateTransferArgs, type PrivateTransferInput, type PrivateTransferOutput, type PrivateTransferParams, type PrivateTransferProofInputs, type ProofVerificationFailedEvent, type ProofVerifiedEvent, type ProxyCallExecutedEvent, type PutAliasOnSaleArgs, type PutOnSaleParams, type RawBlock, type RawBlockHeader, type RawTransferInput, type RawTransferOutput, type RegisterAliasArgs, type RegisterAssetArgs, type RegisterPrivateLinkArgs, type RegisterVerificationKeyArgs, type RelayerInfo, RelayerStatusModule, type RemoveChainLinkArgs, type RemovePrivateLinkArgs, type RemoveSupportedChainArgs, type RemoveVerificationKeyArgs, type ReservedEventData, type ResolvedAlias, type ResolvedSpendVersion, type RevealPrivateLinkArgs, type RpcV2MerkleProof, type RpcV2NullifierStatus, type RpcV2PoolAssetBalance, type RpcV2PoolStats, SLIP0044_NAMESPACE, SPENDING_KEY_VERIFYING_CONTRACT, SPENDING_KEY_WARNING, type ScanCommitment, type SelfEphWindowEntry, type SetAccountMetadataArgs, type SetActiveVersionArgs, type SetMetadataParams, type ShieldArgs, type ShieldBatchArgs, type ShieldBatchItem, type ShieldBatchParams, type ShieldOperation, type ShieldParams, type ShieldedEvent, type ShieldedEventData, type ShieldedPoolCall, type ShieldedPoolEvent, ShieldedPoolModule, ShieldedPoolPrecompile, SignatureScheme, type SpendingKeyTypedData, type StatusChangeEvent, type StatusListener, SubstrateClient, type SupportedChain, type SupportedChainAddedEvent, type SupportedChainRemovedEvent, type SystemHealth, type TokenInfo, type TokenTransfer, type TransferAliasArgs, type TransferEventData, type TransferInputNote, type TransferOutputNote, type TryDecryptOptions, type TxResult, type UnsafeTxOptions, type UnshieldArgs, type UnshieldParams, type UnshieldProofInputs, type UnshieldedEvent, type UnshieldedEventData, type UnverifyAssetArgs, VaultLockedError, type VerificationKeyRegisteredEvent, type VerificationKeyRemovedEvent, type VerifyAssetArgs, type VerifyProofArgs, type VkEntry, type ZkNote, type ZkVerifierCall, type ZkVerifierCircuitVersionInfo, type ZkVerifierEvent, type ZkVerifierHistoricalVersion, ZkVerifierModule, type ZkVerifierVersionStats, type ZkVerifierVkHash, accountIdHexToSs58, addressToAccountIdHex, applyNoteStatus, bigintTo32Be, bigintTo32Le, bigintTo32LeArr, blindTag, buildDummyTransferInput, bytesToBigintLE, canonicalAccountId, computeNoteCommitment, computeNullifier, computePathIndices, createNoteDisclosureKey, decodeNoteDisclosureKey, decodePrecompileCalldata, decryptJson, decryptNoteRecord, deriveMasterKeyBytes, deriveOwnerPk, deriveSelfEphSk, deriveSpendingKeyFromSignature, deriveSpendingKeyMessageV2, deriveSpendingKeyTypedData, deriveStealthOwnerPk, deriveStealthSk, deriveVaultBlindKey, deriveVaultKey, deriveViewTag, deriveViewingPublicKey, deriveViewingSecretKey, encryptJson, encryptNote, ensureHexPrefix, evmAddressToAccountId, evmToImplicitSubstrate, evmToMappedAccountHex, evmToSubstrate, formatBalance, formatORB, fromBase64, fromHex, generateFeeClaimProof, generateTransferProof, generateUnshieldProof, getPrecompileLabel, hexToBigint, hexToNumber, implicitSubstrateToEvm, isEvmAddress, isImplicitEvmAccount, isSs58, isSubstrateAddress, isUnifiedAddress, leHexToBigint, mapExtrinsicArgs, mapZkEventData, normalizeEvmAddress, noteBlindTag, randomBlinding, recoverOwnerPkPoint, selectNotes, selfEphWindow, shortHash, substrateSs58ToAccountIdHex, substrateToEvm, toBase64, toHex, toTxResult, treeIdOf, truncateMiddle, tryDecryptNote, tryDecryptNoteVerbose, vaultReplacer, vaultReviver };
|
package/dist/index.d.ts
CHANGED
|
@@ -721,6 +721,13 @@ type ZkNote = {
|
|
|
721
721
|
spendingKey: bigint;
|
|
722
722
|
/** Circuit version this note was created under (see `CURRENT_CIRCUIT_VERSION`). Required. */
|
|
723
723
|
circuitVersion: number;
|
|
724
|
+
/**
|
|
725
|
+
* Global Merkle leaf index, when known. Optional so pre-forest vaults
|
|
726
|
+
* need no migration: notes without it predate the first tree seal and
|
|
727
|
+
* belong to tree 0. Populated on shield and on scan; used only to derive
|
|
728
|
+
* the forest tree for same-tree coin selection (`treeIdOf`).
|
|
729
|
+
*/
|
|
730
|
+
leafIndex?: number;
|
|
724
731
|
/** Whether the note has been spent/nullified on-chain. */
|
|
725
732
|
spent: boolean;
|
|
726
733
|
/** Local timestamp when this note was marked spent, or null if still active/unknown. */
|
|
@@ -1095,6 +1102,7 @@ type RpcV2MerkleProof = {
|
|
|
1095
1102
|
path: string[];
|
|
1096
1103
|
leafIndex: number;
|
|
1097
1104
|
treeDepth: number;
|
|
1105
|
+
treeId?: number | undefined;
|
|
1098
1106
|
};
|
|
1099
1107
|
type PrivacyMerkleProof = RpcV2MerkleProof & {
|
|
1100
1108
|
root: string;
|
|
@@ -2301,22 +2309,52 @@ declare function generateTransferProof(params: PrivateTransferProofInputs, optio
|
|
|
2301
2309
|
verbose?: boolean;
|
|
2302
2310
|
}): Promise<ProofResult>;
|
|
2303
2311
|
|
|
2312
|
+
/**
|
|
2313
|
+
* Forest tree a note belongs to.
|
|
2314
|
+
*
|
|
2315
|
+
* Falls back to tree 0 for a missing or malformed `leafIndex`. Both cases are
|
|
2316
|
+
* expected rather than defensive noise:
|
|
2317
|
+
*
|
|
2318
|
+
* - Notes persisted before the forest upgrade carry no index, and they all
|
|
2319
|
+
* predate the first seal, so tree 0 is the correct answer.
|
|
2320
|
+
* - The index originates in an indexer scan hint, which is untrusted. A
|
|
2321
|
+
* `NaN` reaching this function would make every same-tree comparison
|
|
2322
|
+
* false — no pair would ever be selectable and the whole balance would
|
|
2323
|
+
* look unspendable.
|
|
2324
|
+
*/
|
|
2325
|
+
declare function treeIdOf(note: Pick<ZkNote, 'leafIndex'>): number;
|
|
2326
|
+
/**
|
|
2327
|
+
* Outcome of {@link selectNotes}.
|
|
2328
|
+
*
|
|
2329
|
+
* - `[noteA, noteB | null]` — a spendable selection; a `null` second slot
|
|
2330
|
+
* means the transfer runs with a dummy input.
|
|
2331
|
+
* - `{ needsConsolidation: true }` — the balance covers the amount, but only
|
|
2332
|
+
* by pairing notes from different forest trees, which no single proof can
|
|
2333
|
+
* do. The caller should offer a consolidation, not an insufficient-funds
|
|
2334
|
+
* error.
|
|
2335
|
+
* - `null` — no combination covers the amount.
|
|
2336
|
+
*/
|
|
2337
|
+
type CoinSelection = [ZkNote, ZkNote | null] | {
|
|
2338
|
+
needsConsolidation: true;
|
|
2339
|
+
} | null;
|
|
2304
2340
|
/**
|
|
2305
2341
|
* Selects up to 2 unspent notes that together cover `needed` planck.
|
|
2306
2342
|
*
|
|
2307
|
-
*
|
|
2308
|
-
*
|
|
2309
|
-
*
|
|
2310
|
-
*
|
|
2343
|
+
* Both inputs of a transfer are proven together against ONE circuit VK and ONE
|
|
2344
|
+
* public `merkle_root`, so a pair must agree on two things: mixing circuit
|
|
2345
|
+
* versions produces an invalid proof, and notes in different forest trees
|
|
2346
|
+
* anchor to different roots that can never converge. A single note needs
|
|
2347
|
+
* neither check.
|
|
2311
2348
|
*
|
|
2312
|
-
*
|
|
2313
|
-
*
|
|
2314
|
-
*
|
|
2315
|
-
*
|
|
2349
|
+
* Resolution order:
|
|
2350
|
+
* 1. One note that alone covers `needed` → `[note, null]`.
|
|
2351
|
+
* 2. Smallest same-version, same-tree pair whose sum covers it → `[a, b]`.
|
|
2352
|
+
* 3. A cross-tree pair would cover it → `{ needsConsolidation: true }`.
|
|
2353
|
+
* 4. Nothing covers it → `null`.
|
|
2316
2354
|
*
|
|
2317
2355
|
* Only unspent notes with value > 0 are considered.
|
|
2318
2356
|
*/
|
|
2319
|
-
declare function selectNotes(notes: ZkNote[], needed: bigint):
|
|
2357
|
+
declare function selectNotes(notes: ZkNote[], needed: bigint): CoinSelection;
|
|
2320
2358
|
/**
|
|
2321
2359
|
* Builds a dummy `TransferInputNote` for use as the second input in a single-note transfer.
|
|
2322
2360
|
*
|
|
@@ -4453,4 +4491,4 @@ interface ExtrinsicFailedData {
|
|
|
4453
4491
|
dispatch_info: DispatchInfo;
|
|
4454
4492
|
}
|
|
4455
4493
|
|
|
4456
|
-
export { type AccountListing, type AccountMappedData, type AccountMappedEvent, type AccountMappingCall, type AccountMappingEvent, AccountMappingModule, AccountMappingPrecompile, type AccountMetadata, type AccountUnmappedEvent, type ActiveVersionSetEvent, type AddChainLinkArgs, type AddChainLinkParams, type AddSupportedChainArgs, type AliasFullIdentity, type AliasInfo, type AliasListedForSaleEvent, type AliasOnSaleData, type AliasRegisteredData, type AliasRegisteredEvent, type AliasReleasedEvent, type AliasSaleCancelledEvent, type AliasSoldData, type AliasSoldEvent, type AliasTransferredData, type AliasTransferredEvent, type AssetRegisteredEvent, type AssetUnverifiedEvent, type AssetVerifiedEvent, BABYJUB_SUBORDER, BN254_R, type BatchRegisterVerificationKeysArgs, type BatchVerificationKeysRegisteredEvent, type BlockInfo, type BuyAliasArgs, type Bytes32, CURRENT_CIRCUIT_VERSION, type ChainInfo, type ChainLink, type ChainLinkAddedEvent, type ChainLinkRemovedEvent, CircuitId, CircuitId as CircuitIdType, CircuitVersionResolver, type ClaimShieldedFeesParams, type ClientProviderConfig, type CommitmentsInsertedEvent, type CommitmentsInsertedEventData, type ConnectionStatus, CryptoPrecompiles, type DecodedAddChainLinkArgs, type DecodedBatchArgs, type DecodedDispatchAsPrivateLinkArgs, type DecodedEthereumTransactArgs, type DecodedEvmCallArgs, type DecodedPrecompile, type DecodedPrivateTransferArgs, type DecodedPutAliasForSaleArgs, type DecodedRegisterAliasArgs, type DecodedRemarkArgs, type DecodedRevealPrivateLinkArgs, type DecodedSetAccountMetadataArgs, type DecodedShieldArgs, type DecodedShieldBatchArgs, type DecodedShieldBatchOperation, type DecodedSudoArgs, type DecodedTransferAllArgs, type DecodedTransferArgs, type DecodedTransferKeepAliveArgs, type DecodedUnshieldArgs, type DecryptedMemo, type DispatchAsLinkedAccountArgs, type DispatchAsLinkedParams, type DispatchAsPrivateLinkArgs, type DispatchError, type DispatchInfo, type DynamicBuilder, ENCRYPTED_MEMO_SIZE, EncryptedMemo, type EncryptedNoteRecord, type EndowedEventData, type EthereumExecutedData, type EventData, type EventPhase, type EventRecord, type EvmAddressInfo, type EvmBlock, EvmClient, type EvmExecutedData, type EvmExitReason, EvmExplorer, type EvmLog, type EvmSigner, type EvmTransaction, type EvmTxRequest, type EvmTxSummary, type ExtrinsicDecoder, type ExtrinsicFailedData, type ExtrinsicSuccessData, type FeeClaimProofInputs, type FormatOptions, KNOWN_PRECOMPILES, type KnownPrecompileInfo, type ListingInfo, MIN_SIGNATURE_BYTES, type MerkleRootUpdatedData, type MerkleRootUpdatedEvent, type MerkleTreeInfo, type MetadataUpdatedEvent, NoteBuilder, type NoteDisclosure, type NoteInput, type NoteStatusUpdate, type NullifiersSpentEvent, type NullifiersSpentEventData, OrbinumClient, type OrbinumClientConfig, OrbinumClientProvider, PRECOMPILE_ADDR, PrivacyKeyManager, type PrivacyMerkleProof, PrivacyModule, type PrivateChainLinkAddedEvent, type PrivateChainLinkRemovedEvent, type PrivateChainLinkRevealedEvent, type PrivateLink, type PrivateLinkDispatchExecutedEvent, type PrivateTransferArgs, type PrivateTransferInput, type PrivateTransferOutput, type PrivateTransferParams, type PrivateTransferProofInputs, type ProofVerificationFailedEvent, type ProofVerifiedEvent, type ProxyCallExecutedEvent, type PutAliasOnSaleArgs, type PutOnSaleParams, type RawBlock, type RawBlockHeader, type RawTransferInput, type RawTransferOutput, type RegisterAliasArgs, type RegisterAssetArgs, type RegisterPrivateLinkArgs, type RegisterVerificationKeyArgs, type RelayerInfo, RelayerStatusModule, type RemoveChainLinkArgs, type RemovePrivateLinkArgs, type RemoveSupportedChainArgs, type RemoveVerificationKeyArgs, type ReservedEventData, type ResolvedAlias, type ResolvedSpendVersion, type RevealPrivateLinkArgs, type RpcV2MerkleProof, type RpcV2NullifierStatus, type RpcV2PoolAssetBalance, type RpcV2PoolStats, SLIP0044_NAMESPACE, SPENDING_KEY_VERIFYING_CONTRACT, SPENDING_KEY_WARNING, type ScanCommitment, type SelfEphWindowEntry, type SetAccountMetadataArgs, type SetActiveVersionArgs, type SetMetadataParams, type ShieldArgs, type ShieldBatchArgs, type ShieldBatchItem, type ShieldBatchParams, type ShieldOperation, type ShieldParams, type ShieldedEvent, type ShieldedEventData, type ShieldedPoolCall, type ShieldedPoolEvent, ShieldedPoolModule, ShieldedPoolPrecompile, SignatureScheme, type SpendingKeyTypedData, type StatusChangeEvent, type StatusListener, SubstrateClient, type SupportedChain, type SupportedChainAddedEvent, type SupportedChainRemovedEvent, type SystemHealth, type TokenInfo, type TokenTransfer, type TransferAliasArgs, type TransferEventData, type TransferInputNote, type TransferOutputNote, type TryDecryptOptions, type TxResult, type UnsafeTxOptions, type UnshieldArgs, type UnshieldParams, type UnshieldProofInputs, type UnshieldedEvent, type UnshieldedEventData, type UnverifyAssetArgs, VaultLockedError, type VerificationKeyRegisteredEvent, type VerificationKeyRemovedEvent, type VerifyAssetArgs, type VerifyProofArgs, type VkEntry, type ZkNote, type ZkVerifierCall, type ZkVerifierCircuitVersionInfo, type ZkVerifierEvent, type ZkVerifierHistoricalVersion, ZkVerifierModule, type ZkVerifierVersionStats, type ZkVerifierVkHash, accountIdHexToSs58, addressToAccountIdHex, applyNoteStatus, bigintTo32Be, bigintTo32Le, bigintTo32LeArr, blindTag, buildDummyTransferInput, bytesToBigintLE, canonicalAccountId, computeNoteCommitment, computeNullifier, computePathIndices, createNoteDisclosureKey, decodeNoteDisclosureKey, decodePrecompileCalldata, decryptJson, decryptNoteRecord, deriveMasterKeyBytes, deriveOwnerPk, deriveSelfEphSk, deriveSpendingKeyFromSignature, deriveSpendingKeyMessageV2, deriveSpendingKeyTypedData, deriveStealthOwnerPk, deriveStealthSk, deriveVaultBlindKey, deriveVaultKey, deriveViewTag, deriveViewingPublicKey, deriveViewingSecretKey, encryptJson, encryptNote, ensureHexPrefix, evmAddressToAccountId, evmToImplicitSubstrate, evmToMappedAccountHex, evmToSubstrate, formatBalance, formatORB, fromBase64, fromHex, generateFeeClaimProof, generateTransferProof, generateUnshieldProof, getPrecompileLabel, hexToBigint, hexToNumber, implicitSubstrateToEvm, isEvmAddress, isImplicitEvmAccount, isSs58, isSubstrateAddress, isUnifiedAddress, leHexToBigint, mapExtrinsicArgs, mapZkEventData, normalizeEvmAddress, noteBlindTag, randomBlinding, recoverOwnerPkPoint, selectNotes, selfEphWindow, shortHash, substrateSs58ToAccountIdHex, substrateToEvm, toBase64, toHex, toTxResult, truncateMiddle, tryDecryptNote, tryDecryptNoteVerbose, vaultReplacer, vaultReviver };
|
|
4494
|
+
export { type AccountListing, type AccountMappedData, type AccountMappedEvent, type AccountMappingCall, type AccountMappingEvent, AccountMappingModule, AccountMappingPrecompile, type AccountMetadata, type AccountUnmappedEvent, type ActiveVersionSetEvent, type AddChainLinkArgs, type AddChainLinkParams, type AddSupportedChainArgs, type AliasFullIdentity, type AliasInfo, type AliasListedForSaleEvent, type AliasOnSaleData, type AliasRegisteredData, type AliasRegisteredEvent, type AliasReleasedEvent, type AliasSaleCancelledEvent, type AliasSoldData, type AliasSoldEvent, type AliasTransferredData, type AliasTransferredEvent, type AssetRegisteredEvent, type AssetUnverifiedEvent, type AssetVerifiedEvent, BABYJUB_SUBORDER, BN254_R, type BatchRegisterVerificationKeysArgs, type BatchVerificationKeysRegisteredEvent, type BlockInfo, type BuyAliasArgs, type Bytes32, CURRENT_CIRCUIT_VERSION, type ChainInfo, type ChainLink, type ChainLinkAddedEvent, type ChainLinkRemovedEvent, CircuitId, CircuitId as CircuitIdType, CircuitVersionResolver, type ClaimShieldedFeesParams, type ClientProviderConfig, type CommitmentsInsertedEvent, type CommitmentsInsertedEventData, type ConnectionStatus, CryptoPrecompiles, type DecodedAddChainLinkArgs, type DecodedBatchArgs, type DecodedDispatchAsPrivateLinkArgs, type DecodedEthereumTransactArgs, type DecodedEvmCallArgs, type DecodedPrecompile, type DecodedPrivateTransferArgs, type DecodedPutAliasForSaleArgs, type DecodedRegisterAliasArgs, type DecodedRemarkArgs, type DecodedRevealPrivateLinkArgs, type DecodedSetAccountMetadataArgs, type DecodedShieldArgs, type DecodedShieldBatchArgs, type DecodedShieldBatchOperation, type DecodedSudoArgs, type DecodedTransferAllArgs, type DecodedTransferArgs, type DecodedTransferKeepAliveArgs, type DecodedUnshieldArgs, type DecryptedMemo, type DispatchAsLinkedAccountArgs, type DispatchAsLinkedParams, type DispatchAsPrivateLinkArgs, type DispatchError, type DispatchInfo, type DynamicBuilder, ENCRYPTED_MEMO_SIZE, EncryptedMemo, type EncryptedNoteRecord, type EndowedEventData, type EthereumExecutedData, type EventData, type EventPhase, type EventRecord, type EvmAddressInfo, type EvmBlock, EvmClient, type EvmExecutedData, type EvmExitReason, EvmExplorer, type EvmLog, type EvmSigner, type EvmTransaction, type EvmTxRequest, type EvmTxSummary, type ExtrinsicDecoder, type ExtrinsicFailedData, type ExtrinsicSuccessData, type FeeClaimProofInputs, type FormatOptions, KNOWN_PRECOMPILES, type KnownPrecompileInfo, type ListingInfo, MIN_SIGNATURE_BYTES, type MerkleRootUpdatedData, type MerkleRootUpdatedEvent, type MerkleTreeInfo, type MetadataUpdatedEvent, NoteBuilder, type NoteDisclosure, type NoteInput, type NoteStatusUpdate, type NullifiersSpentEvent, type NullifiersSpentEventData, OrbinumClient, type OrbinumClientConfig, OrbinumClientProvider, PRECOMPILE_ADDR, PrivacyKeyManager, type PrivacyMerkleProof, PrivacyModule, type PrivateChainLinkAddedEvent, type PrivateChainLinkRemovedEvent, type PrivateChainLinkRevealedEvent, type PrivateLink, type PrivateLinkDispatchExecutedEvent, type PrivateTransferArgs, type PrivateTransferInput, type PrivateTransferOutput, type PrivateTransferParams, type PrivateTransferProofInputs, type ProofVerificationFailedEvent, type ProofVerifiedEvent, type ProxyCallExecutedEvent, type PutAliasOnSaleArgs, type PutOnSaleParams, type RawBlock, type RawBlockHeader, type RawTransferInput, type RawTransferOutput, type RegisterAliasArgs, type RegisterAssetArgs, type RegisterPrivateLinkArgs, type RegisterVerificationKeyArgs, type RelayerInfo, RelayerStatusModule, type RemoveChainLinkArgs, type RemovePrivateLinkArgs, type RemoveSupportedChainArgs, type RemoveVerificationKeyArgs, type ReservedEventData, type ResolvedAlias, type ResolvedSpendVersion, type RevealPrivateLinkArgs, type RpcV2MerkleProof, type RpcV2NullifierStatus, type RpcV2PoolAssetBalance, type RpcV2PoolStats, SLIP0044_NAMESPACE, SPENDING_KEY_VERIFYING_CONTRACT, SPENDING_KEY_WARNING, type ScanCommitment, type SelfEphWindowEntry, type SetAccountMetadataArgs, type SetActiveVersionArgs, type SetMetadataParams, type ShieldArgs, type ShieldBatchArgs, type ShieldBatchItem, type ShieldBatchParams, type ShieldOperation, type ShieldParams, type ShieldedEvent, type ShieldedEventData, type ShieldedPoolCall, type ShieldedPoolEvent, ShieldedPoolModule, ShieldedPoolPrecompile, SignatureScheme, type SpendingKeyTypedData, type StatusChangeEvent, type StatusListener, SubstrateClient, type SupportedChain, type SupportedChainAddedEvent, type SupportedChainRemovedEvent, type SystemHealth, type TokenInfo, type TokenTransfer, type TransferAliasArgs, type TransferEventData, type TransferInputNote, type TransferOutputNote, type TryDecryptOptions, type TxResult, type UnsafeTxOptions, type UnshieldArgs, type UnshieldParams, type UnshieldProofInputs, type UnshieldedEvent, type UnshieldedEventData, type UnverifyAssetArgs, VaultLockedError, type VerificationKeyRegisteredEvent, type VerificationKeyRemovedEvent, type VerifyAssetArgs, type VerifyProofArgs, type VkEntry, type ZkNote, type ZkVerifierCall, type ZkVerifierCircuitVersionInfo, type ZkVerifierEvent, type ZkVerifierHistoricalVersion, ZkVerifierModule, type ZkVerifierVersionStats, type ZkVerifierVkHash, accountIdHexToSs58, addressToAccountIdHex, applyNoteStatus, bigintTo32Be, bigintTo32Le, bigintTo32LeArr, blindTag, buildDummyTransferInput, bytesToBigintLE, canonicalAccountId, computeNoteCommitment, computeNullifier, computePathIndices, createNoteDisclosureKey, decodeNoteDisclosureKey, decodePrecompileCalldata, decryptJson, decryptNoteRecord, deriveMasterKeyBytes, deriveOwnerPk, deriveSelfEphSk, deriveSpendingKeyFromSignature, deriveSpendingKeyMessageV2, deriveSpendingKeyTypedData, deriveStealthOwnerPk, deriveStealthSk, deriveVaultBlindKey, deriveVaultKey, deriveViewTag, deriveViewingPublicKey, deriveViewingSecretKey, encryptJson, encryptNote, ensureHexPrefix, evmAddressToAccountId, evmToImplicitSubstrate, evmToMappedAccountHex, evmToSubstrate, formatBalance, formatORB, fromBase64, fromHex, generateFeeClaimProof, generateTransferProof, generateUnshieldProof, getPrecompileLabel, hexToBigint, hexToNumber, implicitSubstrateToEvm, isEvmAddress, isImplicitEvmAccount, isSs58, isSubstrateAddress, isUnifiedAddress, leHexToBigint, mapExtrinsicArgs, mapZkEventData, normalizeEvmAddress, noteBlindTag, randomBlinding, recoverOwnerPkPoint, selectNotes, selfEphWindow, shortHash, substrateSs58ToAccountIdHex, substrateToEvm, toBase64, toHex, toTxResult, treeIdOf, truncateMiddle, tryDecryptNote, tryDecryptNoteVerbose, vaultReplacer, vaultReviver };
|
package/dist/index.js
CHANGED
|
@@ -131,6 +131,7 @@ __export(index_exports, {
|
|
|
131
131
|
toBase64: () => toBase64,
|
|
132
132
|
toHex: () => toHex,
|
|
133
133
|
toTxResult: () => toTxResult,
|
|
134
|
+
treeIdOf: () => treeIdOf,
|
|
134
135
|
truncateMiddle: () => truncateMiddle,
|
|
135
136
|
tryDecryptNote: () => tryDecryptNote,
|
|
136
137
|
tryDecryptNoteVerbose: () => tryDecryptNoteVerbose,
|
|
@@ -2288,7 +2289,8 @@ var PrivacyModule = class {
|
|
|
2288
2289
|
return {
|
|
2289
2290
|
path: raw.path,
|
|
2290
2291
|
leafIndex: raw.leaf_index,
|
|
2291
|
-
treeDepth: raw.tree_depth
|
|
2292
|
+
treeDepth: raw.tree_depth,
|
|
2293
|
+
treeId: raw.tree_id
|
|
2292
2294
|
};
|
|
2293
2295
|
}
|
|
2294
2296
|
/**
|
|
@@ -2308,6 +2310,7 @@ var PrivacyModule = class {
|
|
|
2308
2310
|
path: raw.path,
|
|
2309
2311
|
leafIndex: raw.leaf_index,
|
|
2310
2312
|
treeDepth: raw.tree_depth,
|
|
2313
|
+
treeId: raw.tree_id,
|
|
2311
2314
|
root: raw.root
|
|
2312
2315
|
};
|
|
2313
2316
|
}
|
|
@@ -4100,6 +4103,7 @@ function tryDecryptNoteVerbose(commitment, viewingSecretKey, spendingKey, ownOwn
|
|
|
4100
4103
|
blinding: plaintext.blinding,
|
|
4101
4104
|
spendingKey: effectiveSpendingKey,
|
|
4102
4105
|
circuitVersion: plaintext.circuitVersion,
|
|
4106
|
+
...Number.isSafeInteger(commitment.leafIndex) && commitment.leafIndex >= 0 && commitment.leafIndex < 2 ** 32 ? { leafIndex: commitment.leafIndex } : {},
|
|
4103
4107
|
spent: false,
|
|
4104
4108
|
spentAt: null,
|
|
4105
4109
|
commitment: recomputed,
|
|
@@ -4164,6 +4168,12 @@ function decodeNoteDisclosureKey(key) {
|
|
|
4164
4168
|
|
|
4165
4169
|
// src/shielded-pool/protocol/coinSelection.ts
|
|
4166
4170
|
var TRANSFER_TREE_DEPTH = 20;
|
|
4171
|
+
var LEAVES_PER_TREE = 1 << TRANSFER_TREE_DEPTH;
|
|
4172
|
+
function treeIdOf(note) {
|
|
4173
|
+
const idx = note.leafIndex;
|
|
4174
|
+
if (idx === void 0 || !Number.isSafeInteger(idx) || idx < 0 || idx >= 2 ** 32) return 0;
|
|
4175
|
+
return Math.floor(idx / LEAVES_PER_TREE);
|
|
4176
|
+
}
|
|
4167
4177
|
function selectNotes(notes, needed) {
|
|
4168
4178
|
const unspent = notes.filter((n) => !n.spent && n.value > 0n);
|
|
4169
4179
|
const sorted = [...unspent].sort((a, b) => a.value < b.value ? -1 : 1);
|
|
@@ -4173,11 +4183,20 @@ function selectNotes(notes, needed) {
|
|
|
4173
4183
|
for (let j = i + 1; j < sorted.length; j++) {
|
|
4174
4184
|
const a = sorted[i];
|
|
4175
4185
|
const b = sorted[j];
|
|
4176
|
-
if (a !== void 0 && b !== void 0 && a.circuitVersion === b.circuitVersion && a.value + b.value >= needed) {
|
|
4186
|
+
if (a !== void 0 && b !== void 0 && a.circuitVersion === b.circuitVersion && treeIdOf(a) === treeIdOf(b) && a.value + b.value >= needed) {
|
|
4177
4187
|
return [a, b];
|
|
4178
4188
|
}
|
|
4179
4189
|
}
|
|
4180
4190
|
}
|
|
4191
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
4192
|
+
for (let j = i + 1; j < sorted.length; j++) {
|
|
4193
|
+
const a = sorted[i];
|
|
4194
|
+
const b = sorted[j];
|
|
4195
|
+
if (a !== void 0 && b !== void 0 && a.circuitVersion === b.circuitVersion && a.value + b.value >= needed) {
|
|
4196
|
+
return { needsConsolidation: true };
|
|
4197
|
+
}
|
|
4198
|
+
}
|
|
4199
|
+
}
|
|
4181
4200
|
return null;
|
|
4182
4201
|
}
|
|
4183
4202
|
function buildDummyTransferInput(assetId) {
|
|
@@ -5579,6 +5598,7 @@ var import_polkadot_api5 = require("polkadot-api");
|
|
|
5579
5598
|
toBase64,
|
|
5580
5599
|
toHex,
|
|
5581
5600
|
toTxResult,
|
|
5601
|
+
treeIdOf,
|
|
5582
5602
|
truncateMiddle,
|
|
5583
5603
|
tryDecryptNote,
|
|
5584
5604
|
tryDecryptNoteVerbose,
|
package/dist/index.mjs
CHANGED
|
@@ -2148,7 +2148,8 @@ var PrivacyModule = class {
|
|
|
2148
2148
|
return {
|
|
2149
2149
|
path: raw.path,
|
|
2150
2150
|
leafIndex: raw.leaf_index,
|
|
2151
|
-
treeDepth: raw.tree_depth
|
|
2151
|
+
treeDepth: raw.tree_depth,
|
|
2152
|
+
treeId: raw.tree_id
|
|
2152
2153
|
};
|
|
2153
2154
|
}
|
|
2154
2155
|
/**
|
|
@@ -2168,6 +2169,7 @@ var PrivacyModule = class {
|
|
|
2168
2169
|
path: raw.path,
|
|
2169
2170
|
leafIndex: raw.leaf_index,
|
|
2170
2171
|
treeDepth: raw.tree_depth,
|
|
2172
|
+
treeId: raw.tree_id,
|
|
2171
2173
|
root: raw.root
|
|
2172
2174
|
};
|
|
2173
2175
|
}
|
|
@@ -3963,6 +3965,7 @@ function tryDecryptNoteVerbose(commitment, viewingSecretKey, spendingKey, ownOwn
|
|
|
3963
3965
|
blinding: plaintext.blinding,
|
|
3964
3966
|
spendingKey: effectiveSpendingKey,
|
|
3965
3967
|
circuitVersion: plaintext.circuitVersion,
|
|
3968
|
+
...Number.isSafeInteger(commitment.leafIndex) && commitment.leafIndex >= 0 && commitment.leafIndex < 2 ** 32 ? { leafIndex: commitment.leafIndex } : {},
|
|
3966
3969
|
spent: false,
|
|
3967
3970
|
spentAt: null,
|
|
3968
3971
|
commitment: recomputed,
|
|
@@ -4027,6 +4030,12 @@ function decodeNoteDisclosureKey(key) {
|
|
|
4027
4030
|
|
|
4028
4031
|
// src/shielded-pool/protocol/coinSelection.ts
|
|
4029
4032
|
var TRANSFER_TREE_DEPTH = 20;
|
|
4033
|
+
var LEAVES_PER_TREE = 1 << TRANSFER_TREE_DEPTH;
|
|
4034
|
+
function treeIdOf(note) {
|
|
4035
|
+
const idx = note.leafIndex;
|
|
4036
|
+
if (idx === void 0 || !Number.isSafeInteger(idx) || idx < 0 || idx >= 2 ** 32) return 0;
|
|
4037
|
+
return Math.floor(idx / LEAVES_PER_TREE);
|
|
4038
|
+
}
|
|
4030
4039
|
function selectNotes(notes, needed) {
|
|
4031
4040
|
const unspent = notes.filter((n) => !n.spent && n.value > 0n);
|
|
4032
4041
|
const sorted = [...unspent].sort((a, b) => a.value < b.value ? -1 : 1);
|
|
@@ -4036,11 +4045,20 @@ function selectNotes(notes, needed) {
|
|
|
4036
4045
|
for (let j = i + 1; j < sorted.length; j++) {
|
|
4037
4046
|
const a = sorted[i];
|
|
4038
4047
|
const b = sorted[j];
|
|
4039
|
-
if (a !== void 0 && b !== void 0 && a.circuitVersion === b.circuitVersion && a.value + b.value >= needed) {
|
|
4048
|
+
if (a !== void 0 && b !== void 0 && a.circuitVersion === b.circuitVersion && treeIdOf(a) === treeIdOf(b) && a.value + b.value >= needed) {
|
|
4040
4049
|
return [a, b];
|
|
4041
4050
|
}
|
|
4042
4051
|
}
|
|
4043
4052
|
}
|
|
4053
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
4054
|
+
for (let j = i + 1; j < sorted.length; j++) {
|
|
4055
|
+
const a = sorted[i];
|
|
4056
|
+
const b = sorted[j];
|
|
4057
|
+
if (a !== void 0 && b !== void 0 && a.circuitVersion === b.circuitVersion && a.value + b.value >= needed) {
|
|
4058
|
+
return { needsConsolidation: true };
|
|
4059
|
+
}
|
|
4060
|
+
}
|
|
4061
|
+
}
|
|
4044
4062
|
return null;
|
|
4045
4063
|
}
|
|
4046
4064
|
function buildDummyTransferInput(assetId) {
|
|
@@ -5464,6 +5482,7 @@ export {
|
|
|
5464
5482
|
toBase64,
|
|
5465
5483
|
toHex,
|
|
5466
5484
|
toTxResult,
|
|
5485
|
+
treeIdOf,
|
|
5467
5486
|
truncateMiddle,
|
|
5468
5487
|
tryDecryptNote,
|
|
5469
5488
|
tryDecryptNoteVerbose,
|