@gurge/sdk-react-native 0.3.96 → 0.3.105

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/bootstrap.cjs CHANGED
@@ -1 +1 @@
1
- const e=require(`./_virtual/_rolldown/runtime.cjs`);require(`react-native-get-random-values`);let t=require(`buffer`),n=require(`react-native`);if(n=e.__toESM(n),globalThis.WebAssembly===void 0){class e extends Error{constructor(e){super(e),this.name=`RuntimeError`}}globalThis.WebAssembly={RuntimeError:e}}global.Buffer=t.Buffer,globalThis.indexedDB===void 0&&(globalThis.indexedDB={}),global.require===void 0&&(global.require=e=>{if(e===`react-native`)return n;throw Error(`global.require shim: unsupported module "${e}"`)});
1
+ const e=require(`./_virtual/_rolldown/runtime.cjs`);require(`react-native-get-random-values`);let t=require(`buffer`),n=require(`react-native`);n=e.__toESM(n),globalThis.process?.versions?.node&&delete globalThis.process.versions.node,global.Buffer=t.Buffer,globalThis.indexedDB===void 0&&(globalThis.indexedDB={}),global.require===void 0&&(global.require=e=>{if(e===`react-native`)return n;throw Error(`global.require shim: unsupported module "${e}"`)});
package/bootstrap.mjs CHANGED
@@ -1,16 +1,7 @@
1
1
  import "react-native-get-random-values";
2
2
  import { Buffer as e } from "buffer";
3
3
  import * as t from "react-native";
