@orbinum/sdk 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +50 -2
- package/dist/index.d.ts +50 -2
- package/dist/index.js +81 -15
- package/dist/index.mjs +85 -22
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -664,6 +664,13 @@ type NoteInput = {
|
|
|
664
664
|
counterpartyPk?: bigint;
|
|
665
665
|
/** Circuit version to stamp on the note. Defaults to `CURRENT_CIRCUIT_VERSION`. */
|
|
666
666
|
circuitVersion?: number;
|
|
667
|
+
/**
|
|
668
|
+
* 32-byte ephemeral secret for the memo ECDH. Self-notes pass a
|
|
669
|
+
* deterministic one (deriveSelfEphSk) so a cold restore recognizes them by
|
|
670
|
+
* ephPk equality with no trial ECDH. Ignored on the stealth path (it
|
|
671
|
+
* generates its own coordinated ephSk). Default: random.
|
|
672
|
+
*/
|
|
673
|
+
ephSkOverride?: Uint8Array;
|
|
667
674
|
};
|
|
668
675
|
/**
|
|
669
676
|
* Circuit version notes are created under today. A note carries its version
|
|
@@ -1920,7 +1927,8 @@ declare class NoteBuilder {
|
|
|
1920
1927
|
/**
|
|
1921
1928
|
* EncryptedMemo — TypeScript implementation of Orbinum's encrypted note memo.
|
|
1922
1929
|
*
|
|
1923
|
-
*
|
|
1930
|
+
* Native TypeScript implementation — no WASM required. This file IS the
|
|
1931
|
+
* normative memo format: the chain treats memos as opaque 180-byte blobs.
|
|
1924
1932
|
*
|
|
1925
1933
|
* Layout (180 bytes, ECDH):
|
|
1926
1934
|
* nonce(12) || ciphertext+MAC(136) || ephPk_packed(32) = 180
|
|
@@ -2048,6 +2056,31 @@ declare const EncryptedMemo: {
|
|
|
2048
2056
|
*/
|
|
2049
2057
|
declare function deriveViewTag(sharedSecret: Uint8Array): number;
|
|
2050
2058
|
|
|
2059
|
+
/**
|
|
2060
|
+
* Derive the deterministic 32-byte ephemeral secret for self-note `index`.
|
|
2061
|
+
* Feed it to EncryptedMemo.encrypt / NoteBuilder.build as `ephSkOverride`.
|
|
2062
|
+
*/
|
|
2063
|
+
declare function deriveSelfEphSk(spendingKey: bigint, index: number): Uint8Array;
|
|
2064
|
+
/** One precomputed self-note window entry. */
|
|
2065
|
+
interface SelfEphWindowEntry {
|
|
2066
|
+
index: number;
|
|
2067
|
+
/** 0x-prefixed LE-packed ephPk — byte-identical to the memo's last 32 bytes. */
|
|
2068
|
+
ephPkHex: string;
|
|
2069
|
+
/** ECDH shared secret vs the wallet's own ivk — feeds decryptWithSharedSecret. */
|
|
2070
|
+
sharedSecret: Uint8Array;
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Precompute the self-note discovery window [from, from+count): for each
|
|
2074
|
+
* index, the ephPk the wallet would have published and the shared secret
|
|
2075
|
+
* needed to decrypt the memo. One EC pass up front; scanning then matches
|
|
2076
|
+
* hints by ephPk hex equality with no per-hint EC work.
|
|
2077
|
+
*
|
|
2078
|
+
* @param spendingKey Wallet spending key (the seed of the derivation).
|
|
2079
|
+
* @param ivkPacked The wallet's OWN 32-byte LE packed viewing public key —
|
|
2080
|
+
* self memos are encrypted to it.
|
|
2081
|
+
*/
|
|
2082
|
+
declare function selfEphWindow(spendingKey: bigint, ivkPacked: Uint8Array, from: number, count: number): SelfEphWindowEntry[];
|
|
2083
|
+
|
|
2051
2084
|
/**
|
|
2052
2085
|
* NoteDecryptor
|
|
2053
2086
|
*
|
|
@@ -2071,6 +2104,14 @@ declare function deriveViewTag(sharedSecret: Uint8Array): number;
|
|
|
2071
2104
|
* deriveSpendingKeyFromSignature.
|
|
2072
2105
|
*/
|
|
2073
2106
|
declare function computeNullifier(commitment: bigint, spendingKey: bigint): bigint;
|
|
2107
|
+
/**
|
|
2108
|
+
* Computes a note commitment.
|
|
2109
|
+
* commitment = Poseidon4(value, assetId, ownerPk, blinding)
|
|
2110
|
+
*
|
|
2111
|
+
* Mirrors NoteCommitment in note.circom — use it to verify a stored note
|
|
2112
|
+
* against its on-chain commitment before spending it.
|
|
2113
|
+
*/
|
|
2114
|
+
declare function computeNoteCommitment(value: bigint, assetId: bigint, ownerPk: bigint, blinding: bigint): bigint;
|
|
2074
2115
|
interface TryDecryptOptions {
|
|
2075
2116
|
/**
|
|
2076
2117
|
* View-tag fast path: compute the ECDH shared secret once, compare the
|
|
@@ -2081,6 +2122,13 @@ interface TryDecryptOptions {
|
|
|
2081
2122
|
* legacy memos carry a random byte there and would be silently dropped.
|
|
2082
2123
|
*/
|
|
2083
2124
|
viewTag?: boolean;
|
|
2125
|
+
/**
|
|
2126
|
+
* Precomputed ECDH shared secret (self-note discovery: the caller matched
|
|
2127
|
+
* the hint's ephPk against a selfEphWindow and already holds the secret).
|
|
2128
|
+
* Skips the ECDH and the view-tag gate entirely; the decrypt + commitment
|
|
2129
|
+
* check still validate the note as usual.
|
|
2130
|
+
*/
|
|
2131
|
+
sharedSecret?: Uint8Array;
|
|
2084
2132
|
}
|
|
2085
2133
|
/**
|
|
2086
2134
|
* Attempt to decrypt an on-chain commitment using the recipient's viewing secret key.
|
|
@@ -4221,4 +4269,4 @@ interface ExtrinsicFailedData {
|
|
|
4221
4269
|
dispatch_info: DispatchInfo;
|
|
4222
4270
|
}
|
|
4223
4271
|
|
|
4224
|
-
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, 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, type ScanCommitment, 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 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, computeNullifier, computePathIndices, createNoteDisclosureKey, decodeNoteDisclosureKey, decodePrecompileCalldata, decryptJson, decryptNoteRecord, deriveMasterKeyBytes, deriveOwnerPk, deriveSpendingKeyFromSignature, deriveSpendingKeyMessage, 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, shortHash, substrateSs58ToAccountIdHex, substrateToEvm, toBase64, toHex, toTxResult, truncateMiddle, tryDecryptNote, tryDecryptNoteVerbose, vaultReplacer, vaultReviver };
|
|
4272
|
+
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, 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, 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 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, computeNoteCommitment, computeNullifier, computePathIndices, createNoteDisclosureKey, decodeNoteDisclosureKey, decodePrecompileCalldata, decryptJson, decryptNoteRecord, deriveMasterKeyBytes, deriveOwnerPk, deriveSelfEphSk, deriveSpendingKeyFromSignature, deriveSpendingKeyMessage, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -664,6 +664,13 @@ type NoteInput = {
|
|
|
664
664
|
counterpartyPk?: bigint;
|
|
665
665
|
/** Circuit version to stamp on the note. Defaults to `CURRENT_CIRCUIT_VERSION`. */
|
|
666
666
|
circuitVersion?: number;
|
|
667
|
+
/**
|
|
668
|
+
* 32-byte ephemeral secret for the memo ECDH. Self-notes pass a
|
|
669
|
+
* deterministic one (deriveSelfEphSk) so a cold restore recognizes them by
|
|
670
|
+
* ephPk equality with no trial ECDH. Ignored on the stealth path (it
|
|
671
|
+
* generates its own coordinated ephSk). Default: random.
|
|
672
|
+
*/
|
|
673
|
+
ephSkOverride?: Uint8Array;
|
|
667
674
|
};
|
|
668
675
|
/**
|
|
669
676
|
* Circuit version notes are created under today. A note carries its version
|
|
@@ -1920,7 +1927,8 @@ declare class NoteBuilder {
|
|
|
1920
1927
|
/**
|
|
1921
1928
|
* EncryptedMemo — TypeScript implementation of Orbinum's encrypted note memo.
|
|
1922
1929
|
*
|
|
1923
|
-
*
|
|
1930
|
+
* Native TypeScript implementation — no WASM required. This file IS the
|
|
1931
|
+
* normative memo format: the chain treats memos as opaque 180-byte blobs.
|
|
1924
1932
|
*
|
|
1925
1933
|
* Layout (180 bytes, ECDH):
|
|
1926
1934
|
* nonce(12) || ciphertext+MAC(136) || ephPk_packed(32) = 180
|
|
@@ -2048,6 +2056,31 @@ declare const EncryptedMemo: {
|
|
|
2048
2056
|
*/
|
|
2049
2057
|
declare function deriveViewTag(sharedSecret: Uint8Array): number;
|
|
2050
2058
|
|
|
2059
|
+
/**
|
|
2060
|
+
* Derive the deterministic 32-byte ephemeral secret for self-note `index`.
|
|
2061
|
+
* Feed it to EncryptedMemo.encrypt / NoteBuilder.build as `ephSkOverride`.
|
|
2062
|
+
*/
|
|
2063
|
+
declare function deriveSelfEphSk(spendingKey: bigint, index: number): Uint8Array;
|
|
2064
|
+
/** One precomputed self-note window entry. */
|
|
2065
|
+
interface SelfEphWindowEntry {
|
|
2066
|
+
index: number;
|
|
2067
|
+
/** 0x-prefixed LE-packed ephPk — byte-identical to the memo's last 32 bytes. */
|
|
2068
|
+
ephPkHex: string;
|
|
2069
|
+
/** ECDH shared secret vs the wallet's own ivk — feeds decryptWithSharedSecret. */
|
|
2070
|
+
sharedSecret: Uint8Array;
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Precompute the self-note discovery window [from, from+count): for each
|
|
2074
|
+
* index, the ephPk the wallet would have published and the shared secret
|
|
2075
|
+
* needed to decrypt the memo. One EC pass up front; scanning then matches
|
|
2076
|
+
* hints by ephPk hex equality with no per-hint EC work.
|
|
2077
|
+
*
|
|
2078
|
+
* @param spendingKey Wallet spending key (the seed of the derivation).
|
|
2079
|
+
* @param ivkPacked The wallet's OWN 32-byte LE packed viewing public key —
|
|
2080
|
+
* self memos are encrypted to it.
|
|
2081
|
+
*/
|
|
2082
|
+
declare function selfEphWindow(spendingKey: bigint, ivkPacked: Uint8Array, from: number, count: number): SelfEphWindowEntry[];
|
|
2083
|
+
|
|
2051
2084
|
/**
|
|
2052
2085
|
* NoteDecryptor
|
|
2053
2086
|
*
|
|
@@ -2071,6 +2104,14 @@ declare function deriveViewTag(sharedSecret: Uint8Array): number;
|
|
|
2071
2104
|
* deriveSpendingKeyFromSignature.
|
|
2072
2105
|
*/
|
|
2073
2106
|
declare function computeNullifier(commitment: bigint, spendingKey: bigint): bigint;
|
|
2107
|
+
/**
|
|
2108
|
+
* Computes a note commitment.
|
|
2109
|
+
* commitment = Poseidon4(value, assetId, ownerPk, blinding)
|
|
2110
|
+
*
|
|
2111
|
+
* Mirrors NoteCommitment in note.circom — use it to verify a stored note
|
|
2112
|
+
* against its on-chain commitment before spending it.
|
|
2113
|
+
*/
|
|
2114
|
+
declare function computeNoteCommitment(value: bigint, assetId: bigint, ownerPk: bigint, blinding: bigint): bigint;
|
|
2074
2115
|
interface TryDecryptOptions {
|
|
2075
2116
|
/**
|
|
2076
2117
|
* View-tag fast path: compute the ECDH shared secret once, compare the
|
|
@@ -2081,6 +2122,13 @@ interface TryDecryptOptions {
|
|
|
2081
2122
|
* legacy memos carry a random byte there and would be silently dropped.
|
|
2082
2123
|
*/
|
|
2083
2124
|
viewTag?: boolean;
|
|
2125
|
+
/**
|
|
2126
|
+
* Precomputed ECDH shared secret (self-note discovery: the caller matched
|
|
2127
|
+
* the hint's ephPk against a selfEphWindow and already holds the secret).
|
|
2128
|
+
* Skips the ECDH and the view-tag gate entirely; the decrypt + commitment
|
|
2129
|
+
* check still validate the note as usual.
|
|
2130
|
+
*/
|
|
2131
|
+
sharedSecret?: Uint8Array;
|
|
2084
2132
|
}
|
|
2085
2133
|
/**
|
|
2086
2134
|
* Attempt to decrypt an on-chain commitment using the recipient's viewing secret key.
|
|
@@ -4221,4 +4269,4 @@ interface ExtrinsicFailedData {
|
|
|
4221
4269
|
dispatch_info: DispatchInfo;
|
|
4222
4270
|
}
|
|
4223
4271
|
|
|
4224
|
-
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, 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, type ScanCommitment, 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 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, computeNullifier, computePathIndices, createNoteDisclosureKey, decodeNoteDisclosureKey, decodePrecompileCalldata, decryptJson, decryptNoteRecord, deriveMasterKeyBytes, deriveOwnerPk, deriveSpendingKeyFromSignature, deriveSpendingKeyMessage, 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, shortHash, substrateSs58ToAccountIdHex, substrateToEvm, toBase64, toHex, toTxResult, truncateMiddle, tryDecryptNote, tryDecryptNoteVerbose, vaultReplacer, vaultReviver };
|
|
4272
|
+
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, 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, 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 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, computeNoteCommitment, computeNullifier, computePathIndices, createNoteDisclosureKey, decodeNoteDisclosureKey, decodePrecompileCalldata, decryptJson, decryptNoteRecord, deriveMasterKeyBytes, deriveOwnerPk, deriveSelfEphSk, deriveSpendingKeyFromSignature, deriveSpendingKeyMessage, 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 };
|
package/dist/index.js
CHANGED
|
@@ -63,6 +63,7 @@ __export(index_exports, {
|
|
|
63
63
|
blindTag: () => blindTag,
|
|
64
64
|
buildDummyTransferInput: () => buildDummyTransferInput,
|
|
65
65
|
bytesToBigintLE: () => bytesToBigintLE,
|
|
66
|
+
computeNoteCommitment: () => computeNoteCommitment,
|
|
66
67
|
computeNullifier: () => computeNullifier,
|
|
67
68
|
computePathIndices: () => computePathIndices,
|
|
68
69
|
connectInjectedExtension: () => import_pjs_signer.connectInjectedExtension,
|
|
@@ -73,6 +74,7 @@ __export(index_exports, {
|
|
|
73
74
|
decryptNoteRecord: () => decryptNoteRecord,
|
|
74
75
|
deriveMasterKeyBytes: () => deriveMasterKeyBytes,
|
|
75
76
|
deriveOwnerPk: () => deriveOwnerPk,
|
|
77
|
+
deriveSelfEphSk: () => deriveSelfEphSk,
|
|
76
78
|
deriveSpendingKeyFromSignature: () => deriveSpendingKeyFromSignature,
|
|
77
79
|
deriveSpendingKeyMessage: () => deriveSpendingKeyMessage,
|
|
78
80
|
deriveStealthOwnerPk: () => deriveStealthOwnerPk,
|
|
@@ -117,6 +119,7 @@ __export(index_exports, {
|
|
|
117
119
|
randomBlinding: () => randomBlinding,
|
|
118
120
|
recoverOwnerPkPoint: () => recoverOwnerPkPoint,
|
|
119
121
|
selectNotes: () => selectNotes,
|
|
122
|
+
selfEphWindow: () => selfEphWindow,
|
|
120
123
|
shortHash: () => shortHash,
|
|
121
124
|
substrateSs58ToAccountIdHex: () => substrateSs58ToAccountIdHex,
|
|
122
125
|
substrateToEvm: () => substrateToEvm,
|
|
@@ -1208,6 +1211,32 @@ var import_chacha = require("@noble/ciphers/chacha.js");
|
|
|
1208
1211
|
var import_utils = require("@noble/ciphers/utils.js");
|
|
1209
1212
|
var import_baby_jubjub = require("@zk-kit/baby-jubjub");
|
|
1210
1213
|
|
|
1214
|
+
// src/utils/bjj-fast.ts
|
|
1215
|
+
var import_edwards = require("@noble/curves/abstract/edwards.js");
|
|
1216
|
+
var P = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
1217
|
+
var N = 2736030358979909402780800718157159386076813972158567259200215660948447373041n;
|
|
1218
|
+
var BjjPoint = (0, import_edwards.edwards)({
|
|
1219
|
+
p: P,
|
|
1220
|
+
n: N,
|
|
1221
|
+
h: 8n,
|
|
1222
|
+
a: 168700n,
|
|
1223
|
+
d: 168696n,
|
|
1224
|
+
Gx: 5299619240641551281634865583518297030282874472190772894086521144482721001553n,
|
|
1225
|
+
Gy: 16950150798460657717958625567821834550301663161624707787222815936182638968203n
|
|
1226
|
+
});
|
|
1227
|
+
function fastMulBase(scalar) {
|
|
1228
|
+
const s = scalar % N;
|
|
1229
|
+
if (s === 0n) return [0n, 1n];
|
|
1230
|
+
const { x, y } = BjjPoint.BASE.multiply(s).toAffine();
|
|
1231
|
+
return [x, y];
|
|
1232
|
+
}
|
|
1233
|
+
function fastMulPoint(point, scalar) {
|
|
1234
|
+
const s = scalar % N;
|
|
1235
|
+
if (s === 0n) return [0n, 1n];
|
|
1236
|
+
const { x, y } = BjjPoint.fromAffine({ x: point[0], y: point[1] }).multiplyUnsafe(s).toAffine();
|
|
1237
|
+
return [x, y];
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1211
1240
|
// src/utils/bytes.ts
|
|
1212
1241
|
function bigintTo32Le(n) {
|
|
1213
1242
|
const buf = new Uint8Array(32);
|
|
@@ -1357,13 +1386,13 @@ var EncryptedMemo = {
|
|
|
1357
1386
|
if (ephSkBytes.length !== 32)
|
|
1358
1387
|
throw new Error("EncryptedMemo.encrypt: ephSkOverride must be 32 bytes");
|
|
1359
1388
|
const ephSkScalar = bytesToBjjScalar(ephSkBytes);
|
|
1360
|
-
const ephPkPoint = (
|
|
1389
|
+
const ephPkPoint = fastMulBase(ephSkScalar);
|
|
1361
1390
|
ephPkPackedBytes = bigintTo32Le((0, import_baby_jubjub.packPoint)(ephPkPoint));
|
|
1362
1391
|
const ivkPackedBigint = bytesToBigintLE(recipientIvkPacked);
|
|
1363
1392
|
const ivkPoint = (0, import_baby_jubjub.unpackPoint)(ivkPackedBigint);
|
|
1364
1393
|
if (!ivkPoint)
|
|
1365
1394
|
throw new Error("EncryptedMemo.encrypt: invalid recipient viewing public key");
|
|
1366
|
-
const sharedPoint = (
|
|
1395
|
+
const sharedPoint = fastMulPoint(ivkPoint, ephSkScalar);
|
|
1367
1396
|
sharedSecret = bigintTo32Le(sharedPoint[0]);
|
|
1368
1397
|
}
|
|
1369
1398
|
nonce[0] = deriveViewTag(sharedSecret);
|
|
@@ -1453,7 +1482,7 @@ var EncryptedMemo = {
|
|
|
1453
1482
|
const ephPkPoint = (0, import_baby_jubjub.unpackPoint)(ephPkPackedBigint);
|
|
1454
1483
|
if (!ephPkPoint) return null;
|
|
1455
1484
|
const ivskScalar = bytesToBjjScalar(viewingSecretKey);
|
|
1456
|
-
const sharedPoint = (
|
|
1485
|
+
const sharedPoint = fastMulPoint(ephPkPoint, ivskScalar);
|
|
1457
1486
|
return bigintTo32Le(sharedPoint[0]);
|
|
1458
1487
|
},
|
|
1459
1488
|
/**
|
|
@@ -3834,7 +3863,8 @@ var NoteBuilder = class {
|
|
|
3834
3863
|
commitmentBytes,
|
|
3835
3864
|
input.viewingPublicKey,
|
|
3836
3865
|
bigintTo32Le(counterpartyPk),
|
|
3837
|
-
circuitVersion
|
|
3866
|
+
circuitVersion,
|
|
3867
|
+
input.ephSkOverride
|
|
3838
3868
|
)
|
|
3839
3869
|
) : Array.from(EncryptedMemo.dummy());
|
|
3840
3870
|
if (memo.length !== ENCRYPTED_MEMO_SIZE)
|
|
@@ -3884,11 +3914,44 @@ var NoteBuilder = class {
|
|
|
3884
3914
|
}
|
|
3885
3915
|
};
|
|
3886
3916
|
|
|
3917
|
+
// src/shielded-pool/protocol/selfEph.ts
|
|
3918
|
+
var import_sha23 = require("@noble/hashes/sha2.js");
|
|
3919
|
+
var import_baby_jubjub5 = require("@zk-kit/baby-jubjub");
|
|
3920
|
+
var SELF_EPH_DOMAIN = new TextEncoder().encode("orbinum-self-eph-v1");
|
|
3921
|
+
function deriveSelfEphSk(spendingKey, index) {
|
|
3922
|
+
const h = import_sha23.sha256.create();
|
|
3923
|
+
h.update(SELF_EPH_DOMAIN);
|
|
3924
|
+
h.update(bigintTo32Le(spendingKey));
|
|
3925
|
+
const idx = new Uint8Array(4);
|
|
3926
|
+
new DataView(idx.buffer).setUint32(0, index >>> 0, true);
|
|
3927
|
+
h.update(idx);
|
|
3928
|
+
return h.digest();
|
|
3929
|
+
}
|
|
3930
|
+
function selfEphWindow(spendingKey, ivkPacked, from, count) {
|
|
3931
|
+
const ivkPoint = (0, import_baby_jubjub5.unpackPoint)(bytesToBigintLE(ivkPacked));
|
|
3932
|
+
if (!ivkPoint) throw new Error("selfEphWindow: invalid viewing public key");
|
|
3933
|
+
const entries = [];
|
|
3934
|
+
for (let i = from; i < from + count; i++) {
|
|
3935
|
+
const scalar = bytesToBjjScalar(deriveSelfEphSk(spendingKey, i));
|
|
3936
|
+
const ephPk = fastMulBase(scalar);
|
|
3937
|
+
const sharedPoint = fastMulPoint(ivkPoint, scalar);
|
|
3938
|
+
entries.push({
|
|
3939
|
+
index: i,
|
|
3940
|
+
ephPkHex: toHex(bigintTo32Le((0, import_baby_jubjub5.packPoint)(ephPk))),
|
|
3941
|
+
sharedSecret: bigintTo32Le(sharedPoint[0])
|
|
3942
|
+
});
|
|
3943
|
+
}
|
|
3944
|
+
return entries;
|
|
3945
|
+
}
|
|
3946
|
+
|
|
3887
3947
|
// src/shielded-pool/protocol/NoteDecryptor.ts
|
|
3888
3948
|
var import_poseidon_lite2 = require("poseidon-lite");
|
|
3889
3949
|
function computeNullifier(commitment, spendingKey) {
|
|
3890
3950
|
return (0, import_poseidon_lite2.poseidon2)([commitment, spendingKey]);
|
|
3891
3951
|
}
|
|
3952
|
+
function computeNoteCommitment(value, assetId, ownerPk, blinding) {
|
|
3953
|
+
return (0, import_poseidon_lite2.poseidon4)([value, assetId, ownerPk, blinding]);
|
|
3954
|
+
}
|
|
3892
3955
|
function tryDecryptNote(commitment, viewingSecretKey, spendingKey, ownOwnerPk = 0n, opts) {
|
|
3893
3956
|
return tryDecryptNoteVerbose(commitment, viewingSecretKey, spendingKey, ownOwnerPk, opts).note;
|
|
3894
3957
|
}
|
|
@@ -3908,8 +3971,8 @@ function tryDecryptNoteVerbose(commitment, viewingSecretKey, spendingKey, ownOwn
|
|
|
3908
3971
|
reason: `memo_size_mismatch:got_${memoBytes.length}_expected_${ENCRYPTED_MEMO_SIZE}`
|
|
3909
3972
|
};
|
|
3910
3973
|
}
|
|
3911
|
-
let sharedSecret = null;
|
|
3912
|
-
if (opts?.viewTag) {
|
|
3974
|
+
let sharedSecret = opts?.sharedSecret ?? null;
|
|
3975
|
+
if (!sharedSecret && opts?.viewTag) {
|
|
3913
3976
|
sharedSecret = EncryptedMemo.extractSharedSecret(memoBytes, viewingSecretKey);
|
|
3914
3977
|
if (!sharedSecret) return { note: null, reason: "stealth_shared_secret_failed" };
|
|
3915
3978
|
if (!EncryptedMemo.checkViewTag(memoBytes, sharedSecret)) {
|
|
@@ -4058,8 +4121,8 @@ function randomBlinding() {
|
|
|
4058
4121
|
|
|
4059
4122
|
// src/privacy-keys/PrivacyKeys.ts
|
|
4060
4123
|
var import_hkdf2 = require("@noble/hashes/hkdf.js");
|
|
4061
|
-
var
|
|
4062
|
-
var
|
|
4124
|
+
var import_sha24 = require("@noble/hashes/sha2.js");
|
|
4125
|
+
var import_baby_jubjub6 = require("@zk-kit/baby-jubjub");
|
|
4063
4126
|
var IVK_DOMAIN = new TextEncoder().encode("orbinum-ivk-v1");
|
|
4064
4127
|
function deriveSpendingKeyMessage(chainId, address) {
|
|
4065
4128
|
return `orbinum-spending-key-v1
|
|
@@ -4069,7 +4132,7 @@ ${address.toLowerCase()}`;
|
|
|
4069
4132
|
async function deriveMasterKeyBytes(signatureHex, chainId, address) {
|
|
4070
4133
|
const sigBytes = fromHex(signatureHex);
|
|
4071
4134
|
const info = new TextEncoder().encode(`orbinum-sk-v1:${chainId}:${address.toLowerCase()}`);
|
|
4072
|
-
return (0, import_hkdf2.hkdf)(
|
|
4135
|
+
return (0, import_hkdf2.hkdf)(import_sha24.sha256, sigBytes, new Uint8Array(0), info, 32);
|
|
4073
4136
|
}
|
|
4074
4137
|
async function deriveSpendingKeyFromSignature(signatureHex, chainId, address) {
|
|
4075
4138
|
const masterBytes = await deriveMasterKeyBytes(signatureHex, chainId, address);
|
|
@@ -4078,17 +4141,17 @@ async function deriveSpendingKeyFromSignature(signatureHex, chainId, address) {
|
|
|
4078
4141
|
}
|
|
4079
4142
|
function deriveViewingSecretKey(spendingKey) {
|
|
4080
4143
|
const ikm = bigintTo32Le(spendingKey);
|
|
4081
|
-
return (0, import_hkdf2.hkdf)(
|
|
4144
|
+
return (0, import_hkdf2.hkdf)(import_sha24.sha256, ikm, void 0, IVK_DOMAIN, 32);
|
|
4082
4145
|
}
|
|
4083
4146
|
function deriveViewingPublicKey(ivsk) {
|
|
4084
4147
|
const ivskScalar = BigInt(toHex(ivsk)) % BABYJUB_SUBORDER || 1n;
|
|
4085
|
-
const ivkPoint = (0,
|
|
4086
|
-
const packed = (0,
|
|
4148
|
+
const ivkPoint = (0, import_baby_jubjub6.mulPointEscalar)(import_baby_jubjub6.Base8, ivskScalar);
|
|
4149
|
+
const packed = (0, import_baby_jubjub6.packPoint)(ivkPoint);
|
|
4087
4150
|
return bigintTo32Le(packed);
|
|
4088
4151
|
}
|
|
4089
4152
|
function deriveOwnerPk(spendingKey) {
|
|
4090
4153
|
try {
|
|
4091
|
-
const pubPoint = (0,
|
|
4154
|
+
const pubPoint = (0, import_baby_jubjub6.mulPointEscalar)(import_baby_jubjub6.Base8, spendingKey);
|
|
4092
4155
|
return pubPoint[0];
|
|
4093
4156
|
} catch {
|
|
4094
4157
|
return 0n;
|
|
@@ -4397,7 +4460,7 @@ async function noteBlindTag(blindKey, hex) {
|
|
|
4397
4460
|
// src/proof-generator/unshield.ts
|
|
4398
4461
|
var import_proof_generator2 = require("@orbinum/proof-generator");
|
|
4399
4462
|
var import_utils3 = require("@noble/ciphers/utils.js");
|
|
4400
|
-
var
|
|
4463
|
+
var import_baby_jubjub7 = require("@zk-kit/baby-jubjub");
|
|
4401
4464
|
var import_poseidon_lite4 = require("poseidon-lite");
|
|
4402
4465
|
|
|
4403
4466
|
// src/proof-generator/merkle.ts
|
|
@@ -4420,7 +4483,7 @@ async function generateUnshieldProof(inputs, options = {}) {
|
|
|
4420
4483
|
if (changeValue < 0n) {
|
|
4421
4484
|
throw new Error("changeValue must be >= 0.");
|
|
4422
4485
|
}
|
|
4423
|
-
const changeOwnerPubkey = inputs.changeOwnerPubkey ?? (0,
|
|
4486
|
+
const changeOwnerPubkey = inputs.changeOwnerPubkey ?? (0, import_baby_jubjub7.mulPointEscalar)(import_baby_jubjub7.Base8, inputs.spendingKey)[0];
|
|
4424
4487
|
const changeBlinding = inputs.changeBlinding ?? (changeValue > 0n ? bytesToBigintLE((0, import_utils3.randomBytes)(32)) : 0n);
|
|
4425
4488
|
const changeCommitment = changeValue > 0n ? (0, import_poseidon_lite4.poseidon4)([changeValue, inputs.assetId, changeOwnerPubkey, changeBlinding]) : 0n;
|
|
4426
4489
|
const circuitInputs = {
|
|
@@ -5315,6 +5378,7 @@ var import_polkadot_api4 = require("polkadot-api");
|
|
|
5315
5378
|
blindTag,
|
|
5316
5379
|
buildDummyTransferInput,
|
|
5317
5380
|
bytesToBigintLE,
|
|
5381
|
+
computeNoteCommitment,
|
|
5318
5382
|
computeNullifier,
|
|
5319
5383
|
computePathIndices,
|
|
5320
5384
|
connectInjectedExtension,
|
|
@@ -5325,6 +5389,7 @@ var import_polkadot_api4 = require("polkadot-api");
|
|
|
5325
5389
|
decryptNoteRecord,
|
|
5326
5390
|
deriveMasterKeyBytes,
|
|
5327
5391
|
deriveOwnerPk,
|
|
5392
|
+
deriveSelfEphSk,
|
|
5328
5393
|
deriveSpendingKeyFromSignature,
|
|
5329
5394
|
deriveSpendingKeyMessage,
|
|
5330
5395
|
deriveStealthOwnerPk,
|
|
@@ -5369,6 +5434,7 @@ var import_polkadot_api4 = require("polkadot-api");
|
|
|
5369
5434
|
randomBlinding,
|
|
5370
5435
|
recoverOwnerPkPoint,
|
|
5371
5436
|
selectNotes,
|
|
5437
|
+
selfEphWindow,
|
|
5372
5438
|
shortHash,
|
|
5373
5439
|
substrateSs58ToAccountIdHex,
|
|
5374
5440
|
substrateToEvm,
|
package/dist/index.mjs
CHANGED
|
@@ -1074,7 +1074,33 @@ function resolveTx(unsafe, pallet, call) {
|
|
|
1074
1074
|
// src/shielded-pool/protocol/EncryptedMemo.ts
|
|
1075
1075
|
import { chacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
1076
1076
|
import { randomBytes } from "@noble/ciphers/utils.js";
|
|
1077
|
-
import {
|
|
1077
|
+
import { packPoint, unpackPoint } from "@zk-kit/baby-jubjub";
|
|
1078
|
+
|
|
1079
|
+
// src/utils/bjj-fast.ts
|
|
1080
|
+
import { edwards } from "@noble/curves/abstract/edwards.js";
|
|
1081
|
+
var P = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
1082
|
+
var N = 2736030358979909402780800718157159386076813972158567259200215660948447373041n;
|
|
1083
|
+
var BjjPoint = edwards({
|
|
1084
|
+
p: P,
|
|
1085
|
+
n: N,
|
|
1086
|
+
h: 8n,
|
|
1087
|
+
a: 168700n,
|
|
1088
|
+
d: 168696n,
|
|
1089
|
+
Gx: 5299619240641551281634865583518297030282874472190772894086521144482721001553n,
|
|
1090
|
+
Gy: 16950150798460657717958625567821834550301663161624707787222815936182638968203n
|
|
1091
|
+
});
|
|
1092
|
+
function fastMulBase(scalar) {
|
|
1093
|
+
const s = scalar % N;
|
|
1094
|
+
if (s === 0n) return [0n, 1n];
|
|
1095
|
+
const { x, y } = BjjPoint.BASE.multiply(s).toAffine();
|
|
1096
|
+
return [x, y];
|
|
1097
|
+
}
|
|
1098
|
+
function fastMulPoint(point, scalar) {
|
|
1099
|
+
const s = scalar % N;
|
|
1100
|
+
if (s === 0n) return [0n, 1n];
|
|
1101
|
+
const { x, y } = BjjPoint.fromAffine({ x: point[0], y: point[1] }).multiplyUnsafe(s).toAffine();
|
|
1102
|
+
return [x, y];
|
|
1103
|
+
}
|
|
1078
1104
|
|
|
1079
1105
|
// src/utils/bytes.ts
|
|
1080
1106
|
function bigintTo32Le(n) {
|
|
@@ -1225,13 +1251,13 @@ var EncryptedMemo = {
|
|
|
1225
1251
|
if (ephSkBytes.length !== 32)
|
|
1226
1252
|
throw new Error("EncryptedMemo.encrypt: ephSkOverride must be 32 bytes");
|
|
1227
1253
|
const ephSkScalar = bytesToBjjScalar(ephSkBytes);
|
|
1228
|
-
const ephPkPoint =
|
|
1254
|
+
const ephPkPoint = fastMulBase(ephSkScalar);
|
|
1229
1255
|
ephPkPackedBytes = bigintTo32Le(packPoint(ephPkPoint));
|
|
1230
1256
|
const ivkPackedBigint = bytesToBigintLE(recipientIvkPacked);
|
|
1231
1257
|
const ivkPoint = unpackPoint(ivkPackedBigint);
|
|
1232
1258
|
if (!ivkPoint)
|
|
1233
1259
|
throw new Error("EncryptedMemo.encrypt: invalid recipient viewing public key");
|
|
1234
|
-
const sharedPoint =
|
|
1260
|
+
const sharedPoint = fastMulPoint(ivkPoint, ephSkScalar);
|
|
1235
1261
|
sharedSecret = bigintTo32Le(sharedPoint[0]);
|
|
1236
1262
|
}
|
|
1237
1263
|
nonce[0] = deriveViewTag(sharedSecret);
|
|
@@ -1321,7 +1347,7 @@ var EncryptedMemo = {
|
|
|
1321
1347
|
const ephPkPoint = unpackPoint(ephPkPackedBigint);
|
|
1322
1348
|
if (!ephPkPoint) return null;
|
|
1323
1349
|
const ivskScalar = bytesToBjjScalar(viewingSecretKey);
|
|
1324
|
-
const sharedPoint =
|
|
1350
|
+
const sharedPoint = fastMulPoint(ephPkPoint, ivskScalar);
|
|
1325
1351
|
return bigintTo32Le(sharedPoint[0]);
|
|
1326
1352
|
},
|
|
1327
1353
|
/**
|
|
@@ -3523,7 +3549,7 @@ var CURRENT_CIRCUIT_VERSION = 1;
|
|
|
3523
3549
|
// src/utils/stealth.ts
|
|
3524
3550
|
import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
|
|
3525
3551
|
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
3526
|
-
import { mulPointEscalar
|
|
3552
|
+
import { mulPointEscalar, Base8, addPoint } from "@zk-kit/baby-jubjub";
|
|
3527
3553
|
var STEALTH_INFO = new TextEncoder().encode("orbinum-stealth-v1");
|
|
3528
3554
|
function deriveStealthScalar(sharedSecret, ownerPkBigint) {
|
|
3529
3555
|
const salt = bigintTo32Le(ownerPkBigint);
|
|
@@ -3532,7 +3558,7 @@ function deriveStealthScalar(sharedSecret, ownerPkBigint) {
|
|
|
3532
3558
|
}
|
|
3533
3559
|
function deriveStealthOwnerPk(sharedSecret, ownerPkBigint, ownerPkPoint) {
|
|
3534
3560
|
const stealthScalar = deriveStealthScalar(sharedSecret, ownerPkBigint);
|
|
3535
|
-
const stealthPt = addPoint(
|
|
3561
|
+
const stealthPt = addPoint(mulPointEscalar(Base8, stealthScalar), ownerPkPoint);
|
|
3536
3562
|
return stealthPt[0];
|
|
3537
3563
|
}
|
|
3538
3564
|
function deriveStealthSk(sharedSecret, ownerPkBigint, spendingKey) {
|
|
@@ -3541,7 +3567,7 @@ function deriveStealthSk(sharedSecret, ownerPkBigint, spendingKey) {
|
|
|
3541
3567
|
}
|
|
3542
3568
|
|
|
3543
3569
|
// src/utils/bjj.ts
|
|
3544
|
-
import { mulPointEscalar as
|
|
3570
|
+
import { mulPointEscalar as mulPointEscalar2 } from "@zk-kit/baby-jubjub";
|
|
3545
3571
|
var BJJ_A = 168700n;
|
|
3546
3572
|
var BJJ_D = 168696n;
|
|
3547
3573
|
function _modpow(base, exp, mod) {
|
|
@@ -3596,7 +3622,7 @@ function recoverOwnerPkPoint(ax) {
|
|
|
3596
3622
|
if (y === null) return null;
|
|
3597
3623
|
const yAlt = BN254_R - y;
|
|
3598
3624
|
try {
|
|
3599
|
-
const check =
|
|
3625
|
+
const check = mulPointEscalar2([ax, y], BABYJUB_SUBORDER);
|
|
3600
3626
|
return check[0] === 0n && check[1] === 1n ? [ax, y] : [ax, yAlt];
|
|
3601
3627
|
} catch {
|
|
3602
3628
|
return [ax, yAlt];
|
|
@@ -3604,7 +3630,7 @@ function recoverOwnerPkPoint(ax) {
|
|
|
3604
3630
|
}
|
|
3605
3631
|
|
|
3606
3632
|
// src/shielded-pool/protocol/NoteBuilder.ts
|
|
3607
|
-
import { mulPointEscalar as
|
|
3633
|
+
import { mulPointEscalar as mulPointEscalar3, unpackPoint as unpackPoint2 } from "@zk-kit/baby-jubjub";
|
|
3608
3634
|
import { randomBytes as randomBytes2 } from "@noble/ciphers/utils.js";
|
|
3609
3635
|
import { poseidon2, poseidon4 } from "poseidon-lite";
|
|
3610
3636
|
var NoteBuilder = class {
|
|
@@ -3640,7 +3666,7 @@ var NoteBuilder = class {
|
|
|
3640
3666
|
if (!ivkPoint)
|
|
3641
3667
|
throw new Error("NoteBuilder.build: invalid recipient viewing public key");
|
|
3642
3668
|
const ephSkScalar = BigInt(toHex(ephSk)) % BABYJUB_SUBORDER || 1n;
|
|
3643
|
-
const sharedPoint =
|
|
3669
|
+
const sharedPoint = mulPointEscalar3(ivkPoint, ephSkScalar);
|
|
3644
3670
|
const sharedSecret = bigintTo32Le(sharedPoint[0]);
|
|
3645
3671
|
const recipientPkPoint = recoverOwnerPkPoint(recipientOwnerPk);
|
|
3646
3672
|
if (!recipientPkPoint)
|
|
@@ -3705,7 +3731,8 @@ var NoteBuilder = class {
|
|
|
3705
3731
|
commitmentBytes,
|
|
3706
3732
|
input.viewingPublicKey,
|
|
3707
3733
|
bigintTo32Le(counterpartyPk),
|
|
3708
|
-
circuitVersion
|
|
3734
|
+
circuitVersion,
|
|
3735
|
+
input.ephSkOverride
|
|
3709
3736
|
)
|
|
3710
3737
|
) : Array.from(EncryptedMemo.dummy());
|
|
3711
3738
|
if (memo.length !== ENCRYPTED_MEMO_SIZE)
|
|
@@ -3755,11 +3782,44 @@ var NoteBuilder = class {
|
|
|
3755
3782
|
}
|
|
3756
3783
|
};
|
|
3757
3784
|
|
|
3785
|
+
// src/shielded-pool/protocol/selfEph.ts
|
|
3786
|
+
import { sha256 as sha2563 } from "@noble/hashes/sha2.js";
|
|
3787
|
+
import { packPoint as packPoint2, unpackPoint as unpackPoint3 } from "@zk-kit/baby-jubjub";
|
|
3788
|
+
var SELF_EPH_DOMAIN = new TextEncoder().encode("orbinum-self-eph-v1");
|
|
3789
|
+
function deriveSelfEphSk(spendingKey, index) {
|
|
3790
|
+
const h = sha2563.create();
|
|
3791
|
+
h.update(SELF_EPH_DOMAIN);
|
|
3792
|
+
h.update(bigintTo32Le(spendingKey));
|
|
3793
|
+
const idx = new Uint8Array(4);
|
|
3794
|
+
new DataView(idx.buffer).setUint32(0, index >>> 0, true);
|
|
3795
|
+
h.update(idx);
|
|
3796
|
+
return h.digest();
|
|
3797
|
+
}
|
|
3798
|
+
function selfEphWindow(spendingKey, ivkPacked, from, count) {
|
|
3799
|
+
const ivkPoint = unpackPoint3(bytesToBigintLE(ivkPacked));
|
|
3800
|
+
if (!ivkPoint) throw new Error("selfEphWindow: invalid viewing public key");
|
|
3801
|
+
const entries = [];
|
|
3802
|
+
for (let i = from; i < from + count; i++) {
|
|
3803
|
+
const scalar = bytesToBjjScalar(deriveSelfEphSk(spendingKey, i));
|
|
3804
|
+
const ephPk = fastMulBase(scalar);
|
|
3805
|
+
const sharedPoint = fastMulPoint(ivkPoint, scalar);
|
|
3806
|
+
entries.push({
|
|
3807
|
+
index: i,
|
|
3808
|
+
ephPkHex: toHex(bigintTo32Le(packPoint2(ephPk))),
|
|
3809
|
+
sharedSecret: bigintTo32Le(sharedPoint[0])
|
|
3810
|
+
});
|
|
3811
|
+
}
|
|
3812
|
+
return entries;
|
|
3813
|
+
}
|
|
3814
|
+
|
|
3758
3815
|
// src/shielded-pool/protocol/NoteDecryptor.ts
|
|
3759
3816
|
import { poseidon2 as poseidon22, poseidon4 as poseidon42 } from "poseidon-lite";
|
|
3760
3817
|
function computeNullifier(commitment, spendingKey) {
|
|
3761
3818
|
return poseidon22([commitment, spendingKey]);
|
|
3762
3819
|
}
|
|
3820
|
+
function computeNoteCommitment(value, assetId, ownerPk, blinding) {
|
|
3821
|
+
return poseidon42([value, assetId, ownerPk, blinding]);
|
|
3822
|
+
}
|
|
3763
3823
|
function tryDecryptNote(commitment, viewingSecretKey, spendingKey, ownOwnerPk = 0n, opts) {
|
|
3764
3824
|
return tryDecryptNoteVerbose(commitment, viewingSecretKey, spendingKey, ownOwnerPk, opts).note;
|
|
3765
3825
|
}
|
|
@@ -3779,8 +3839,8 @@ function tryDecryptNoteVerbose(commitment, viewingSecretKey, spendingKey, ownOwn
|
|
|
3779
3839
|
reason: `memo_size_mismatch:got_${memoBytes.length}_expected_${ENCRYPTED_MEMO_SIZE}`
|
|
3780
3840
|
};
|
|
3781
3841
|
}
|
|
3782
|
-
let sharedSecret = null;
|
|
3783
|
-
if (opts?.viewTag) {
|
|
3842
|
+
let sharedSecret = opts?.sharedSecret ?? null;
|
|
3843
|
+
if (!sharedSecret && opts?.viewTag) {
|
|
3784
3844
|
sharedSecret = EncryptedMemo.extractSharedSecret(memoBytes, viewingSecretKey);
|
|
3785
3845
|
if (!sharedSecret) return { note: null, reason: "stealth_shared_secret_failed" };
|
|
3786
3846
|
if (!EncryptedMemo.checkViewTag(memoBytes, sharedSecret)) {
|
|
@@ -3929,8 +3989,8 @@ function randomBlinding() {
|
|
|
3929
3989
|
|
|
3930
3990
|
// src/privacy-keys/PrivacyKeys.ts
|
|
3931
3991
|
import { hkdf as hkdf2 } from "@noble/hashes/hkdf.js";
|
|
3932
|
-
import { sha256 as
|
|
3933
|
-
import { mulPointEscalar as
|
|
3992
|
+
import { sha256 as sha2564 } from "@noble/hashes/sha2.js";
|
|
3993
|
+
import { mulPointEscalar as mulPointEscalar4, Base8 as Base82, packPoint as packPoint3 } from "@zk-kit/baby-jubjub";
|
|
3934
3994
|
var IVK_DOMAIN = new TextEncoder().encode("orbinum-ivk-v1");
|
|
3935
3995
|
function deriveSpendingKeyMessage(chainId, address) {
|
|
3936
3996
|
return `orbinum-spending-key-v1
|
|
@@ -3940,7 +4000,7 @@ ${address.toLowerCase()}`;
|
|
|
3940
4000
|
async function deriveMasterKeyBytes(signatureHex, chainId, address) {
|
|
3941
4001
|
const sigBytes = fromHex(signatureHex);
|
|
3942
4002
|
const info = new TextEncoder().encode(`orbinum-sk-v1:${chainId}:${address.toLowerCase()}`);
|
|
3943
|
-
return hkdf2(
|
|
4003
|
+
return hkdf2(sha2564, sigBytes, new Uint8Array(0), info, 32);
|
|
3944
4004
|
}
|
|
3945
4005
|
async function deriveSpendingKeyFromSignature(signatureHex, chainId, address) {
|
|
3946
4006
|
const masterBytes = await deriveMasterKeyBytes(signatureHex, chainId, address);
|
|
@@ -3949,17 +4009,17 @@ async function deriveSpendingKeyFromSignature(signatureHex, chainId, address) {
|
|
|
3949
4009
|
}
|
|
3950
4010
|
function deriveViewingSecretKey(spendingKey) {
|
|
3951
4011
|
const ikm = bigintTo32Le(spendingKey);
|
|
3952
|
-
return hkdf2(
|
|
4012
|
+
return hkdf2(sha2564, ikm, void 0, IVK_DOMAIN, 32);
|
|
3953
4013
|
}
|
|
3954
4014
|
function deriveViewingPublicKey(ivsk) {
|
|
3955
4015
|
const ivskScalar = BigInt(toHex(ivsk)) % BABYJUB_SUBORDER || 1n;
|
|
3956
|
-
const ivkPoint =
|
|
3957
|
-
const packed =
|
|
4016
|
+
const ivkPoint = mulPointEscalar4(Base82, ivskScalar);
|
|
4017
|
+
const packed = packPoint3(ivkPoint);
|
|
3958
4018
|
return bigintTo32Le(packed);
|
|
3959
4019
|
}
|
|
3960
4020
|
function deriveOwnerPk(spendingKey) {
|
|
3961
4021
|
try {
|
|
3962
|
-
const pubPoint =
|
|
4022
|
+
const pubPoint = mulPointEscalar4(Base82, spendingKey);
|
|
3963
4023
|
return pubPoint[0];
|
|
3964
4024
|
} catch {
|
|
3965
4025
|
return 0n;
|
|
@@ -4272,7 +4332,7 @@ import {
|
|
|
4272
4332
|
WebArtifactProvider as WebArtifactProvider2
|
|
4273
4333
|
} from "@orbinum/proof-generator";
|
|
4274
4334
|
import { randomBytes as randomBytes3 } from "@noble/ciphers/utils.js";
|
|
4275
|
-
import { mulPointEscalar as
|
|
4335
|
+
import { mulPointEscalar as mulPointEscalar5, Base8 as Base83 } from "@zk-kit/baby-jubjub";
|
|
4276
4336
|
import { poseidon4 as poseidon44 } from "poseidon-lite";
|
|
4277
4337
|
|
|
4278
4338
|
// src/proof-generator/merkle.ts
|
|
@@ -4295,7 +4355,7 @@ async function generateUnshieldProof(inputs, options = {}) {
|
|
|
4295
4355
|
if (changeValue < 0n) {
|
|
4296
4356
|
throw new Error("changeValue must be >= 0.");
|
|
4297
4357
|
}
|
|
4298
|
-
const changeOwnerPubkey = inputs.changeOwnerPubkey ??
|
|
4358
|
+
const changeOwnerPubkey = inputs.changeOwnerPubkey ?? mulPointEscalar5(Base83, inputs.spendingKey)[0];
|
|
4299
4359
|
const changeBlinding = inputs.changeBlinding ?? (changeValue > 0n ? bytesToBigintLE(randomBytes3(32)) : 0n);
|
|
4300
4360
|
const changeCommitment = changeValue > 0n ? poseidon44([changeValue, inputs.assetId, changeOwnerPubkey, changeBlinding]) : 0n;
|
|
4301
4361
|
const circuitInputs = {
|
|
@@ -5208,6 +5268,7 @@ export {
|
|
|
5208
5268
|
blindTag,
|
|
5209
5269
|
buildDummyTransferInput,
|
|
5210
5270
|
bytesToBigintLE,
|
|
5271
|
+
computeNoteCommitment,
|
|
5211
5272
|
computeNullifier,
|
|
5212
5273
|
computePathIndices,
|
|
5213
5274
|
connectInjectedExtension,
|
|
@@ -5218,6 +5279,7 @@ export {
|
|
|
5218
5279
|
decryptNoteRecord,
|
|
5219
5280
|
deriveMasterKeyBytes,
|
|
5220
5281
|
deriveOwnerPk,
|
|
5282
|
+
deriveSelfEphSk,
|
|
5221
5283
|
deriveSpendingKeyFromSignature,
|
|
5222
5284
|
deriveSpendingKeyMessage,
|
|
5223
5285
|
deriveStealthOwnerPk,
|
|
@@ -5262,6 +5324,7 @@ export {
|
|
|
5262
5324
|
randomBlinding,
|
|
5263
5325
|
recoverOwnerPkPoint,
|
|
5264
5326
|
selectNotes,
|
|
5327
|
+
selfEphWindow,
|
|
5265
5328
|
shortHash,
|
|
5266
5329
|
substrateSs58ToAccountIdHex,
|
|
5267
5330
|
substrateToEvm,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orbinum/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Official TypeScript SDK for Orbinum.",
|
|
5
5
|
"author": "Orbinum",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@noble/ciphers": "2.2.0",
|
|
49
|
+
"@noble/curves": "^2.2.0",
|
|
49
50
|
"@noble/hashes": "2.2.0",
|
|
50
51
|
"@orbinum/proof-generator": "4.0.0",
|
|
51
52
|
"@polkadot-api/metadata-builders": "0.14.2",
|