@sip-protocol/sdk 0.8.1 → 0.9.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/browser.js +105 -102
- package/dist/browser.mjs +1 -1
- package/dist/chunk-5EKF243P.mjs +33809 -0
- package/dist/chunk-6EU6WQFK.mjs +33809 -0
- package/dist/index.js +102 -99
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/chains/ethereum/constants.ts +33 -1
- package/src/chains/ethereum/index.ts +2 -1
- package/src/chains/ethereum/privacy-adapter.ts +36 -21
- package/src/chains/ethereum/stealth.ts +74 -23
- package/src/chains/ethereum/types.ts +4 -0
package/dist/index.js
CHANGED
|
@@ -18922,12 +18922,12 @@ async function createShieldedIntent(params, options) {
|
|
|
18922
18922
|
"Using placeholder signatures for proof generation - NOT cryptographically valid"
|
|
18923
18923
|
);
|
|
18924
18924
|
} else {
|
|
18925
|
-
const { secp256k1:
|
|
18926
|
-
const publicKey =
|
|
18925
|
+
const { secp256k1: secp256k112 } = await import("@noble/curves/secp256k1");
|
|
18926
|
+
const publicKey = secp256k112.getPublicKey(effectiveSenderSecret, true);
|
|
18927
18927
|
const senderAddressBytes = (0, import_sha2565.sha256)(publicKey);
|
|
18928
|
-
const ownershipSig =
|
|
18928
|
+
const ownershipSig = secp256k112.sign(senderAddressBytes, effectiveSenderSecret);
|
|
18929
18929
|
effectiveOwnershipSig = ownershipSig.toCompactRawBytes();
|
|
18930
|
-
const authSig =
|
|
18930
|
+
const authSig = secp256k112.sign(intentHashBytes, effectiveSenderSecret);
|
|
18931
18931
|
effectiveAuthSig = authSig.toCompactRawBytes();
|
|
18932
18932
|
}
|
|
18933
18933
|
const fundingResult = await proofProvider.generateFundingProof({
|
|
@@ -40003,11 +40003,14 @@ function createEthereumAdapter(config) {
|
|
|
40003
40003
|
|
|
40004
40004
|
// src/wallet/ethereum/privacy-adapter.ts
|
|
40005
40005
|
var import_sha25 = require("@noble/hashes/sha2");
|
|
40006
|
-
var
|
|
40006
|
+
var import_secp256k112 = require("@noble/curves/secp256k1");
|
|
40007
40007
|
var import_sha33 = require("@noble/hashes/sha3");
|
|
40008
40008
|
|
|
40009
40009
|
// src/chains/ethereum/stealth.ts
|
|
40010
|
+
var import_secp256k110 = require("@noble/curves/secp256k1");
|
|
40010
40011
|
init_secp256k1();
|
|
40012
|
+
init_utils();
|
|
40013
|
+
init_validation();
|
|
40011
40014
|
init_errors();
|
|
40012
40015
|
|
|
40013
40016
|
// src/chains/ethereum/constants.ts
|
|
@@ -40529,7 +40532,7 @@ var import_types64 = require("@sip-protocol/types");
|
|
|
40529
40532
|
// src/wallet/near/adapter.ts
|
|
40530
40533
|
var import_ed2551912 = require("@noble/curves/ed25519");
|
|
40531
40534
|
var import_sha26 = require("@noble/hashes/sha2");
|
|
40532
|
-
var
|
|
40535
|
+
var import_utils60 = require("@noble/hashes/utils");
|
|
40533
40536
|
var import_types66 = require("@sip-protocol/types");
|
|
40534
40537
|
|
|
40535
40538
|
// src/chains/near/stealth.ts
|
|
@@ -40738,12 +40741,12 @@ var ED25519_ORDER5 = 2n ** 252n + 27742317777372353535851937790883648493n;
|
|
|
40738
40741
|
|
|
40739
40742
|
// src/wallet/near/wallet-selector.ts
|
|
40740
40743
|
var import_sha27 = require("@noble/hashes/sha2");
|
|
40741
|
-
var
|
|
40744
|
+
var import_utils62 = require("@noble/hashes/utils");
|
|
40742
40745
|
var import_ed2551914 = require("@noble/curves/ed25519");
|
|
40743
40746
|
|
|
40744
40747
|
// src/chains/near/implicit-account.ts
|
|
40745
40748
|
var import_ed2551913 = require("@noble/curves/ed25519");
|
|
40746
|
-
var
|
|
40749
|
+
var import_utils61 = require("@noble/hashes/utils");
|
|
40747
40750
|
init_errors();
|
|
40748
40751
|
init_validation();
|
|
40749
40752
|
|
|
@@ -40784,12 +40787,12 @@ function createAnnouncementMemo2(ephemeralPublicKey, viewTag) {
|
|
|
40784
40787
|
|
|
40785
40788
|
// src/wallet/near/my-near-wallet.ts
|
|
40786
40789
|
var import_sha28 = require("@noble/hashes/sha2");
|
|
40787
|
-
var
|
|
40790
|
+
var import_utils63 = require("@noble/hashes/utils");
|
|
40788
40791
|
var import_ed2551915 = require("@noble/curves/ed25519");
|
|
40789
40792
|
|
|
40790
40793
|
// src/wallet/near/meteor-wallet.ts
|
|
40791
40794
|
var import_sha29 = require("@noble/hashes/sha2");
|
|
40792
|
-
var
|
|
40795
|
+
var import_utils64 = require("@noble/hashes/utils");
|
|
40793
40796
|
var import_ed2551916 = require("@noble/curves/ed25519");
|
|
40794
40797
|
|
|
40795
40798
|
// src/wallet/hardware/types.ts
|
|
@@ -41400,9 +41403,9 @@ function createLedgerAdapter(config) {
|
|
|
41400
41403
|
}
|
|
41401
41404
|
|
|
41402
41405
|
// src/wallet/hardware/ledger-privacy.ts
|
|
41403
|
-
var
|
|
41406
|
+
var import_secp256k113 = require("@noble/curves/secp256k1");
|
|
41404
41407
|
var import_sha25628 = require("@noble/hashes/sha256");
|
|
41405
|
-
var
|
|
41408
|
+
var import_utils65 = require("@noble/hashes/utils");
|
|
41406
41409
|
var import_types70 = require("@sip-protocol/types");
|
|
41407
41410
|
|
|
41408
41411
|
// src/wallet/hardware/trezor.ts
|
|
@@ -41845,7 +41848,7 @@ function createTrezorAdapter(config) {
|
|
|
41845
41848
|
|
|
41846
41849
|
// src/wallet/hardware/mock.ts
|
|
41847
41850
|
var import_types74 = require("@sip-protocol/types");
|
|
41848
|
-
var
|
|
41851
|
+
var import_utils66 = require("@noble/hashes/utils");
|
|
41849
41852
|
var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
41850
41853
|
chain;
|
|
41851
41854
|
name = "mock-ledger";
|
|
@@ -42090,15 +42093,15 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
42090
42093
|
}
|
|
42091
42094
|
}
|
|
42092
42095
|
generateMockAddress(index) {
|
|
42093
|
-
const bytes = (0,
|
|
42096
|
+
const bytes = (0, import_utils66.randomBytes)(20);
|
|
42094
42097
|
bytes[0] = index;
|
|
42095
|
-
return `0x${(0,
|
|
42098
|
+
return `0x${(0, import_utils66.bytesToHex)(bytes)}`;
|
|
42096
42099
|
}
|
|
42097
42100
|
generateMockPublicKey(index) {
|
|
42098
|
-
const bytes = (0,
|
|
42101
|
+
const bytes = (0, import_utils66.randomBytes)(33);
|
|
42099
42102
|
bytes[0] = 2;
|
|
42100
42103
|
bytes[1] = index;
|
|
42101
|
-
return `0x${(0,
|
|
42104
|
+
return `0x${(0, import_utils66.bytesToHex)(bytes)}`;
|
|
42102
42105
|
}
|
|
42103
42106
|
generateMockSignature(data) {
|
|
42104
42107
|
const sig = new Uint8Array(65);
|
|
@@ -42107,7 +42110,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
42107
42110
|
sig[32 + i] = (data[i % data.length] ?? 0) ^ i * 11;
|
|
42108
42111
|
}
|
|
42109
42112
|
sig[64] = 27;
|
|
42110
|
-
return `0x${(0,
|
|
42113
|
+
return `0x${(0, import_utils66.bytesToHex)(sig)}`;
|
|
42111
42114
|
}
|
|
42112
42115
|
delay(ms) {
|
|
42113
42116
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -42296,15 +42299,15 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
|
|
|
42296
42299
|
}
|
|
42297
42300
|
}
|
|
42298
42301
|
generateMockAddress(index) {
|
|
42299
|
-
const bytes = (0,
|
|
42302
|
+
const bytes = (0, import_utils66.randomBytes)(20);
|
|
42300
42303
|
bytes[0] = index + 100;
|
|
42301
|
-
return `0x${(0,
|
|
42304
|
+
return `0x${(0, import_utils66.bytesToHex)(bytes)}`;
|
|
42302
42305
|
}
|
|
42303
42306
|
generateMockPublicKey(index) {
|
|
42304
|
-
const bytes = (0,
|
|
42307
|
+
const bytes = (0, import_utils66.randomBytes)(33);
|
|
42305
42308
|
bytes[0] = 3;
|
|
42306
42309
|
bytes[1] = index + 100;
|
|
42307
|
-
return `0x${(0,
|
|
42310
|
+
return `0x${(0, import_utils66.bytesToHex)(bytes)}`;
|
|
42308
42311
|
}
|
|
42309
42312
|
generateMockSignature(data) {
|
|
42310
42313
|
const sig = new Uint8Array(65);
|
|
@@ -42313,7 +42316,7 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
|
|
|
42313
42316
|
sig[32 + i] = (data[i % data.length] ?? 0) ^ i * 17;
|
|
42314
42317
|
}
|
|
42315
42318
|
sig[64] = 28;
|
|
42316
|
-
return `0x${(0,
|
|
42319
|
+
return `0x${(0, import_utils66.bytesToHex)(sig)}`;
|
|
42317
42320
|
}
|
|
42318
42321
|
delay(ms) {
|
|
42319
42322
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -42975,7 +42978,7 @@ function createMainnetVerifier(config = {}) {
|
|
|
42975
42978
|
|
|
42976
42979
|
// src/solana/jito-relayer.ts
|
|
42977
42980
|
var import_web317 = require("@solana/web3.js");
|
|
42978
|
-
var
|
|
42981
|
+
var import_utils67 = require("@noble/hashes/utils");
|
|
42979
42982
|
var JITO_BLOCK_ENGINES = {
|
|
42980
42983
|
mainnet: {
|
|
42981
42984
|
amsterdam: "https://amsterdam.mainnet.block-engine.jito.wtf/api/v1",
|
|
@@ -43095,7 +43098,7 @@ var JitoRelayer = class {
|
|
|
43095
43098
|
}
|
|
43096
43099
|
const signatures = bundleTransactions.map((tx) => {
|
|
43097
43100
|
if (tx instanceof import_web317.VersionedTransaction) {
|
|
43098
|
-
return (0,
|
|
43101
|
+
return (0, import_utils67.bytesToHex)(tx.signatures[0]);
|
|
43099
43102
|
} else {
|
|
43100
43103
|
return tx.signature?.toString() ?? "";
|
|
43101
43104
|
}
|
|
@@ -43134,7 +43137,7 @@ var JitoRelayer = class {
|
|
|
43134
43137
|
const bundleId = await this.sendBundle([serializedTx]);
|
|
43135
43138
|
let signature;
|
|
43136
43139
|
if (request.transaction instanceof import_web317.VersionedTransaction) {
|
|
43137
|
-
signature = (0,
|
|
43140
|
+
signature = (0, import_utils67.bytesToHex)(request.transaction.signatures[0]);
|
|
43138
43141
|
} else {
|
|
43139
43142
|
signature = request.transaction.signature?.toString() ?? "";
|
|
43140
43143
|
}
|
|
@@ -43359,7 +43362,7 @@ function createMainnetRelayer(rpcUrl) {
|
|
|
43359
43362
|
// src/chains/near/commitment.ts
|
|
43360
43363
|
var import_ed2551917 = require("@noble/curves/ed25519");
|
|
43361
43364
|
var import_sha210 = require("@noble/hashes/sha2");
|
|
43362
|
-
var
|
|
43365
|
+
var import_utils68 = require("@noble/hashes/utils");
|
|
43363
43366
|
init_errors();
|
|
43364
43367
|
init_validation();
|
|
43365
43368
|
var H_DOMAIN3 = "SIP-NEAR-PEDERSEN-GENERATOR-H-v1";
|
|
@@ -43380,7 +43383,7 @@ function generateH3() {
|
|
|
43380
43383
|
if (!point.equals(import_ed2551917.ed25519.ExtendedPoint.ZERO)) {
|
|
43381
43384
|
const gBytes = G3.toRawBytes();
|
|
43382
43385
|
const hBytes = point.toRawBytes();
|
|
43383
|
-
if ((0,
|
|
43386
|
+
if ((0, import_utils68.bytesToHex)(gBytes) !== (0, import_utils68.bytesToHex)(hBytes)) {
|
|
43384
43387
|
return point;
|
|
43385
43388
|
}
|
|
43386
43389
|
}
|
|
@@ -43431,13 +43434,13 @@ function commitNEAR(value, blinding) {
|
|
|
43431
43434
|
{ curveOrder: ED25519_ORDER6.toString(16) }
|
|
43432
43435
|
);
|
|
43433
43436
|
}
|
|
43434
|
-
const r = blinding ?? (0,
|
|
43437
|
+
const r = blinding ?? (0, import_utils68.randomBytes)(32);
|
|
43435
43438
|
if (r.length !== 32) {
|
|
43436
43439
|
throw new ValidationError("must be 32 bytes", "blinding", { received: r.length });
|
|
43437
43440
|
}
|
|
43438
43441
|
const rScalar = bytesToBigInt4(r) % ED25519_ORDER6;
|
|
43439
43442
|
if (rScalar === 0n) {
|
|
43440
|
-
return commitNEAR(value, (0,
|
|
43443
|
+
return commitNEAR(value, (0, import_utils68.randomBytes)(32));
|
|
43441
43444
|
}
|
|
43442
43445
|
let C;
|
|
43443
43446
|
if (value === 0n) {
|
|
@@ -43449,8 +43452,8 @@ function commitNEAR(value, blinding) {
|
|
|
43449
43452
|
}
|
|
43450
43453
|
const rScalarBytes = bigIntToBytes4(rScalar, 32);
|
|
43451
43454
|
return {
|
|
43452
|
-
commitment: `0x${(0,
|
|
43453
|
-
blinding: `0x${(0,
|
|
43455
|
+
commitment: `0x${(0, import_utils68.bytesToHex)(C.toRawBytes())}`,
|
|
43456
|
+
blinding: `0x${(0, import_utils68.bytesToHex)(rScalarBytes)}`
|
|
43454
43457
|
};
|
|
43455
43458
|
}
|
|
43456
43459
|
function verifyOpeningNEAR(commitment, value, blinding) {
|
|
@@ -43543,7 +43546,7 @@ function addCommitmentsNEAR(c1, c2) {
|
|
|
43543
43546
|
}
|
|
43544
43547
|
const sum = point1.add(point2);
|
|
43545
43548
|
return {
|
|
43546
|
-
commitment: `0x${(0,
|
|
43549
|
+
commitment: `0x${(0, import_utils68.bytesToHex)(sum.toRawBytes())}`
|
|
43547
43550
|
};
|
|
43548
43551
|
}
|
|
43549
43552
|
function subtractCommitmentsNEAR(c1, c2) {
|
|
@@ -43572,7 +43575,7 @@ function subtractCommitmentsNEAR(c1, c2) {
|
|
|
43572
43575
|
};
|
|
43573
43576
|
}
|
|
43574
43577
|
return {
|
|
43575
|
-
commitment: `0x${(0,
|
|
43578
|
+
commitment: `0x${(0, import_utils68.bytesToHex)(diff.toRawBytes())}`
|
|
43576
43579
|
};
|
|
43577
43580
|
}
|
|
43578
43581
|
function addBlindingsNEAR(b1, b2) {
|
|
@@ -43588,7 +43591,7 @@ function addBlindingsNEAR(b1, b2) {
|
|
|
43588
43591
|
const b2Scalar = bytesToBigInt4(b2Bytes);
|
|
43589
43592
|
const sum = (b1Scalar + b2Scalar) % ED25519_ORDER6;
|
|
43590
43593
|
const sumBytes = bigIntToBytes4(sum, 32);
|
|
43591
|
-
return `0x${(0,
|
|
43594
|
+
return `0x${(0, import_utils68.bytesToHex)(sumBytes)}`;
|
|
43592
43595
|
}
|
|
43593
43596
|
function subtractBlindingsNEAR(b1, b2) {
|
|
43594
43597
|
if (!isValidHex(b1)) {
|
|
@@ -43603,22 +43606,22 @@ function subtractBlindingsNEAR(b1, b2) {
|
|
|
43603
43606
|
const b2Scalar = bytesToBigInt4(b2Bytes);
|
|
43604
43607
|
const diff = (b1Scalar - b2Scalar + ED25519_ORDER6) % ED25519_ORDER6;
|
|
43605
43608
|
const diffBytes = bigIntToBytes4(diff, 32);
|
|
43606
|
-
return `0x${(0,
|
|
43609
|
+
return `0x${(0, import_utils68.bytesToHex)(diffBytes)}`;
|
|
43607
43610
|
}
|
|
43608
43611
|
function getGeneratorsNEAR() {
|
|
43609
43612
|
return {
|
|
43610
|
-
G: `0x${(0,
|
|
43611
|
-
H: `0x${(0,
|
|
43613
|
+
G: `0x${(0, import_utils68.bytesToHex)(G3.toRawBytes())}`,
|
|
43614
|
+
H: `0x${(0, import_utils68.bytesToHex)(H3.toRawBytes())}`
|
|
43612
43615
|
};
|
|
43613
43616
|
}
|
|
43614
43617
|
function generateBlindingNEAR() {
|
|
43615
|
-
const bytes = (0,
|
|
43618
|
+
const bytes = (0, import_utils68.randomBytes)(32);
|
|
43616
43619
|
const scalar = bytesToBigInt4(bytes) % ED25519_ORDER6;
|
|
43617
43620
|
if (scalar === 0n) {
|
|
43618
43621
|
return generateBlindingNEAR();
|
|
43619
43622
|
}
|
|
43620
43623
|
const scalarBytes = bigIntToBytes4(scalar, 32);
|
|
43621
|
-
return `0x${(0,
|
|
43624
|
+
return `0x${(0, import_utils68.bytesToHex)(scalarBytes)}`;
|
|
43622
43625
|
}
|
|
43623
43626
|
|
|
43624
43627
|
// src/chains/near/viewing-key.ts
|
|
@@ -43626,7 +43629,7 @@ var import_ed2551918 = require("@noble/curves/ed25519");
|
|
|
43626
43629
|
var import_sha25629 = require("@noble/hashes/sha256");
|
|
43627
43630
|
var import_hmac7 = require("@noble/hashes/hmac");
|
|
43628
43631
|
var import_hkdf5 = require("@noble/hashes/hkdf");
|
|
43629
|
-
var
|
|
43632
|
+
var import_utils69 = require("@noble/hashes/utils");
|
|
43630
43633
|
var import_chacha6 = require("@noble/ciphers/chacha.js");
|
|
43631
43634
|
init_errors();
|
|
43632
43635
|
init_validation();
|
|
@@ -43642,7 +43645,7 @@ function generateNEARViewingKeyFromSpending(spendingPrivateKey, label) {
|
|
|
43642
43645
|
"spendingPrivateKey"
|
|
43643
43646
|
);
|
|
43644
43647
|
}
|
|
43645
|
-
const spendingBytes = (0,
|
|
43648
|
+
const spendingBytes = (0, import_utils69.hexToBytes)(spendingPrivateKey.slice(2));
|
|
43646
43649
|
if (spendingBytes.length !== 32) {
|
|
43647
43650
|
throw new ValidationError(
|
|
43648
43651
|
"spendingPrivateKey must be 32 bytes",
|
|
@@ -43653,15 +43656,15 @@ function generateNEARViewingKeyFromSpending(spendingPrivateKey, label) {
|
|
|
43653
43656
|
try {
|
|
43654
43657
|
viewingPrivateBytes = (0, import_hmac7.hmac)(
|
|
43655
43658
|
import_sha25629.sha256,
|
|
43656
|
-
(0,
|
|
43659
|
+
(0, import_utils69.utf8ToBytes)(VIEWING_KEY_CONTEXT3),
|
|
43657
43660
|
spendingBytes
|
|
43658
43661
|
);
|
|
43659
43662
|
const viewingPublicBytes = import_ed2551918.ed25519.getPublicKey(viewingPrivateBytes);
|
|
43660
43663
|
const hashBytes = (0, import_sha25629.sha256)(viewingPublicBytes);
|
|
43661
43664
|
return {
|
|
43662
|
-
privateKey: `0x${(0,
|
|
43663
|
-
publicKey: `0x${(0,
|
|
43664
|
-
hash: `0x${(0,
|
|
43665
|
+
privateKey: `0x${(0, import_utils69.bytesToHex)(viewingPrivateBytes)}`,
|
|
43666
|
+
publicKey: `0x${(0, import_utils69.bytesToHex)(viewingPublicBytes)}`,
|
|
43667
|
+
hash: `0x${(0, import_utils69.bytesToHex)(hashBytes)}`,
|
|
43665
43668
|
label,
|
|
43666
43669
|
createdAt: Date.now()
|
|
43667
43670
|
};
|
|
@@ -43671,14 +43674,14 @@ function generateNEARViewingKeyFromSpending(spendingPrivateKey, label) {
|
|
|
43671
43674
|
}
|
|
43672
43675
|
}
|
|
43673
43676
|
function generateRandomNEARViewingKey(label) {
|
|
43674
|
-
const privateBytes = (0,
|
|
43677
|
+
const privateBytes = (0, import_utils69.randomBytes)(32);
|
|
43675
43678
|
try {
|
|
43676
43679
|
const publicBytes = import_ed2551918.ed25519.getPublicKey(privateBytes);
|
|
43677
43680
|
const hashBytes = (0, import_sha25629.sha256)(publicBytes);
|
|
43678
43681
|
return {
|
|
43679
|
-
privateKey: `0x${(0,
|
|
43680
|
-
publicKey: `0x${(0,
|
|
43681
|
-
hash: `0x${(0,
|
|
43682
|
+
privateKey: `0x${(0, import_utils69.bytesToHex)(privateBytes)}`,
|
|
43683
|
+
publicKey: `0x${(0, import_utils69.bytesToHex)(publicBytes)}`,
|
|
43684
|
+
hash: `0x${(0, import_utils69.bytesToHex)(hashBytes)}`,
|
|
43682
43685
|
label,
|
|
43683
43686
|
createdAt: Date.now()
|
|
43684
43687
|
};
|
|
@@ -43693,7 +43696,7 @@ function computeNEARViewingKeyHash(viewingPublicKey) {
|
|
|
43693
43696
|
"viewingPublicKey"
|
|
43694
43697
|
);
|
|
43695
43698
|
}
|
|
43696
|
-
const publicBytes = (0,
|
|
43699
|
+
const publicBytes = (0, import_utils69.hexToBytes)(viewingPublicKey.slice(2));
|
|
43697
43700
|
if (publicBytes.length !== 32) {
|
|
43698
43701
|
throw new ValidationError(
|
|
43699
43702
|
"viewingPublicKey must be 32 bytes",
|
|
@@ -43701,7 +43704,7 @@ function computeNEARViewingKeyHash(viewingPublicKey) {
|
|
|
43701
43704
|
);
|
|
43702
43705
|
}
|
|
43703
43706
|
const hashBytes = (0, import_sha25629.sha256)(publicBytes);
|
|
43704
|
-
return `0x${(0,
|
|
43707
|
+
return `0x${(0, import_utils69.bytesToHex)(hashBytes)}`;
|
|
43705
43708
|
}
|
|
43706
43709
|
function computeNEARViewingKeyHashFromPrivate(viewingPrivateKey) {
|
|
43707
43710
|
if (!viewingPrivateKey || !viewingPrivateKey.startsWith("0x")) {
|
|
@@ -43710,7 +43713,7 @@ function computeNEARViewingKeyHashFromPrivate(viewingPrivateKey) {
|
|
|
43710
43713
|
"viewingPrivateKey"
|
|
43711
43714
|
);
|
|
43712
43715
|
}
|
|
43713
|
-
const privateBytes = (0,
|
|
43716
|
+
const privateBytes = (0, import_utils69.hexToBytes)(viewingPrivateKey.slice(2));
|
|
43714
43717
|
if (privateBytes.length !== 32) {
|
|
43715
43718
|
throw new ValidationError(
|
|
43716
43719
|
"viewingPrivateKey must be 32 bytes",
|
|
@@ -43720,7 +43723,7 @@ function computeNEARViewingKeyHashFromPrivate(viewingPrivateKey) {
|
|
|
43720
43723
|
try {
|
|
43721
43724
|
const publicBytes = import_ed2551918.ed25519.getPublicKey(privateBytes);
|
|
43722
43725
|
const hashBytes = (0, import_sha25629.sha256)(publicBytes);
|
|
43723
|
-
return `0x${(0,
|
|
43726
|
+
return `0x${(0, import_utils69.bytesToHex)(hashBytes)}`;
|
|
43724
43727
|
} finally {
|
|
43725
43728
|
secureWipe(privateBytes);
|
|
43726
43729
|
}
|
|
@@ -43767,9 +43770,9 @@ function importNEARViewingKey(exported) {
|
|
|
43767
43770
|
{ expected: computedHash, received: exported.hash }
|
|
43768
43771
|
);
|
|
43769
43772
|
}
|
|
43770
|
-
const privateBytes = (0,
|
|
43773
|
+
const privateBytes = (0, import_utils69.hexToBytes)(exported.privateKey.slice(2));
|
|
43771
43774
|
try {
|
|
43772
|
-
const derivedPublic = `0x${(0,
|
|
43775
|
+
const derivedPublic = `0x${(0, import_utils69.bytesToHex)(import_ed2551918.ed25519.getPublicKey(privateBytes))}`;
|
|
43773
43776
|
if (derivedPublic !== exported.publicKey) {
|
|
43774
43777
|
throw new ValidationError(
|
|
43775
43778
|
"Public key does not match private key",
|
|
@@ -43788,10 +43791,10 @@ function importNEARViewingKey(exported) {
|
|
|
43788
43791
|
};
|
|
43789
43792
|
}
|
|
43790
43793
|
function deriveEncryptionKey3(key, salt) {
|
|
43791
|
-
const keyBytes = (0,
|
|
43794
|
+
const keyBytes = (0, import_utils69.hexToBytes)(key.slice(2));
|
|
43792
43795
|
try {
|
|
43793
|
-
const hkdfSalt = salt ?? (0,
|
|
43794
|
-
return (0, import_hkdf5.hkdf)(import_sha25629.sha256, keyBytes, hkdfSalt, (0,
|
|
43796
|
+
const hkdfSalt = salt ?? (0, import_utils69.utf8ToBytes)(ENCRYPTION_DOMAIN3);
|
|
43797
|
+
return (0, import_hkdf5.hkdf)(import_sha25629.sha256, keyBytes, hkdfSalt, (0, import_utils69.utf8ToBytes)("encryption"), 32);
|
|
43795
43798
|
} finally {
|
|
43796
43799
|
secureWipe(keyBytes);
|
|
43797
43800
|
}
|
|
@@ -43799,13 +43802,13 @@ function deriveEncryptionKey3(key, salt) {
|
|
|
43799
43802
|
function encryptForNEARViewing(data, viewingKey) {
|
|
43800
43803
|
const encKey = deriveEncryptionKey3(viewingKey.privateKey);
|
|
43801
43804
|
try {
|
|
43802
|
-
const nonce = (0,
|
|
43803
|
-
const plaintext = (0,
|
|
43805
|
+
const nonce = (0, import_utils69.randomBytes)(NONCE_SIZE4);
|
|
43806
|
+
const plaintext = (0, import_utils69.utf8ToBytes)(JSON.stringify(data));
|
|
43804
43807
|
const cipher = (0, import_chacha6.xchacha20poly1305)(encKey, nonce);
|
|
43805
43808
|
const ciphertext = cipher.encrypt(plaintext);
|
|
43806
43809
|
return {
|
|
43807
|
-
ciphertext: `0x${(0,
|
|
43808
|
-
nonce: `0x${(0,
|
|
43810
|
+
ciphertext: `0x${(0, import_utils69.bytesToHex)(ciphertext)}`,
|
|
43811
|
+
nonce: `0x${(0, import_utils69.bytesToHex)(nonce)}`,
|
|
43809
43812
|
viewingKeyHash: viewingKey.hash
|
|
43810
43813
|
};
|
|
43811
43814
|
} finally {
|
|
@@ -43822,8 +43825,8 @@ function decryptWithNEARViewing(encrypted, viewingKey) {
|
|
|
43822
43825
|
}
|
|
43823
43826
|
const encKey = deriveEncryptionKey3(viewingKey.privateKey);
|
|
43824
43827
|
try {
|
|
43825
|
-
const ciphertext = (0,
|
|
43826
|
-
const nonce = (0,
|
|
43828
|
+
const ciphertext = (0, import_utils69.hexToBytes)(encrypted.ciphertext.slice(2));
|
|
43829
|
+
const nonce = (0, import_utils69.hexToBytes)(encrypted.nonce.slice(2));
|
|
43827
43830
|
if (nonce.length !== NONCE_SIZE4) {
|
|
43828
43831
|
throw new ValidationError(
|
|
43829
43832
|
`Invalid nonce length: ${nonce.length}. Expected: ${NONCE_SIZE4}`,
|
|
@@ -43873,15 +43876,15 @@ function deriveNEARChildViewingKey(parentKey, childPath, label) {
|
|
|
43873
43876
|
if (!childPath || typeof childPath !== "string") {
|
|
43874
43877
|
throw new ValidationError("childPath must be a non-empty string", "childPath");
|
|
43875
43878
|
}
|
|
43876
|
-
const parentBytes = (0,
|
|
43879
|
+
const parentBytes = (0, import_utils69.hexToBytes)(parentKey.privateKey.slice(2));
|
|
43877
43880
|
try {
|
|
43878
|
-
const childBytes = (0, import_hmac7.hmac)(import_sha25629.sha256, (0,
|
|
43881
|
+
const childBytes = (0, import_hmac7.hmac)(import_sha25629.sha256, (0, import_utils69.utf8ToBytes)(childPath), parentBytes);
|
|
43879
43882
|
const publicBytes = import_ed2551918.ed25519.getPublicKey(childBytes);
|
|
43880
43883
|
const hashBytes = (0, import_sha25629.sha256)(publicBytes);
|
|
43881
43884
|
const result = {
|
|
43882
|
-
privateKey: `0x${(0,
|
|
43883
|
-
publicKey: `0x${(0,
|
|
43884
|
-
hash: `0x${(0,
|
|
43885
|
+
privateKey: `0x${(0, import_utils69.bytesToHex)(childBytes)}`,
|
|
43886
|
+
publicKey: `0x${(0, import_utils69.bytesToHex)(publicBytes)}`,
|
|
43887
|
+
hash: `0x${(0, import_utils69.bytesToHex)(hashBytes)}`,
|
|
43885
43888
|
label: label ?? `${parentKey.label ?? "Key"}/${childPath}`,
|
|
43886
43889
|
createdAt: Date.now()
|
|
43887
43890
|
};
|
|
@@ -43898,7 +43901,7 @@ function getNEARViewingPublicKey(viewingPrivateKey) {
|
|
|
43898
43901
|
"viewingPrivateKey"
|
|
43899
43902
|
);
|
|
43900
43903
|
}
|
|
43901
|
-
const privateBytes = (0,
|
|
43904
|
+
const privateBytes = (0, import_utils69.hexToBytes)(viewingPrivateKey.slice(2));
|
|
43902
43905
|
if (privateBytes.length !== 32) {
|
|
43903
43906
|
throw new ValidationError(
|
|
43904
43907
|
"viewingPrivateKey must be 32 bytes",
|
|
@@ -43907,7 +43910,7 @@ function getNEARViewingPublicKey(viewingPrivateKey) {
|
|
|
43907
43910
|
}
|
|
43908
43911
|
try {
|
|
43909
43912
|
const publicBytes = import_ed2551918.ed25519.getPublicKey(privateBytes);
|
|
43910
|
-
return `0x${(0,
|
|
43913
|
+
return `0x${(0, import_utils69.bytesToHex)(publicBytes)}`;
|
|
43911
43914
|
} finally {
|
|
43912
43915
|
secureWipe(privateBytes);
|
|
43913
43916
|
}
|
|
@@ -43942,9 +43945,9 @@ function validateNEARViewingKey(viewingKey) {
|
|
|
43942
43945
|
{ expected: computedHash, received: viewingKey.hash }
|
|
43943
43946
|
);
|
|
43944
43947
|
}
|
|
43945
|
-
const privateBytes = (0,
|
|
43948
|
+
const privateBytes = (0, import_utils69.hexToBytes)(viewingKey.privateKey.slice(2));
|
|
43946
43949
|
try {
|
|
43947
|
-
const derivedPublic = `0x${(0,
|
|
43950
|
+
const derivedPublic = `0x${(0, import_utils69.bytesToHex)(import_ed2551918.ed25519.getPublicKey(privateBytes))}`;
|
|
43948
43951
|
if (derivedPublic !== viewingKey.publicKey) {
|
|
43949
43952
|
throw new ValidationError(
|
|
43950
43953
|
"publicKey does not match privateKey",
|
|
@@ -43958,7 +43961,7 @@ function validateNEARViewingKey(viewingKey) {
|
|
|
43958
43961
|
}
|
|
43959
43962
|
|
|
43960
43963
|
// src/chains/near/resolver.ts
|
|
43961
|
-
var
|
|
43964
|
+
var import_utils70 = require("@noble/hashes/utils");
|
|
43962
43965
|
init_errors();
|
|
43963
43966
|
init_validation();
|
|
43964
43967
|
function createNEARAnnouncementCache() {
|
|
@@ -44210,7 +44213,7 @@ var NEARStealthScanner = class {
|
|
|
44210
44213
|
recipient.viewingPrivateKey
|
|
44211
44214
|
);
|
|
44212
44215
|
if (isMatch) {
|
|
44213
|
-
const stealthAddress = isImplicitAccount(announcement.stealthAddress) ? announcement.stealthAddress : (0,
|
|
44216
|
+
const stealthAddress = isImplicitAccount(announcement.stealthAddress) ? announcement.stealthAddress : (0, import_utils70.bytesToHex)((0, import_utils70.hexToBytes)(stealthPublicKey.slice(2)));
|
|
44214
44217
|
let amount = metadata?.amount ?? 0n;
|
|
44215
44218
|
if (amount === 0n && isImplicitAccount(stealthAddress)) {
|
|
44216
44219
|
try {
|
|
@@ -46585,7 +46588,7 @@ function createPrivacyLogger(moduleName, config = {}) {
|
|
|
46585
46588
|
}
|
|
46586
46589
|
|
|
46587
46590
|
// src/privacy-backends/privacycash.ts
|
|
46588
|
-
var
|
|
46591
|
+
var import_utils71 = require("@noble/hashes/utils");
|
|
46589
46592
|
var privacyCashLogger = createPrivacyLogger("PrivacyCash");
|
|
46590
46593
|
var DEFAULT_ANONYMITY_SET = 50;
|
|
46591
46594
|
var BASE_COST_LAMPORTS = BigInt(1e7);
|
|
@@ -46615,7 +46618,7 @@ var PRIVACYCASH_CAPABILITIES = {
|
|
|
46615
46618
|
|
|
46616
46619
|
// src/privacy-backends/shadowwire.ts
|
|
46617
46620
|
var import_shadowwire = require("@radr/shadowwire");
|
|
46618
|
-
var
|
|
46621
|
+
var import_utils72 = require("@noble/hashes/utils");
|
|
46619
46622
|
var SHADOWWIRE_TOKEN_MINTS = {
|
|
46620
46623
|
SOL: "So11111111111111111111111111111111111111112",
|
|
46621
46624
|
USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
@@ -46669,7 +46672,7 @@ var COST_PER_ENCRYPTED_INPUT_WEI = BigInt("1000000000000000");
|
|
|
46669
46672
|
// src/privacy-backends/magicblock.ts
|
|
46670
46673
|
var import_ephemeral_rollups_sdk = require("@magicblock-labs/ephemeral-rollups-sdk");
|
|
46671
46674
|
var import_web318 = require("@solana/web3.js");
|
|
46672
|
-
var
|
|
46675
|
+
var import_utils73 = require("@noble/hashes/utils");
|
|
46673
46676
|
var magicBlockLogger = createPrivacyLogger("MagicBlock");
|
|
46674
46677
|
|
|
46675
46678
|
// src/privacy-backends/cspl-types.ts
|
|
@@ -47359,7 +47362,7 @@ var CSPLClient = class {
|
|
|
47359
47362
|
|
|
47360
47363
|
// src/privacy-backends/private-swap.ts
|
|
47361
47364
|
var import_sha25630 = require("@noble/hashes/sha256");
|
|
47362
|
-
var
|
|
47365
|
+
var import_utils74 = require("@noble/hashes/utils");
|
|
47363
47366
|
|
|
47364
47367
|
// src/privacy-backends/cspl-token.ts
|
|
47365
47368
|
var CSPLTokenService = class {
|
|
@@ -50070,7 +50073,7 @@ init_proxy();
|
|
|
50070
50073
|
// src/sync/oblivious.ts
|
|
50071
50074
|
var import_sha211 = require("@noble/hashes/sha2");
|
|
50072
50075
|
var import_hmac8 = require("@noble/hashes/hmac");
|
|
50073
|
-
var
|
|
50076
|
+
var import_utils75 = require("@noble/hashes/utils");
|
|
50074
50077
|
init_secure_memory();
|
|
50075
50078
|
var DEFAULT_SYNC_CONFIG = {
|
|
50076
50079
|
maxBatchSize: 1e3,
|
|
@@ -50081,7 +50084,7 @@ var DEFAULT_SYNC_CONFIG = {
|
|
|
50081
50084
|
parallelSync: true
|
|
50082
50085
|
};
|
|
50083
50086
|
function generateSyncRandomness(epoch, durationSeconds = DEFAULT_SYNC_CONFIG.epochDurationSeconds) {
|
|
50084
|
-
const value = (0,
|
|
50087
|
+
const value = (0, import_utils75.randomBytes)(32);
|
|
50085
50088
|
const expiresAt = Date.now() + durationSeconds * 1e3;
|
|
50086
50089
|
return {
|
|
50087
50090
|
value,
|
|
@@ -50097,21 +50100,21 @@ function getCurrentEpoch(epochDurationSeconds = DEFAULT_SYNC_CONFIG.epochDuratio
|
|
|
50097
50100
|
}
|
|
50098
50101
|
var OBLIVIOUS_NULLIFIER_DOMAIN = "SIP-OBLIVIOUS-NULLIFIER-V1";
|
|
50099
50102
|
function deriveObliviousNullifier(noteCommitment, spendingKey, syncRandomness) {
|
|
50100
|
-
const commitmentBytes = (0,
|
|
50103
|
+
const commitmentBytes = (0, import_utils75.hexToBytes)(
|
|
50101
50104
|
noteCommitment.startsWith("0x") ? noteCommitment.slice(2) : noteCommitment
|
|
50102
50105
|
);
|
|
50103
|
-
const keyBytes = (0,
|
|
50106
|
+
const keyBytes = (0, import_utils75.hexToBytes)(
|
|
50104
50107
|
spendingKey.startsWith("0x") ? spendingKey.slice(2) : spendingKey
|
|
50105
50108
|
);
|
|
50106
50109
|
try {
|
|
50107
|
-
const domain = (0,
|
|
50110
|
+
const domain = (0, import_utils75.utf8ToBytes)(OBLIVIOUS_NULLIFIER_DOMAIN);
|
|
50108
50111
|
const message = new Uint8Array(domain.length + commitmentBytes.length + syncRandomness.value.length);
|
|
50109
50112
|
message.set(domain, 0);
|
|
50110
50113
|
message.set(commitmentBytes, domain.length);
|
|
50111
50114
|
message.set(syncRandomness.value, domain.length + commitmentBytes.length);
|
|
50112
50115
|
const nullifierBytes = (0, import_hmac8.hmac)(import_sha211.sha256, keyBytes, message);
|
|
50113
50116
|
return {
|
|
50114
|
-
nullifier: `0x${(0,
|
|
50117
|
+
nullifier: `0x${(0, import_utils75.bytesToHex)(nullifierBytes)}`,
|
|
50115
50118
|
epoch: syncRandomness.epoch,
|
|
50116
50119
|
chainId: "default"
|
|
50117
50120
|
// Will be set by caller
|
|
@@ -50121,15 +50124,15 @@ function deriveObliviousNullifier(noteCommitment, spendingKey, syncRandomness) {
|
|
|
50121
50124
|
}
|
|
50122
50125
|
}
|
|
50123
50126
|
function deriveTraditionalNullifier(noteCommitment, spendingKey) {
|
|
50124
|
-
const commitmentBytes = (0,
|
|
50127
|
+
const commitmentBytes = (0, import_utils75.hexToBytes)(
|
|
50125
50128
|
noteCommitment.startsWith("0x") ? noteCommitment.slice(2) : noteCommitment
|
|
50126
50129
|
);
|
|
50127
|
-
const keyBytes = (0,
|
|
50130
|
+
const keyBytes = (0, import_utils75.hexToBytes)(
|
|
50128
50131
|
spendingKey.startsWith("0x") ? spendingKey.slice(2) : spendingKey
|
|
50129
50132
|
);
|
|
50130
50133
|
try {
|
|
50131
50134
|
const nullifierBytes = (0, import_hmac8.hmac)(import_sha211.sha256, keyBytes, commitmentBytes);
|
|
50132
|
-
return `0x${(0,
|
|
50135
|
+
return `0x${(0, import_utils75.bytesToHex)(nullifierBytes)}`;
|
|
50133
50136
|
} finally {
|
|
50134
50137
|
secureWipe(keyBytes);
|
|
50135
50138
|
}
|
|
@@ -50174,7 +50177,7 @@ function createTimeWindowedKey(masterViewingKey, startTime, endTime, epochDurati
|
|
|
50174
50177
|
for (let e = startEpoch; e <= endEpoch; e++) {
|
|
50175
50178
|
epochs.push(e);
|
|
50176
50179
|
}
|
|
50177
|
-
const keyBytes = (0,
|
|
50180
|
+
const keyBytes = (0, import_utils75.hexToBytes)(
|
|
50178
50181
|
masterViewingKey.startsWith("0x") ? masterViewingKey.slice(2) : masterViewingKey
|
|
50179
50182
|
);
|
|
50180
50183
|
const windowData = new Uint8Array(16);
|
|
@@ -50185,11 +50188,11 @@ function createTimeWindowedKey(masterViewingKey, startTime, endTime, epochDurati
|
|
|
50185
50188
|
const keyHash = (0, import_sha211.sha256)(derivedKey);
|
|
50186
50189
|
secureWipe(keyBytes);
|
|
50187
50190
|
return {
|
|
50188
|
-
viewingKey: `0x${(0,
|
|
50191
|
+
viewingKey: `0x${(0, import_utils75.bytesToHex)(derivedKey)}`,
|
|
50189
50192
|
windowStart: startTime,
|
|
50190
50193
|
windowEnd: endTime,
|
|
50191
50194
|
epochs,
|
|
50192
|
-
hash: `0x${(0,
|
|
50195
|
+
hash: `0x${(0, import_utils75.bytesToHex)(keyHash)}`
|
|
50193
50196
|
};
|
|
50194
50197
|
}
|
|
50195
50198
|
function isNoteInWindow(_note, _windowedKey) {
|
|
@@ -50215,7 +50218,7 @@ var ObliviousSyncError = class extends Error {
|
|
|
50215
50218
|
};
|
|
50216
50219
|
|
|
50217
50220
|
// src/sync/mock-provider.ts
|
|
50218
|
-
var
|
|
50221
|
+
var import_utils76 = require("@noble/hashes/utils");
|
|
50219
50222
|
var DEFAULT_MOCK_CONFIG = {
|
|
50220
50223
|
chains: ["ethereum", "solana", "near"],
|
|
50221
50224
|
latencyMs: 100,
|
|
@@ -50312,7 +50315,7 @@ var MockObliviousSyncProvider = class {
|
|
|
50312
50315
|
merkleProofs,
|
|
50313
50316
|
syncHeight: this.config.blockHeight,
|
|
50314
50317
|
timestamp: Date.now(),
|
|
50315
|
-
queryHash: `0x${(0,
|
|
50318
|
+
queryHash: `0x${(0, import_utils76.bytesToHex)((0, import_utils76.randomBytes)(32))}`
|
|
50316
50319
|
};
|
|
50317
50320
|
}
|
|
50318
50321
|
async getCurrentHeight(chainId) {
|
|
@@ -50393,23 +50396,23 @@ var MockObliviousSyncProvider = class {
|
|
|
50393
50396
|
generateMockNote(blockRange) {
|
|
50394
50397
|
const blockNumber = blockRange.startBlock + BigInt(Math.floor(Math.random() * Number(blockRange.endBlock - blockRange.startBlock)));
|
|
50395
50398
|
return {
|
|
50396
|
-
commitment: `0x${(0,
|
|
50397
|
-
encryptedData: `0x${(0,
|
|
50399
|
+
commitment: `0x${(0, import_utils76.bytesToHex)((0, import_utils76.randomBytes)(32))}`,
|
|
50400
|
+
encryptedData: `0x${(0, import_utils76.bytesToHex)((0, import_utils76.randomBytes)(128))}`,
|
|
50398
50401
|
blockNumber,
|
|
50399
|
-
txHash: `0x${(0,
|
|
50402
|
+
txHash: `0x${(0, import_utils76.bytesToHex)((0, import_utils76.randomBytes)(32))}`,
|
|
50400
50403
|
chainId: blockRange.chainId
|
|
50401
50404
|
};
|
|
50402
50405
|
}
|
|
50403
50406
|
generateMockMerkleProof(leaf) {
|
|
50404
50407
|
const siblings = [];
|
|
50405
50408
|
for (let i = 0; i < 20; i++) {
|
|
50406
|
-
siblings.push(`0x${(0,
|
|
50409
|
+
siblings.push(`0x${(0, import_utils76.bytesToHex)((0, import_utils76.randomBytes)(32))}`);
|
|
50407
50410
|
}
|
|
50408
50411
|
return {
|
|
50409
50412
|
leaf,
|
|
50410
50413
|
siblings,
|
|
50411
50414
|
index: BigInt(Math.floor(Math.random() * 1e6)),
|
|
50412
|
-
root: `0x${(0,
|
|
50415
|
+
root: `0x${(0, import_utils76.bytesToHex)((0, import_utils76.randomBytes)(32))}`
|
|
50413
50416
|
};
|
|
50414
50417
|
}
|
|
50415
50418
|
};
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sip-protocol/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Core SDK for Shielded Intents Protocol - Privacy layer for cross-chain transactions",
|
|
5
5
|
"author": "SIP Protocol <hello@sip-protocol.org>",
|
|
6
6
|
"homepage": "https://sip-protocol.org",
|