4
- //#region ./bootstrap.ts
5
- if (globalThis.WebAssembly === void 0) {
6
- class e extends Error {
7
- constructor(e) {
8
- super(e), this.name = "RuntimeError";
9
- }
10
- }
11
- globalThis.WebAssembly = { RuntimeError: e };
12
- }
13
- global.Buffer = e, globalThis.indexedDB === void 0 && (globalThis.indexedDB = {}), global.require === void 0 && (global.require = (e) => {
4
+ globalThis.process?.versions?.node && delete globalThis.process.versions.node, global.Buffer = e, globalThis.indexedDB === void 0 && (globalThis.indexedDB = {}), global.require === void 0 && (global.require = (e) => {
14
5
  if (e === "react-native") return t;
15
6
  throw Error(`global.require shim: unsupported module "${e}"`);
16
7
  });
@@ -1 +1 @@
1
- const e=require("../../../_virtual/_rolldown/runtime.cjs");let t=require(`ethers`),n=require(`libsodium-wrappers`);n=e.__toESM(n);var r=()=>n.default.crypto_box_SEALBYTES+n.default.crypto_secretbox_KEYBYTES,i=({nonce:e,sealedKeys:t,ciphertext:n})=>{let i=t.length,a=new Uint8Array(1+e.length+i*r()+n.length),o=0;return a[o]=i,o+=1,a.set(e,o),o+=e.length,t.forEach(e=>{a.set(e,o),o+=e.length}),a.set(n,o),a},a=(e,r)=>{let a=n.default.crypto_secretbox_keygen(),o=n.default.randombytes_buf(n.default.crypto_secretbox_NONCEBYTES),s=n.default.crypto_secretbox_easy(e,o,a);return i({nonce:o,sealedKeys:r.map(e=>n.default.crypto_box_seal(a,t.ethers.getBytes(e))),ciphertext:s})};exports.encryptSealedKeys=a,exports.pack=i;
1
+ const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require(`../../../shims/libsodium-wrappers.cjs`);let n=require(`ethers`);var r=e.__toESM(t.default),i=()=>r.default.crypto_box_SEALBYTES+r.default.crypto_secretbox_KEYBYTES,a=({nonce:e,sealedKeys:t,ciphertext:n})=>{let r=t.length,a=new Uint8Array(1+e.length+r*i()+n.length),o=0;return a[o]=r,o+=1,a.set(e,o),o+=e.length,t.forEach(e=>{a.set(e,o),o+=e.length}),a.set(n,o),a},o=(e,t)=>{let i=r.default.crypto_secretbox_keygen(),o=r.default.randombytes_buf(r.default.crypto_secretbox_NONCEBYTES),s=r.default.crypto_secretbox_easy(e,o,i);return a({nonce:o,sealedKeys:t.map(e=>r.default.crypto_box_seal(i,n.ethers.getBytes(e))),ciphertext:s})};exports.encryptSealedKeys=o,exports.pack=a;
@@ -1,18 +1,19 @@
1
- import { ethers as e } from "ethers";
2
- import t from "libsodium-wrappers";
1
+ import { __toESM as e } from "../../../_virtual/_rolldown/runtime.mjs";
2
+ import { require_libsodium_wrappers as t } from "../../../shims/libsodium-wrappers.mjs";
3
+ import { ethers as n } from "ethers";
3
4
  //#region common/src/crypto/ecdh-sealed-keys.ts
4
- var n = () => t.crypto_box_SEALBYTES + t.crypto_secretbox_KEYBYTES, r = ({ nonce: e, sealedKeys: t, ciphertext: r }) => {
5
- let i = t.length, a = new Uint8Array(1 + e.length + i * n() + r.length), o = 0;
6
- return a[o] = i, o += 1, a.set(e, o), o += e.length, t.forEach((e) => {
5
+ var r = /* @__PURE__ */ e(t()), i = () => r.default.crypto_box_SEALBYTES + r.default.crypto_secretbox_KEYBYTES, a = ({ nonce: e, sealedKeys: t, ciphertext: n }) => {
6
+ let r = t.length, a = new Uint8Array(1 + e.length + r * i() + n.length), o = 0;
7
+ return a[o] = r, o += 1, a.set(e, o), o += e.length, t.forEach((e) => {
7
8
  a.set(e, o), o += e.length;
8
- }), a.set(r, o), a;
9
- }, i = (n, i) => {
10
- let a = t.crypto_secretbox_keygen(), o = t.randombytes_buf(t.crypto_secretbox_NONCEBYTES), s = t.crypto_secretbox_easy(n, o, a);
11
- return r({
9
+ }), a.set(n, o), a;
10
+ }, o = (e, t) => {
11
+ let i = r.default.crypto_secretbox_keygen(), o = r.default.randombytes_buf(r.default.crypto_secretbox_NONCEBYTES), s = r.default.crypto_secretbox_easy(e, o, i);
12
+ return a({
12
13
  nonce: o,
13
- sealedKeys: i.map((n) => t.crypto_box_seal(a, e.getBytes(n))),
14
+ sealedKeys: t.map((e) => r.default.crypto_box_seal(i, n.getBytes(e))),
14
15
  ciphertext: s
15
16
  });
16
17
  };
17
18
  //#endregion
18
- export { i as encryptSealedKeys, r as pack };
19
+ export { o as encryptSealedKeys, a as pack };
@@ -1 +1 @@
1
- const e=require("../../../_virtual/_rolldown/runtime.cjs");require(`ethers`);let t=require(`libsodium-wrappers`);t=e.__toESM(t);
1
+ require("../../../_virtual/_rolldown/runtime.cjs");const e=require(`../../../shims/libsodium-wrappers.cjs`);require(`ethers`),e.default;
@@ -1,2 +1,5 @@
1
+ import "../../../_virtual/_rolldown/runtime.mjs";
2
+ import { require_libsodium_wrappers as e } from "../../../shims/libsodium-wrappers.mjs";
1
3
  import "ethers";
2
- import "libsodium-wrappers";
4
+ e();
5
+ //#endregion
@@ -1 +1,2 @@
1
- const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require(`./poseidon.cjs`),n=require(`./babyJub.cjs`),r=require(`./eddsa.cjs`);let i=require(`buffer`),a=require(`libsodium-wrappers`);a=e.__toESM(a);let o=require(`process`);o=e.__toESM(o);var s=async(e=!1)=>{(typeof window<`u`||typeof self<`u`)&&(typeof window<`u`&&(window.global=window),globalThis.Buffer=i.Buffer,globalThis.process=o.default),await Promise.all([a.default.ready,t.poseidonHolder.init(),n.jubHolder.init(),...e?[]:[r.eddsaHolder.init()]])};exports.preProcessing=s;
1
+ require("../../../bootstrap.cjs");
2
+ const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require(`./poseidon.cjs`),n=require(`../../../shims/libsodium-wrappers.cjs`),r=require(`./babyJub.cjs`),i=require(`./eddsa.cjs`);let a=require(`buffer`),o=require(`process`);o=e.__toESM(o);var s=e.__toESM(n.default),c=async(e=!1)=>{(typeof window<`u`||typeof self<`u`)&&(typeof window<`u`&&(window.global=window),globalThis.Buffer=a.Buffer,globalThis.process=o.default,delete globalThis.process?.versions?.node),await Promise.all([s.default.ready,t.poseidonHolder.init(),r.jubHolder.init(),...e?[]:[i.eddsaHolder.init()]])};exports.preProcessing=c;
@@ -1,17 +1,19 @@
1
- import { poseidonHolder as e } from "./poseidon.mjs";
2
- import { jubHolder as t } from "./babyJub.mjs";
3
- import { eddsaHolder as n } from "./eddsa.mjs";
4
- import { Buffer as r } from "buffer";
5
- import i from "libsodium-wrappers";
6
- import a from "process";
1
+ import "../../../bootstrap.mjs";
2
+ import { __toESM as e } from "../../../_virtual/_rolldown/runtime.mjs";
3
+ import { poseidonHolder as t } from "./poseidon.mjs";
4
+ import { require_libsodium_wrappers as n } from "../../../shims/libsodium-wrappers.mjs";
5
+ import { jubHolder as r } from "./babyJub.mjs";
6
+ import { eddsaHolder as i } from "./eddsa.mjs";
7
+ import { Buffer as a } from "buffer";
8
+ import o from "process";
7
9
  //#region common/src/crypto/preProcessing.ts
8
- var o = async (o = !1) => {
9
- (typeof window < "u" || typeof self < "u") && (typeof window < "u" && (window.global = window), globalThis.Buffer = r, globalThis.process = a), await Promise.all([
10
- i.ready,
11
- e.init(),
10
+ var s = /* @__PURE__ */ e(n()), c = async (e = !1) => {
11
+ (typeof window < "u" || typeof self < "u") && (typeof window < "u" && (window.global = window), globalThis.Buffer = a, globalThis.process=o,delete globalThis.process?.versions?.node), await Promise.all([
12
+ s.default.ready,
12
13
  t.init(),
13
- ...o ? [] : [n.init()]
14
+ r.init(),
15
+ ...e ? [] : [i.init()]
14
16
  ]);
15
17
  };
16
18
  //#endregion
17
- export { o as preProcessing };
19
+ export { c as preProcessing };
@@ -1 +1 @@
1
- const e=require("../../../../_virtual/_rolldown/runtime.cjs"),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../../crypto/babyJub.cjs`),i=require(`../../crypto/eddsa.cjs`),a=require(`../cacheDevices/AttachableMemoryCacheDevice.cjs`),o=require(`./keyUtils.cjs`);let s=require(`ethers`),c=require(`@solana/web3.js`),l=require(`bs58`);l=e.__toESM(l);let u=require(`libsodium-wrappers`);u=e.__toESM(u);let d=require(`tweetnacl`);d=e.__toESM(d);let f=require(`tronweb`);var p=new a.AttachableMemoryCacheDevice,m=new a.AttachableMemoryCacheDevice,h=new a.AttachableMemoryCacheDevice,g=class{signature;nullifyingKey;PREFIX_FOR_SPENDING_PAIR=`1`;PREFIX_FOR_NULLIFYING_PAIR=`2`;constructor(e,t){this.signature=e,this.nullifyingKey=t}getSignature(){return this.requireSignature(),this.signature}setSignature(e){this.signature=e}requireSignature(){if(!this.signature)throw Error(`No signature provided`)}requireKeyMaterial(){if(!this.signature&&!this.nullifyingKey)throw Error(`No signature or private key provided`)}verifyTronMessage(e,t){return this.requireSignature(),t===f.Trx.verifyMessageV2(e,this.signature)}getShieldedPrivateKey=()=>(this.requireKeyMaterial(),this.nullifyingKey||=s.ethers.keccak256(this.signature),this.nullifyingKey);getShieldedPublicKey=()=>(this.requireKeyMaterial(),n.poseidonHash(this.getShieldedPrivateKey()));getSpendingKeyPair=()=>{this.requireSignature();let e=i.eddsaInstance(),t=r.babyJubInstance(),a=n.poseidonHash(this.PREFIX_FOR_SPENDING_PAIR,this.getSignature()),o=Buffer.from(s.ethers.getBytes(a)),c=e.prv2pub(o);return{privSpendingKey:a,pubSpendingBJJPoint:[BigInt(t.F.toString(c[0])),BigInt(t.F.toString(c[1]))]}};signEddsa=e=>{this.requireSignature();let t=r.babyJubInstance(),n=i.eddsaInstance(),a=Buffer.from(s.ethers.getBytes(this.getSpendingKeyPair().privSpendingKey)),o=t.F.e(e),c=n.signPoseidon(a,o);return{R8:[BigInt(t.F.toString(c.R8[0])),BigInt(t.F.toString(c.R8[1]))],S:BigInt(c.S)}};getShieldedPrivateKeyFromNonce=e=>{this.requireKeyMaterial();let t=n.poseidonHash(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return s.ethers.keccak256(s.ethers.toUtf8Bytes(`hinkal-offchain-shielded-key:${t}`))};getClaimableSignatureFromNonce=e=>{this.requireKeyMaterial();let t=n.poseidonHash(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return s.ethers.keccak256(s.ethers.toUtf8Bytes(`hinkal-claimable-utxo-signature:${t}`))};getDerivedEthereumAddress=()=>(this.requireKeyMaterial(),new s.ethers.Wallet(this.getShieldedPrivateKey()).address);getDerivedSolanaPublicKey=()=>(this.requireKeyMaterial(),c.Keypair.fromSeed(s.ethers.getBytes(this.getShieldedPrivateKey())).publicKey.toBase58());getNearIntentsAccountId=()=>{this.requireKeyMaterial();let e=c.Keypair.fromSeed(s.ethers.getBytes(this.getShieldedPrivateKey()));return s.ethers.hexlify(e.publicKey.toBytes()).slice(2)};getNearIntentsKeyPairString=()=>{this.requireKeyMaterial();let e=c.Keypair.fromSeed(s.ethers.getBytes(this.getShieldedPrivateKey()));return`ed25519:${l.default.encode(e.secretKey)}`};getSignerPrivateKeyFromNonce=e=>{this.requireKeyMaterial();let t=n.poseidonHash(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return s.ethers.keccak256(s.ethers.toUtf8Bytes(t))};getSignerSolanaPrivateKeyFromNonce=e=>{let t=this.getSignerPrivateKeyFromNonce(e),n=s.ethers.getBytes(t),r=c.Keypair.fromSeed(n);return l.default.encode(r.secretKey)};verifyMessage(e){return this.requireSignature(),s.ethers.verifyMessage(e,this.signature)}verifySolanaMessage(e,t){this.requireSignature();let n=new TextEncoder().encode(e),r=s.ethers.getBytes(this.signature),i=new c.PublicKey(t).toBytes();return d.default.sign.detached.verify(n,r,i)}static getRandomizedStealthPairOld=m.attach((e,n)=>{let i=r.babyJubInstance(),a=e*(BigInt(n)%t.CIRCOM_P)%t.CIRCOM_P,o=i.mulPointEscalar(i.Base8,e),s=i.mulPointEscalar(i.Base8,a);return{H0:[BigInt(i.F.toString(o[0])),BigInt(i.F.toString(o[1]))],H1:[BigInt(i.F.toString(s[0])),BigInt(i.F.toString(s[1]))]}});static getRandomizedStealthPair=p.attach((e,n)=>{let i=r.babyJubInstance(),a=BigInt(n)%t.CIRCOM_P,o=i.mulPointEscalar(i.Base8,e),s=i.mulPointEscalar(o,a);return{H0:[BigInt(i.F.toString(o[0])),BigInt(i.F.toString(o[1]))],H1:[BigInt(i.F.toString(s[0])),BigInt(i.F.toString(s[1]))]}});static getStealthAddressCompressedPoints=(e,t)=>{let{H0:n,H1:r}=this.getRandomizedStealthPairOld(e,t),[i,a]=[n,r].map(e=>BigInt(e[1])+2n**255n*o.getCircomSign(e[0]));return{h0:i,h1:a}};static checkSignature=(e,t,n,r)=>{let{h0:i,h1:a}=this.getStealthAddressCompressedPoints(e,r);return t===i&&n===a};static getStealthAddress=h.attach((e,t)=>{let{H0:r,H1:i}=this.getRandomizedStealthPairOld(e,t);return n.poseidonHash(2n*o.getCircomSign(r[0])+o.getCircomSign(i[0]),r[1],i[1])});static getH1FromH0=(e,n)=>{let i=r.babyJubInstance(),a=BigInt(n)%t.CIRCOM_P,o=[i.F.e(e[0]),i.F.e(e[1])],s=i.mulPointEscalar(o,a);return[BigInt(i.F.toString(s[0])),BigInt(i.F.toString(s[1]))]};static verifyStealthPair=(e,t,n,r=!0)=>{let i=this.getH1FromH0(e,n);return r?i[1]===t[1]:i===t};static getStealthAddressNewStyle=(e,t,r)=>{if(r?.length!==2)throw Error(`Spending public key must be an array of 2 elements`);let i=this.getH1FromH0(e,t);return n.poseidonHash(2n*o.getCircomSign(e[0])+o.getCircomSign(i[0]),e[1],i[1],r[0],r[1],t)};static findCorrectRandomization(e,n){if(!n)throw Error(`No Private Shielded Key Provided`);let r=BigInt(n)%t.CIRCOM_P,i,a,o=0n;do i=e*10n**o%t.CIRCOM_P,a=i*r%t.CIRCOM_P,o+=1n;while(a>=2n**253n||i>=2n**253n);return i}static getH0FromRandomization=e=>{let t=r.babyJubInstance(),n=t.mulPointEscalar(t.Base8,e);return[BigInt(t.F.toString(n[0])),BigInt(t.F.toString(n[1]))]};static findH0(e,t){if(!t)return;let{H0:n}=this.getRandomizedStealthPair(e,t);return n}static getEncryptionKeyPair=e=>{let t=u.default.crypto_box_seed_keypair(s.ethers.getBytes(e));return{privateKey:s.ethers.hexlify(t.privateKey),publicKey:s.ethers.hexlify(t.publicKey)}};getAccessKey=()=>(this.requireKeyMaterial(),n.poseidonHash(this.getShieldedPrivateKey(),this.getShieldedPublicKey()));getBackendToken=()=>(this.requireKeyMaterial(),n.poseidonHash(this.getAccessKey(),this.getShieldedPublicKey()))};exports.UserKeys=g,exports.stealthAddressCacheDevice=h,exports.stealthPairCacheDevice=p,exports.stealthPairOldCacheDevice=m;
1
+ const e=require("../../../../_virtual/_rolldown/runtime.cjs"),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../../../../shims/libsodium-wrappers.cjs`),i=require(`../../crypto/babyJub.cjs`),a=require(`../../crypto/eddsa.cjs`),o=require(`../cacheDevices/AttachableMemoryCacheDevice.cjs`),s=require(`./keyUtils.cjs`);let c=require(`ethers`),l=require(`@solana/web3.js`),u=require(`bs58`);u=e.__toESM(u);let d=require(`tweetnacl`);d=e.__toESM(d);let f=require(`tronweb`);var p=e.__toESM(r.default),m=new o.AttachableMemoryCacheDevice,h=new o.AttachableMemoryCacheDevice,g=new o.AttachableMemoryCacheDevice,_=class{signature;nullifyingKey;PREFIX_FOR_SPENDING_PAIR=`1`;PREFIX_FOR_NULLIFYING_PAIR=`2`;constructor(e,t){this.signature=e,this.nullifyingKey=t}getSignature(){return this.requireSignature(),this.signature}setSignature(e){this.signature=e}requireSignature(){if(!this.signature)throw Error(`No signature provided`)}requireKeyMaterial(){if(!this.signature&&!this.nullifyingKey)throw Error(`No signature or private key provided`)}verifyTronMessage(e,t){return this.requireSignature(),t===f.Trx.verifyMessageV2(e,this.signature)}getShieldedPrivateKey=()=>(this.requireKeyMaterial(),this.nullifyingKey||=c.ethers.keccak256(this.signature),this.nullifyingKey);getShieldedPublicKey=()=>(this.requireKeyMaterial(),n.poseidonHash(this.getShieldedPrivateKey()));getSpendingKeyPair=()=>{this.requireSignature();let e=a.eddsaInstance(),t=i.babyJubInstance(),r=n.poseidonHash(this.PREFIX_FOR_SPENDING_PAIR,this.getSignature()),o=Buffer.from(c.ethers.getBytes(r)),s=e.prv2pub(o);return{privSpendingKey:r,pubSpendingBJJPoint:[BigInt(t.F.toString(s[0])),BigInt(t.F.toString(s[1]))]}};signEddsa=e=>{this.requireSignature();let t=i.babyJubInstance(),n=a.eddsaInstance(),r=Buffer.from(c.ethers.getBytes(this.getSpendingKeyPair().privSpendingKey)),o=t.F.e(e),s=n.signPoseidon(r,o);return{R8:[BigInt(t.F.toString(s.R8[0])),BigInt(t.F.toString(s.R8[1]))],S:BigInt(s.S)}};getShieldedPrivateKeyFromNonce=e=>{this.requireKeyMaterial();let t=n.poseidonHash(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return c.ethers.keccak256(c.ethers.toUtf8Bytes(`hinkal-offchain-shielded-key:${t}`))};getClaimableSignatureFromNonce=e=>{this.requireKeyMaterial();let t=n.poseidonHash(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return c.ethers.keccak256(c.ethers.toUtf8Bytes(`hinkal-claimable-utxo-signature:${t}`))};getDerivedEthereumAddress=()=>(this.requireKeyMaterial(),new c.ethers.Wallet(this.getShieldedPrivateKey()).address);getDerivedSolanaPublicKey=()=>(this.requireKeyMaterial(),l.Keypair.fromSeed(c.ethers.getBytes(this.getShieldedPrivateKey())).publicKey.toBase58());getNearIntentsAccountId=()=>{this.requireKeyMaterial();let e=l.Keypair.fromSeed(c.ethers.getBytes(this.getShieldedPrivateKey()));return c.ethers.hexlify(e.publicKey.toBytes()).slice(2)};getNearIntentsKeyPairString=()=>{this.requireKeyMaterial();let e=l.Keypair.fromSeed(c.ethers.getBytes(this.getShieldedPrivateKey()));return`ed25519:${u.default.encode(e.secretKey)}`};getSignerPrivateKeyFromNonce=e=>{this.requireKeyMaterial();let t=n.poseidonHash(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return c.ethers.keccak256(c.ethers.toUtf8Bytes(t))};getSignerSolanaPrivateKeyFromNonce=e=>{let t=this.getSignerPrivateKeyFromNonce(e),n=c.ethers.getBytes(t),r=l.Keypair.fromSeed(n);return u.default.encode(r.secretKey)};verifyMessage(e){return this.requireSignature(),c.ethers.verifyMessage(e,this.signature)}verifySolanaMessage(e,t){this.requireSignature();let n=new TextEncoder().encode(e),r=c.ethers.getBytes(this.signature),i=new l.PublicKey(t).toBytes();return d.default.sign.detached.verify(n,r,i)}static getRandomizedStealthPairOld=h.attach((e,n)=>{let r=i.babyJubInstance(),a=e*(BigInt(n)%t.CIRCOM_P)%t.CIRCOM_P,o=r.mulPointEscalar(r.Base8,e),s=r.mulPointEscalar(r.Base8,a);return{H0:[BigInt(r.F.toString(o[0])),BigInt(r.F.toString(o[1]))],H1:[BigInt(r.F.toString(s[0])),BigInt(r.F.toString(s[1]))]}});static getRandomizedStealthPair=m.attach((e,n)=>{let r=i.babyJubInstance(),a=BigInt(n)%t.CIRCOM_P,o=r.mulPointEscalar(r.Base8,e),s=r.mulPointEscalar(o,a);return{H0:[BigInt(r.F.toString(o[0])),BigInt(r.F.toString(o[1]))],H1:[BigInt(r.F.toString(s[0])),BigInt(r.F.toString(s[1]))]}});static getStealthAddressCompressedPoints=(e,t)=>{let{H0:n,H1:r}=this.getRandomizedStealthPairOld(e,t),[i,a]=[n,r].map(e=>BigInt(e[1])+2n**255n*s.getCircomSign(e[0]));return{h0:i,h1:a}};static checkSignature=(e,t,n,r)=>{let{h0:i,h1:a}=this.getStealthAddressCompressedPoints(e,r);return t===i&&n===a};static getStealthAddress=g.attach((e,t)=>{let{H0:r,H1:i}=this.getRandomizedStealthPairOld(e,t);return n.poseidonHash(2n*s.getCircomSign(r[0])+s.getCircomSign(i[0]),r[1],i[1])});static getH1FromH0=(e,n)=>{let r=i.babyJubInstance(),a=BigInt(n)%t.CIRCOM_P,o=[r.F.e(e[0]),r.F.e(e[1])],s=r.mulPointEscalar(o,a);return[BigInt(r.F.toString(s[0])),BigInt(r.F.toString(s[1]))]};static verifyStealthPair=(e,t,n,r=!0)=>{let i=this.getH1FromH0(e,n);return r?i[1]===t[1]:i===t};static getStealthAddressNewStyle=(e,t,r)=>{if(r?.length!==2)throw Error(`Spending public key must be an array of 2 elements`);let i=this.getH1FromH0(e,t);return n.poseidonHash(2n*s.getCircomSign(e[0])+s.getCircomSign(i[0]),e[1],i[1],r[0],r[1],t)};static findCorrectRandomization(e,n){if(!n)throw Error(`No Private Shielded Key Provided`);let r=BigInt(n)%t.CIRCOM_P,i,a,o=0n;do i=e*10n**o%t.CIRCOM_P,a=i*r%t.CIRCOM_P,o+=1n;while(a>=2n**253n||i>=2n**253n);return i}static getH0FromRandomization=e=>{let t=i.babyJubInstance(),n=t.mulPointEscalar(t.Base8,e);return[BigInt(t.F.toString(n[0])),BigInt(t.F.toString(n[1]))]};static findH0(e,t){if(!t)return;let{H0:n}=this.getRandomizedStealthPair(e,t);return n}static getEncryptionKeyPair=e=>{let t=p.default.crypto_box_seed_keypair(c.ethers.getBytes(e));return{privateKey:c.ethers.hexlify(t.privateKey),publicKey:c.ethers.hexlify(t.publicKey)}};getAccessKey=()=>(this.requireKeyMaterial(),n.poseidonHash(this.getShieldedPrivateKey(),this.getShieldedPublicKey()));getBackendToken=()=>(this.requireKeyMaterial(),n.poseidonHash(this.getAccessKey(),this.getShieldedPublicKey()))};exports.UserKeys=_,exports.stealthAddressCacheDevice=g,exports.stealthPairCacheDevice=m,exports.stealthPairOldCacheDevice=h;
@@ -1,17 +1,18 @@
1
- import { CIRCOM_P as e } from "../../constants/protocol.constants.mjs";
2
- import { poseidonHash as t } from "../../crypto/poseidon.mjs";
3
- import { babyJubInstance as n } from "../../crypto/babyJub.mjs";
4
- import { eddsaInstance as r } from "../../crypto/eddsa.mjs";
5
- import { AttachableMemoryCacheDevice as i } from "../cacheDevices/AttachableMemoryCacheDevice.mjs";
6
- import { getCircomSign as a } from "./keyUtils.mjs";
7
- import { ethers as o } from "ethers";
8
- import { Keypair as s, PublicKey as c } from "@solana/web3.js";
9
- import l from "bs58";
10
- import u from "libsodium-wrappers";
11
- import d from "tweetnacl";
12
- import { Trx as f } from "tronweb";
1
+ import { __toESM as e } from "../../../../_virtual/_rolldown/runtime.mjs";
2
+ import { CIRCOM_P as t } from "../../constants/protocol.constants.mjs";
3
+ import { poseidonHash as n } from "../../crypto/poseidon.mjs";
4
+ import { require_libsodium_wrappers as r } from "../../../../shims/libsodium-wrappers.mjs";
5
+ import { babyJubInstance as i } from "../../crypto/babyJub.mjs";
6
+ import { eddsaInstance as a } from "../../crypto/eddsa.mjs";
7
+ import { AttachableMemoryCacheDevice as o } from "../cacheDevices/AttachableMemoryCacheDevice.mjs";
8
+ import { getCircomSign as s } from "./keyUtils.mjs";
9
+ import { ethers as c } from "ethers";
10
+ import { Keypair as l, PublicKey as u } from "@solana/web3.js";
11
+ import d from "bs58";
12
+ import f from "tweetnacl";
13
+ import { Trx as p } from "tronweb";
13
14
  //#region common/src/data-structures/crypto-keys/keys.ts
14
- var p = new i(), m = new i(), h = new i(), g = class {
15
+ var m = /* @__PURE__ */ e(r()), h = new o(), g = new o(), _ = new o(), v = class {
15
16
  signature;
16
17
  nullifyingKey;
17
18
  PREFIX_FOR_SPENDING_PAIR = "1";
@@ -32,118 +33,118 @@ var p = new i(), m = new i(), h = new i(), g = class {
32
33
  if (!this.signature && !this.nullifyingKey) throw Error("No signature or private key provided");
33
34
  }
34
35
  verifyTronMessage(e, t) {
35
- return this.requireSignature(), t === f.verifyMessageV2(e, this.signature);
36
+ return this.requireSignature(), t === p.verifyMessageV2(e, this.signature);
36
37
  }
37
- getShieldedPrivateKey = () => (this.requireKeyMaterial(), this.nullifyingKey ||= o.keccak256(this.signature), this.nullifyingKey);
38
- getShieldedPublicKey = () => (this.requireKeyMaterial(), t(this.getShieldedPrivateKey()));
38
+ getShieldedPrivateKey = () => (this.requireKeyMaterial(), this.nullifyingKey ||= c.keccak256(this.signature), this.nullifyingKey);
39
+ getShieldedPublicKey = () => (this.requireKeyMaterial(), n(this.getShieldedPrivateKey()));
39
40
  getSpendingKeyPair = () => {
40
41
  this.requireSignature();
41
- let e = r(), i = n(), a = t(this.PREFIX_FOR_SPENDING_PAIR, this.getSignature()), s = Buffer.from(o.getBytes(a)), c = e.prv2pub(s);
42
+ let e = a(), t = i(), r = n(this.PREFIX_FOR_SPENDING_PAIR, this.getSignature()), o = Buffer.from(c.getBytes(r)), s = e.prv2pub(o);
42
43
  return {
43
- privSpendingKey: a,
44
- pubSpendingBJJPoint: [BigInt(i.F.toString(c[0])), BigInt(i.F.toString(c[1]))]
44
+ privSpendingKey: r,
45
+ pubSpendingBJJPoint: [BigInt(t.F.toString(s[0])), BigInt(t.F.toString(s[1]))]
45
46
  };
46
47
  };
47
48
  signEddsa = (e) => {
48
49
  this.requireSignature();
49
- let t = n(), i = r(), a = Buffer.from(o.getBytes(this.getSpendingKeyPair().privSpendingKey)), s = t.F.e(e), c = i.signPoseidon(a, s);
50
+ let t = i(), n = a(), r = Buffer.from(c.getBytes(this.getSpendingKeyPair().privSpendingKey)), o = t.F.e(e), s = n.signPoseidon(r, o);
50
51
  return {
51
- R8: [BigInt(t.F.toString(c.R8[0])), BigInt(t.F.toString(c.R8[1]))],
52
- S: BigInt(c.S)
52
+ R8: [BigInt(t.F.toString(s.R8[0])), BigInt(t.F.toString(s.R8[1]))],
53
+ S: BigInt(s.S)
53
54
  };
54
55
  };
55
56
  getShieldedPrivateKeyFromNonce = (e) => {
56
57
  this.requireKeyMaterial();
57
- let n = t(e, this.getShieldedPrivateKey(), this.getShieldedPublicKey());
58
- return o.keccak256(o.toUtf8Bytes(`hinkal-offchain-shielded-key:${n}`));
58
+ let t = n(e, this.getShieldedPrivateKey(), this.getShieldedPublicKey());
59
+ return c.keccak256(c.toUtf8Bytes(`hinkal-offchain-shielded-key:${t}`));
59
60
  };
60
61
  getClaimableSignatureFromNonce = (e) => {
61
62
  this.requireKeyMaterial();
62
- let n = t(e, this.getShieldedPrivateKey(), this.getShieldedPublicKey());
63
- return o.keccak256(o.toUtf8Bytes(`hinkal-claimable-utxo-signature:${n}`));
63
+ let t = n(e, this.getShieldedPrivateKey(), this.getShieldedPublicKey());
64
+ return c.keccak256(c.toUtf8Bytes(`hinkal-claimable-utxo-signature:${t}`));
64
65
  };
65
- getDerivedEthereumAddress = () => (this.requireKeyMaterial(), new o.Wallet(this.getShieldedPrivateKey()).address);
66
- getDerivedSolanaPublicKey = () => (this.requireKeyMaterial(), s.fromSeed(o.getBytes(this.getShieldedPrivateKey())).publicKey.toBase58());
66
+ getDerivedEthereumAddress = () => (this.requireKeyMaterial(), new c.Wallet(this.getShieldedPrivateKey()).address);
67
+ getDerivedSolanaPublicKey = () => (this.requireKeyMaterial(), l.fromSeed(c.getBytes(this.getShieldedPrivateKey())).publicKey.toBase58());
67
68
  getNearIntentsAccountId = () => {
68
69
  this.requireKeyMaterial();
69
- let e = s.fromSeed(o.getBytes(this.getShieldedPrivateKey()));
70
- return o.hexlify(e.publicKey.toBytes()).slice(2);
70
+ let e = l.fromSeed(c.getBytes(this.getShieldedPrivateKey()));
71
+ return c.hexlify(e.publicKey.toBytes()).slice(2);
71
72
  };
72
73
  getNearIntentsKeyPairString = () => {
73
74
  this.requireKeyMaterial();
74
- let e = s.fromSeed(o.getBytes(this.getShieldedPrivateKey()));
75
- return `ed25519:${l.encode(e.secretKey)}`;
75
+ let e = l.fromSeed(c.getBytes(this.getShieldedPrivateKey()));
76
+ return `ed25519:${d.encode(e.secretKey)}`;
76
77
  };
77
78
  getSignerPrivateKeyFromNonce = (e) => {
78
79
  this.requireKeyMaterial();
79
- let n = t(e, this.getShieldedPrivateKey(), this.getShieldedPublicKey());
80
- return o.keccak256(o.toUtf8Bytes(n));
80
+ let t = n(e, this.getShieldedPrivateKey(), this.getShieldedPublicKey());
81
+ return c.keccak256(c.toUtf8Bytes(t));
81
82
  };
82
83
  getSignerSolanaPrivateKeyFromNonce = (e) => {
83
- let t = this.getSignerPrivateKeyFromNonce(e), n = o.getBytes(t), r = s.fromSeed(n);
84
- return l.encode(r.secretKey);
84
+ let t = this.getSignerPrivateKeyFromNonce(e), n = c.getBytes(t), r = l.fromSeed(n);
85
+ return d.encode(r.secretKey);
85
86
  };
86
87
  verifyMessage(e) {
87
- return this.requireSignature(), o.verifyMessage(e, this.signature);
88
+ return this.requireSignature(), c.verifyMessage(e, this.signature);
88
89
  }
89
90
  verifySolanaMessage(e, t) {
90
91
  this.requireSignature();
91
- let n = new TextEncoder().encode(e), r = o.getBytes(this.signature), i = new c(t).toBytes();
92
- return d.sign.detached.verify(n, r, i);
92
+ let n = new TextEncoder().encode(e), r = c.getBytes(this.signature), i = new u(t).toBytes();
93
+ return f.sign.detached.verify(n, r, i);
93
94
  }
94
- static getRandomizedStealthPairOld = m.attach((t, r) => {
95
- let i = n(), a = t * (BigInt(r) % e) % e, o = i.mulPointEscalar(i.Base8, t), s = i.mulPointEscalar(i.Base8, a);
95
+ static getRandomizedStealthPairOld = g.attach((e, n) => {
96
+ let r = i(), a = e * (BigInt(n) % t) % t, o = r.mulPointEscalar(r.Base8, e), s = r.mulPointEscalar(r.Base8, a);
96
97
  return {
97
- H0: [BigInt(i.F.toString(o[0])), BigInt(i.F.toString(o[1]))],
98
- H1: [BigInt(i.F.toString(s[0])), BigInt(i.F.toString(s[1]))]
98
+ H0: [BigInt(r.F.toString(o[0])), BigInt(r.F.toString(o[1]))],
99
+ H1: [BigInt(r.F.toString(s[0])), BigInt(r.F.toString(s[1]))]
99
100
  };
100
101
  });
101
- static getRandomizedStealthPair = p.attach((t, r) => {
102
- let i = n(), a = BigInt(r) % e, o = i.mulPointEscalar(i.Base8, t), s = i.mulPointEscalar(o, a);
102
+ static getRandomizedStealthPair = h.attach((e, n) => {
103
+ let r = i(), a = BigInt(n) % t, o = r.mulPointEscalar(r.Base8, e), s = r.mulPointEscalar(o, a);
103
104
  return {
104
- H0: [BigInt(i.F.toString(o[0])), BigInt(i.F.toString(o[1]))],
105
- H1: [BigInt(i.F.toString(s[0])), BigInt(i.F.toString(s[1]))]
105
+ H0: [BigInt(r.F.toString(o[0])), BigInt(r.F.toString(o[1]))],
106
+ H1: [BigInt(r.F.toString(s[0])), BigInt(r.F.toString(s[1]))]
106
107
  };
107
108
  });
108
109
  static getStealthAddressCompressedPoints = (e, t) => {
109
- let { H0: n, H1: r } = this.getRandomizedStealthPairOld(e, t), [i, o] = [n, r].map((e) => BigInt(e[1]) + 2n ** 255n * a(e[0]));
110
+ let { H0: n, H1: r } = this.getRandomizedStealthPairOld(e, t), [i, a] = [n, r].map((e) => BigInt(e[1]) + 2n ** 255n * s(e[0]));
110
111
  return {
111
112
  h0: i,
112
- h1: o
113
+ h1: a
113
114
  };
114
115
  };
115
116
  static checkSignature = (e, t, n, r) => {
116
117
  let { h0: i, h1: a } = this.getStealthAddressCompressedPoints(e, r);
117
118
  return t === i && n === a;
118
119
  };
119
- static getStealthAddress = h.attach((e, n) => {
120
- let { H0: r, H1: i } = this.getRandomizedStealthPairOld(e, n);
121
- return t(2n * a(r[0]) + a(i[0]), r[1], i[1]);
120
+ static getStealthAddress = _.attach((e, t) => {
121
+ let { H0: r, H1: i } = this.getRandomizedStealthPairOld(e, t);
122
+ return n(2n * s(r[0]) + s(i[0]), r[1], i[1]);
122
123
  });
123
- static getH1FromH0 = (t, r) => {
124
- let i = n(), a = BigInt(r) % e, o = [i.F.e(t[0]), i.F.e(t[1])], s = i.mulPointEscalar(o, a);
125
- return [BigInt(i.F.toString(s[0])), BigInt(i.F.toString(s[1]))];
124
+ static getH1FromH0 = (e, n) => {
125
+ let r = i(), a = BigInt(n) % t, o = [r.F.e(e[0]), r.F.e(e[1])], s = r.mulPointEscalar(o, a);
126
+ return [BigInt(r.F.toString(s[0])), BigInt(r.F.toString(s[1]))];
126
127
  };
127
128
  static verifyStealthPair = (e, t, n, r = !0) => {
128
129
  let i = this.getH1FromH0(e, n);
129
130
  return r ? i[1] === t[1] : i === t;
130
131
  };
131
- static getStealthAddressNewStyle = (e, n, r) => {
132
+ static getStealthAddressNewStyle = (e, t, r) => {
132
133
  if (r?.length !== 2) throw Error("Spending public key must be an array of 2 elements");
133
- let i = this.getH1FromH0(e, n);
134
- return t(2n * a(e[0]) + a(i[0]), e[1], i[1], r[0], r[1], n);
134
+ let i = this.getH1FromH0(e, t);
135
+ return n(2n * s(e[0]) + s(i[0]), e[1], i[1], r[0], r[1], t);
135
136
  };
136
- static findCorrectRandomization(t, n) {
137
+ static findCorrectRandomization(e, n) {
137
138
  if (!n) throw Error("No Private Shielded Key Provided");
138
- let r = BigInt(n) % e, i, a, o = 0n;
139
+ let r = BigInt(n) % t, i, a, o = 0n;
139
140
  do
140
- i = t * 10n ** o % e, a = i * r % e, o += 1n;
141
+ i = e * 10n ** o % t, a = i * r % t, o += 1n;
141
142
  while (a >= 2n ** 253n || i >= 2n ** 253n);
142
143
  return i;
143
144
  }
144
145
  static getH0FromRandomization = (e) => {
145
- let t = n(), r = t.mulPointEscalar(t.Base8, e);
146
- return [BigInt(t.F.toString(r[0])), BigInt(t.F.toString(r[1]))];
146
+ let t = i(), n = t.mulPointEscalar(t.Base8, e);
147
+ return [BigInt(t.F.toString(n[0])), BigInt(t.F.toString(n[1]))];
147
148
  };
148
149
  static findH0(e, t) {
149
150
  if (!t) return;
@@ -151,14 +152,14 @@ var p = new i(), m = new i(), h = new i(), g = class {
151
152
  return n;
152
153
  }
153
154
  static getEncryptionKeyPair = (e) => {
154
- let t = u.crypto_box_seed_keypair(o.getBytes(e));
155
+ let t = m.default.crypto_box_seed_keypair(c.getBytes(e));
155
156
  return {
156
- privateKey: o.hexlify(t.privateKey),
157
- publicKey: o.hexlify(t.publicKey)
157
+ privateKey: c.hexlify(t.privateKey),
158
+ publicKey: c.hexlify(t.publicKey)
158
159
  };
159
160
  };
160
- getAccessKey = () => (this.requireKeyMaterial(), t(this.getShieldedPrivateKey(), this.getShieldedPublicKey()));
161
- getBackendToken = () => (this.requireKeyMaterial(), t(this.getAccessKey(), this.getShieldedPublicKey()));
161
+ getAccessKey = () => (this.requireKeyMaterial(), n(this.getShieldedPrivateKey(), this.getShieldedPublicKey()));
162
+ getBackendToken = () => (this.requireKeyMaterial(), n(this.getAccessKey(), this.getShieldedPublicKey()));
162
163
  };
163
164
  //#endregion
164
- export { g as UserKeys, h as stealthAddressCacheDevice, p as stealthPairCacheDevice, m as stealthPairOldCacheDevice };
165
+ export { v as UserKeys, _ as stealthAddressCacheDevice, h as stealthPairCacheDevice, g as stealthPairOldCacheDevice };
@@ -1 +1 @@
1
- const e=require("../../../../_virtual/_rolldown/runtime.cjs"),t=require(`./serialize.utils.cjs`),n=require(`./enclaveHandshakeService.cjs`);let r=require(`ethers`),i=require(`libsodium-wrappers`);i=e.__toESM(i);let a=require(`node-forge`);a=e.__toESM(a);var o=e=>typeof e==`bigint`||typeof e==`number`?e.toString():e,s=e=>a.util.hexToBytes(e.replace(`0x`,``)),c=e=>{let t=structuredClone(e);return Object.entries(t).forEach(([e,n])=>{t[e]=o(n),Array.isArray(n)&&(Array.isArray(n[0])?t[e]=n.map(e=>e.map(o)):t[e]=n.map(o))}),t},l=(e,t)=>{let n=a.util.decode64(e),r=a.asn1.fromDer(a.util.createBuffer(n)),i=a.pki.publicKeyFromAsn1(r),o=a.util.binary.raw.encode(t),s=i.encrypt(o,`RSA-OAEP`,{md:a.md.sha1.create(),mgf1:{md:a.md.sha1.create()}});return a.util.encode64(s)},u=(e,t)=>{let n=i.default.randombytes_buf(i.default.crypto_secretbox_NONCEBYTES),o=i.default.crypto_secretbox_easy(t,n,e),c=s(r.ethers.hexlify(n)+r.ethers.hexlify(o).slice(2));return a.util.encode64(c)},d=(e,t)=>{let n=i.default.randombytes_buf(i.default.crypto_secretbox_KEYBYTES);return{keyCiphertext:l(t,n),inputCiphertext:u(n,e)}},f=(e,n)=>{let r=typeof e==`string`?e:t.safeJsonStringify(c(e));return d(new TextEncoder().encode(r),n)},p=async e=>f(e,await n.enclaveHandshakeService.getPublicKey()),m=async e=>d(e,await n.enclaveHandshakeService.getPublicKey());exports.makeEnclaveHandshakeAndEncryptInput=p,exports.makeEnclaveHandshakeAndEncryptUint8Array=m;
1
+ const e=require("../../../../_virtual/_rolldown/runtime.cjs"),t=require(`./serialize.utils.cjs`),n=require(`../../../../shims/libsodium-wrappers.cjs`),r=require(`./enclaveHandshakeService.cjs`);let i=require(`ethers`),a=require(`node-forge`);a=e.__toESM(a);var o=e.__toESM(n.default),s=e=>typeof e==`bigint`||typeof e==`number`?e.toString():e,c=e=>a.util.hexToBytes(e.replace(`0x`,``)),l=e=>{let t=structuredClone(e);return Object.entries(t).forEach(([e,n])=>{t[e]=s(n),Array.isArray(n)&&(Array.isArray(n[0])?t[e]=n.map(e=>e.map(s)):t[e]=n.map(s))}),t},u=(e,t)=>{let n=a.util.decode64(e),r=a.asn1.fromDer(a.util.createBuffer(n)),i=a.pki.publicKeyFromAsn1(r),o=a.util.binary.raw.encode(t),s=i.encrypt(o,`RSA-OAEP`,{md:a.md.sha1.create(),mgf1:{md:a.md.sha1.create()}});return a.util.encode64(s)},d=(e,t)=>{let n=o.default.randombytes_buf(o.default.crypto_secretbox_NONCEBYTES),r=o.default.crypto_secretbox_easy(t,n,e),s=c(i.ethers.hexlify(n)+i.ethers.hexlify(r).slice(2));return a.util.encode64(s)},f=(e,t)=>{let n=o.default.randombytes_buf(o.default.crypto_secretbox_KEYBYTES);return{keyCiphertext:u(t,n),inputCiphertext:d(n,e)}},p=(e,n)=>{let r=typeof e==`string`?e:t.safeJsonStringify(l(e));return f(new TextEncoder().encode(r),n)},m=async e=>p(e,await r.enclaveHandshakeService.getPublicKey()),h=async e=>f(e,await r.enclaveHandshakeService.getPublicKey());exports.makeEnclaveHandshakeAndEncryptInput=m,exports.makeEnclaveHandshakeAndEncryptUint8Array=h;
@@ -1,32 +1,33 @@
1
- import { safeJsonStringify as e } from "./serialize.utils.mjs";
2
- import { enclaveHandshakeService as t } from "./enclaveHandshakeService.mjs";
3
- import { ethers as n } from "ethers";
4
- import r from "libsodium-wrappers";
5
- import * as i from "node-forge";
1
+ import { __toESM as e } from "../../../../_virtual/_rolldown/runtime.mjs";
2
+ import { safeJsonStringify as t } from "./serialize.utils.mjs";
3
+ import { require_libsodium_wrappers as n } from "../../../../shims/libsodium-wrappers.mjs";
4
+ import { enclaveHandshakeService as r } from "./enclaveHandshakeService.mjs";
5
+ import { ethers as i } from "ethers";
6
+ import * as a from "node-forge";
6
7
  //#region common/src/functions/utils/encryptInputForEnclave.ts
7
- var a = (e) => typeof e == "bigint" || typeof e == "number" ? e.toString() : e, o = (e) => i.util.hexToBytes(e.replace("0x", "")), s = (e) => {
8
+ var o = /* @__PURE__ */ e(n()), s = (e) => typeof e == "bigint" || typeof e == "number" ? e.toString() : e, c = (e) => a.util.hexToBytes(e.replace("0x", "")), l = (e) => {
8
9
  let t = structuredClone(e);
9
10
  return Object.entries(t).forEach(([e, n]) => {
10
- t[e] = a(n), Array.isArray(n) && (Array.isArray(n[0]) ? t[e] = n.map((e) => e.map(a)) : t[e] = n.map(a));
11
+ t[e] = s(n), Array.isArray(n) && (Array.isArray(n[0]) ? t[e] = n.map((e) => e.map(s)) : t[e] = n.map(s));
11
12
  }), t;
12
- }, c = (e, t) => {
13
- let n = i.util.decode64(e), r = i.asn1.fromDer(i.util.createBuffer(n)), a = i.pki.publicKeyFromAsn1(r), o = i.util.binary.raw.encode(t), s = a.encrypt(o, "RSA-OAEP", {
14
- md: i.md.sha1.create(),
15
- mgf1: { md: i.md.sha1.create() }
16
- });
17
- return i.util.encode64(s);
18
- }, l = (e, t) => {
19
- let a = r.randombytes_buf(r.crypto_secretbox_NONCEBYTES), s = r.crypto_secretbox_easy(t, a, e), c = o(n.hexlify(a) + n.hexlify(s).slice(2));
20
- return i.util.encode64(c);
21
13
  }, u = (e, t) => {
22
- let n = r.randombytes_buf(r.crypto_secretbox_KEYBYTES);
14
+ let n = a.util.decode64(e), r = a.asn1.fromDer(a.util.createBuffer(n)), i = a.pki.publicKeyFromAsn1(r), o = a.util.binary.raw.encode(t), s = i.encrypt(o, "RSA-OAEP", {
15
+ md: a.md.sha1.create(),
16
+ mgf1: { md: a.md.sha1.create() }
17
+ });
18
+ return a.util.encode64(s);
19
+ }, d = (e, t) => {
20
+ let n = o.default.randombytes_buf(o.default.crypto_secretbox_NONCEBYTES), r = o.default.crypto_secretbox_easy(t, n, e), s = c(i.hexlify(n) + i.hexlify(r).slice(2));
21
+ return a.util.encode64(s);
22
+ }, f = (e, t) => {
23
+ let n = o.default.randombytes_buf(o.default.crypto_secretbox_KEYBYTES);
23
24
  return {
24
- keyCiphertext: c(t, n),
25
- inputCiphertext: l(n, e)
25
+ keyCiphertext: u(t, n),
26
+ inputCiphertext: d(n, e)
26
27
  };
27
- }, d = (t, n) => {
28
- let r = typeof t == "string" ? t : e(s(t));
29
- return u(new TextEncoder().encode(r), n);
30
- }, f = async (e) => d(e, await t.getPublicKey()), p = async (e) => u(e, await t.getPublicKey());
28
+ }, p = (e, n) => {
29
+ let r = typeof e == "string" ? e : t(l(e));
30
+ return f(new TextEncoder().encode(r), n);
31
+ }, m = async (e) => p(e, await r.getPublicKey()), h = async (e) => f(e, await r.getPublicKey());
31
32
  //#endregion
32
- export { f as makeEnclaveHandshakeAndEncryptInput, p as makeEnclaveHandshakeAndEncryptUint8Array };
33
+ export { m as makeEnclaveHandshakeAndEncryptInput, h as makeEnclaveHandshakeAndEncryptUint8Array };
@@ -2,9 +2,9 @@
2
2
  const domain = 'https://storage.googleapis.com/hinkal-workers-staging';
3
3
 
4
4
  const WORKER_CDN_URLS = {
5
- ZKProof: domain + '/0.3.96/' + 'zkProofWorkerLauncher.js',
6
- SnarkJS: domain + '/0.3.96/' + 'snarkjsWorkerLauncher.js',
7
- UTXO: domain + '/0.3.96/' + 'utxoWorkerLauncher.js',
5
+ ZKProof: domain + '/0.3.105/' + 'zkProofWorkerLauncher.js',
6
+ SnarkJS: domain + '/0.3.105/' + 'snarkjsWorkerLauncher.js',
7
+ UTXO: domain + '/0.3.105/' + 'utxoWorkerLauncher.js',
8
8
  };
9
9
 
10
10
  // Returns a blob:// URL which points
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gurge/sdk-react-native",
3
- "version": "0.3.96",
3
+ "version": "0.3.105",
4
4
  "description": "Prebundled Hinkal SDK for React Native — no Metro config required.",
5
5
  "homepage": "hinkal.io",
6
6
  "author": {
@@ -47,7 +47,8 @@
47
47
  }
48
48
  },
49
49
  "scripts": {
50
- "build": "nx build sdk-react-native"
50
+ "build": "nx build sdk-react-native",
51
+ "postinstall": "node ./scripts/patch-libsodium-for-rn.js"
51
52
  },
52
53
  "dependencies": {
53
54
  "buffer": "6.0.3",
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Patches libsodium's Emscripten glue so Metro can bundle it on React Native.
3
+ * Replaces the static require("node:fs") (dead on Hermes) with a no-op — no Metro config needed.
4
+ */
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+
8
+ const PATCH_MARKER = '/* @hinkal/sdk-react-native: node:fs patched */';
9
+ const LIBSODIUM_FILE = path.join('libsodium', 'dist', 'modules', 'libsodium.js');
10
+
11
+ const patchFile = (filePath) => {
12
+ let content = fs.readFileSync(filePath, 'utf8');
13
+ if (content.includes(PATCH_MARKER)) return false;
14
+ if (!/require\(["']node:fs["']\)/.test(content)) return false;
15
+
16
+ content = `${PATCH_MARKER}\n${content.replace(/require\(["']node:fs["']\)/g, '({})')}`;
17
+ fs.writeFileSync(filePath, content);
18
+ return true;
19
+ };
20
+
21
+ const collectLibsodiumPaths = (startDir) => {
22
+ const found = new Set();
23
+ let dir = startDir;
24
+
25
+ for (let depth = 0; depth < 8 && dir; depth += 1) {
26
+ const nodeModules = path.join(dir, 'node_modules');
27
+ if (fs.existsSync(nodeModules)) {
28
+ const direct = path.join(nodeModules, LIBSODIUM_FILE);
29
+ if (fs.existsSync(direct)) found.add(direct);
30
+
31
+ for (const entry of fs.readdirSync(nodeModules, { withFileTypes: true })) {
32
+ if (!entry.isDirectory() || entry.name.startsWith('.')) continue;
33
+ const nested = path.join(nodeModules, entry.name, 'node_modules', LIBSODIUM_FILE);
34
+ if (fs.existsSync(nested)) found.add(nested);
35
+ }
36
+ }
37
+
38
+ const parent = path.dirname(dir);
39
+ if (parent === dir) break;
40
+ dir = parent;
41
+ }
42
+
43
+ return [...found];
44
+ };
45
+
46
+ const roots = new Set([__dirname, path.join(__dirname, '..'), process.cwd()]);
47
+ const targets = new Set();
48
+ for (const root of roots) {
49
+ for (const filePath of collectLibsodiumPaths(root)) targets.add(filePath);
50
+ }
51
+
52
+ let patched = 0;
53
+ for (const filePath of targets) {
54
+ if (patchFile(filePath)) {
55
+ patched += 1;
56
+ console.log(`[@hinkal/sdk] patched libsodium for React Native: ${filePath}`);
57
+ }
58
+ }
59
+
60
+ if (patched === 0 && targets.length === 0) {
61
+ console.warn('[@hinkal/sdk] libsodium not found — RN postinstall patch skipped (install libsodium-wrappers first)');
62
+ }
@@ -1,2 +1,2 @@
1
- // Static require so Metro can resolve it; subpath bypasses package "import" (ESM) exports.
1
+ // Static CJS subpath bypasses package "import" (ESM) exports. postinstall patches libsodium's node:fs require.
2
2
  module.exports = require("libsodium-wrappers/dist/modules/libsodium-wrappers.js");