@orbinum/sdk 1.4.0 → 2.0.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/{chunk-A2ZRMEYW.mjs → chunk-VYKKBXOE.mjs} +51 -28
- package/dist/{index-V5Z9igEN.d.mts → index-CLpM1984.d.mts} +42 -9
- package/dist/{index-V5Z9igEN.d.ts → index-CLpM1984.d.ts} +42 -9
- package/dist/index.d.mts +372 -103
- package/dist/index.d.ts +372 -103
- package/dist/index.js +546 -319
- package/dist/index.mjs +438 -238
- package/dist/wallet/worker/index.d.mts +1 -1
- package/dist/wallet/worker/index.d.ts +1 -1
- package/dist/wallet/worker/index.js +18 -11
- package/dist/wallet/worker/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { d as DECRYPT_YIELD_EVERY, e as DecryptBatchResult, b as DecryptPool, f as DecryptRequest, E as EMPTY_BATCH_RESULT, K as KnownEphEntry, g as KnownEphWindow, M as MAX_WORKERS, h as MatchSource, P as PAIRWISE_EPH_WINDOW, j as SELF_EPH_WINDOW, c as ScanKeys, W as WORKER_CRASHED, k as WorkerFactory, l as WorkerLike, m as WorkerMessage, n as clearKnownEphWindow, o as createDecryptPool, p as createMainThreadPool, q as createWorkerPool, r as decryptHintBatch, s as getKnownEphWindow } from '../../index-CLpM1984.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { d as DECRYPT_YIELD_EVERY, e as DecryptBatchResult, b as DecryptPool, f as DecryptRequest, E as EMPTY_BATCH_RESULT, K as KnownEphEntry, g as KnownEphWindow, M as MAX_WORKERS, h as MatchSource, P as PAIRWISE_EPH_WINDOW, j as SELF_EPH_WINDOW, c as ScanKeys, W as WORKER_CRASHED, k as WorkerFactory, l as WorkerLike, m as WorkerMessage, n as clearKnownEphWindow, o as createDecryptPool, p as createMainThreadPool, q as createWorkerPool, r as decryptHintBatch, s as getKnownEphWindow } from '../../index-CLpM1984.js';
|
|
@@ -75,17 +75,24 @@ function fromHex(hex) {
|
|
|
75
75
|
if (clean.length % 2 !== 0) {
|
|
76
76
|
throw new Error(`Invalid hex string \u2014 odd length: "${hex}"`);
|
|
77
77
|
}
|
|
78
|
+
if (!/^[0-9a-fA-F]*$/.test(clean)) {
|
|
79
|
+
throw new Error("Invalid hex string \u2014 non-hex characters");
|
|
80
|
+
}
|
|
78
81
|
const bytes = new Uint8Array(clean.length / 2);
|
|
79
82
|
for (let i = 0; i < bytes.length; i++) {
|
|
80
|
-
|
|
81
|
-
if (isNaN(byte)) throw new Error(`Invalid hex character at position ${i * 2}`);
|
|
82
|
-
bytes[i] = byte;
|
|
83
|
+
bytes[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
|
|
83
84
|
}
|
|
84
85
|
return bytes;
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
// src/foundation/encoding/bytes.ts
|
|
89
|
+
function assert32ByteRange(n, fn) {
|
|
90
|
+
if (n < 0n || n >= 1n << 256n) {
|
|
91
|
+
throw new Error(`${fn}: value does not fit in 32 bytes: ${n}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
88
94
|
function bigintTo32Le(n) {
|
|
95
|
+
assert32ByteRange(n, "bigintTo32Le");
|
|
89
96
|
const buf = new Uint8Array(32);
|
|
90
97
|
let v = n;
|
|
91
98
|
for (let i = 0; i < 32; i++) {
|
|
@@ -111,7 +118,7 @@ var import_sha2 = require("@noble/hashes/sha2.js");
|
|
|
111
118
|
var KEY_DOMAIN = new TextEncoder().encode("orbinum-note-encryption-v1");
|
|
112
119
|
var VIEW_TAG_DOMAIN = new TextEncoder().encode("orbinum-view-tag-v1");
|
|
113
120
|
var MEMO_PLAINTEXT_SIZE = 120;
|
|
114
|
-
function serializeMemo(value, ownerPk, blinding, assetId,
|
|
121
|
+
function serializeMemo(value, ownerPk, blinding, assetId, sourcePk, circuitVersion) {
|
|
115
122
|
const buf = new Uint8Array(MEMO_PLAINTEXT_SIZE);
|
|
116
123
|
const view = new DataView(buf.buffer);
|
|
117
124
|
view.setBigUint64(0, value & 0xffffffffffffffffn, true);
|
|
@@ -119,7 +126,7 @@ function serializeMemo(value, ownerPk, blinding, assetId, counterpartyPk, circui
|
|
|
119
126
|
buf.set(ownerPk.slice(0, 32), 16);
|
|
120
127
|
buf.set(blinding.slice(0, 32), 48);
|
|
121
128
|
view.setUint32(80, assetId >>> 0, true);
|
|
122
|
-
buf.set(
|
|
129
|
+
buf.set(sourcePk.slice(0, 32), 84);
|
|
123
130
|
view.setUint32(116, circuitVersion >>> 0, true);
|
|
124
131
|
return buf;
|
|
125
132
|
}
|
|
@@ -157,9 +164,9 @@ function parsePlaintext(nonce, ciphertextWithMac, encKey) {
|
|
|
157
164
|
const ownerPk = bytesToBigintLE(plaintext.slice(16, 48));
|
|
158
165
|
const blinding = bytesToBigintLE(plaintext.slice(48, 80));
|
|
159
166
|
const assetId = BigInt(view.getUint32(80, true));
|
|
160
|
-
const
|
|
167
|
+
const sourcePk = bytesToBigintLE(plaintext.slice(84, 116));
|
|
161
168
|
const circuitVersion = view.getUint32(116, true);
|
|
162
|
-
return { value, ownerPk, blinding, assetId,
|
|
169
|
+
return { value, ownerPk, blinding, assetId, sourcePk, circuitVersion };
|
|
163
170
|
} catch {
|
|
164
171
|
return null;
|
|
165
172
|
}
|
|
@@ -177,19 +184,19 @@ var EncryptedMemo = {
|
|
|
177
184
|
* (from PrivacyKeyManager.getViewingPublicKeyPacked() or
|
|
178
185
|
* decoded from a privacy address).
|
|
179
186
|
* Pass `new Uint8Array(32)` (all zeros) for a publicly-readable memo.
|
|
180
|
-
* @param
|
|
187
|
+
* @param sourcePk 32-byte counterparty BJJ Ax. Default: all zeros.
|
|
181
188
|
* @param circuitVersion ZK circuit version the note is spent under. Default: 0.
|
|
182
189
|
* @param ephSkOverride 32-byte ephemeral secret key (stealth coordination). Optional.
|
|
183
190
|
* @returns 180-byte encrypted memo: nonce(12) || ciphertext+MAC(136) || ephPk(32).
|
|
184
191
|
*/
|
|
185
|
-
encrypt(value, ownerPk, blinding, assetId, commitment, recipientIvkPacked,
|
|
192
|
+
encrypt(value, ownerPk, blinding, assetId, commitment, recipientIvkPacked, sourcePk = new Uint8Array(32), circuitVersion = 0, ephSkOverride) {
|
|
186
193
|
const nonce = (0, import_utils.randomBytes)(NONCE_SIZE);
|
|
187
194
|
const plaintext = serializeMemo(
|
|
188
195
|
value,
|
|
189
196
|
ownerPk,
|
|
190
197
|
blinding,
|
|
191
198
|
assetId,
|
|
192
|
-
|
|
199
|
+
sourcePk,
|
|
193
200
|
circuitVersion
|
|
194
201
|
);
|
|
195
202
|
const isZeroKey = recipientIvkPacked.every((b) => b === 0);
|
|
@@ -494,7 +501,7 @@ function tryDecryptNoteVerbose(commitment, viewingSecretKey, spendingKey, ownOwn
|
|
|
494
501
|
commitmentHex: toHex(bigintTo32Le(recomputed)),
|
|
495
502
|
nullifierHex: toHex(bigintTo32Le(nullifier)),
|
|
496
503
|
memo: Array.from(memoBytes),
|
|
497
|
-
|
|
504
|
+
sourcePk: plaintext.sourcePk
|
|
498
505
|
}
|
|
499
506
|
};
|
|
500
507
|
}
|