@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 +1 -1
- package/bootstrap.mjs +1 -10
- package/common/src/crypto/ecdh-sealed-keys.cjs +1 -1
- package/common/src/crypto/ecdh-sealed-keys.mjs +12 -11
- package/common/src/crypto/ecdh.cjs +1 -1
- package/common/src/crypto/ecdh.mjs +4 -1
- package/common/src/crypto/preProcessing.cjs +2 -1
- package/common/src/crypto/preProcessing.mjs +14 -12
- package/common/src/data-structures/crypto-keys/keys.cjs +1 -1
- package/common/src/data-structures/crypto-keys/keys.mjs +70 -69
- package/common/src/functions/utils/encryptInputForEnclave.cjs +1 -1
- package/common/src/functions/utils/encryptInputForEnclave.mjs +25 -24
- package/common/src/webworker/viteWorkerURL.constant.mjs +3 -3
- package/package.json +3 -2
- package/scripts/patch-libsodium-for-rn.js +62 -0
- package/shims/libsodium-wrappers.cjs +1 -1
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`);
|
|
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
|
-
|
|
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")
|
|
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 {
|
|
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
|
|
5
|
-
let
|
|
6
|
-
return a[o] =
|
|
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(
|
|
9
|
-
},
|
|
10
|
-
let
|
|
11
|
-
return
|
|
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:
|
|
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 {
|
|
19
|
+
export { o as encryptSealedKeys, a as pack };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
require("../../../_virtual/_rolldown/runtime.cjs");const e=require(`../../../shims/libsodium-wrappers.cjs`);require(`ethers`),e.default;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
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
|
|
9
|
-
(typeof window < "u" || typeof self < "u") && (typeof window < "u" && (window.global = window), globalThis.Buffer =
|
|
10
|
-
|
|
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
|
-
|
|
14
|
+
r.init(),
|
|
15
|
+
...e ? [] : [i.init()]
|
|
14
16
|
]);
|
|
15
17
|
};
|
|
16
18
|
//#endregion
|
|
17
|
-
export {
|
|
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`),
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import u from "
|
|
11
|
-
import d from "
|
|
12
|
-
import
|
|
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
|
|
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 ===
|
|
36
|
+
return this.requireSignature(), t === p.verifyMessageV2(e, this.signature);
|
|
36
37
|
}
|
|
37
|
-
getShieldedPrivateKey = () => (this.requireKeyMaterial(), this.nullifyingKey ||=
|
|
38
|
-
getShieldedPublicKey = () => (this.requireKeyMaterial(),
|
|
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 =
|
|
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:
|
|
44
|
-
pubSpendingBJJPoint: [BigInt(
|
|
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 =
|
|
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(
|
|
52
|
-
S: BigInt(
|
|
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
|
|
58
|
-
return
|
|
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
|
|
63
|
-
return
|
|
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
|
|
66
|
-
getDerivedSolanaPublicKey = () => (this.requireKeyMaterial(),
|
|
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 =
|
|
70
|
-
return
|
|
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 =
|
|
75
|
-
return `ed25519:${
|
|
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
|
|
80
|
-
return
|
|
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 =
|
|
84
|
-
return
|
|
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(),
|
|
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 =
|
|
92
|
-
return
|
|
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 =
|
|
95
|
-
let
|
|
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(
|
|
98
|
-
H1: [BigInt(
|
|
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 =
|
|
102
|
-
let
|
|
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(
|
|
105
|
-
H1: [BigInt(
|
|
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,
|
|
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:
|
|
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 =
|
|
120
|
-
let { H0: r, H1: i } = this.getRandomizedStealthPairOld(e,
|
|
121
|
-
return
|
|
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 = (
|
|
124
|
-
let
|
|
125
|
-
return [BigInt(
|
|
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,
|
|
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,
|
|
134
|
-
return
|
|
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(
|
|
137
|
+
static findCorrectRandomization(e, n) {
|
|
137
138
|
if (!n) throw Error("No Private Shielded Key Provided");
|
|
138
|
-
let r = BigInt(n) %
|
|
139
|
+
let r = BigInt(n) % t, i, a, o = 0n;
|
|
139
140
|
do
|
|
140
|
-
i =
|
|
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 =
|
|
146
|
-
return [BigInt(t.F.toString(
|
|
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 =
|
|
155
|
+
let t = m.default.crypto_box_seed_keypair(c.getBytes(e));
|
|
155
156
|
return {
|
|
156
|
-
privateKey:
|
|
157
|
-
publicKey:
|
|
157
|
+
privateKey: c.hexlify(t.privateKey),
|
|
158
|
+
publicKey: c.hexlify(t.publicKey)
|
|
158
159
|
};
|
|
159
160
|
};
|
|
160
|
-
getAccessKey = () => (this.requireKeyMaterial(),
|
|
161
|
-
getBackendToken = () => (this.requireKeyMaterial(),
|
|
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 {
|
|
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
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import r from "
|
|
5
|
-
import
|
|
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
|
|
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] =
|
|
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.
|
|
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:
|
|
25
|
-
inputCiphertext:
|
|
25
|
+
keyCiphertext: u(t, n),
|
|
26
|
+
inputCiphertext: d(n, e)
|
|
26
27
|
};
|
|
27
|
-
},
|
|
28
|
-
let r = typeof
|
|
29
|
-
return
|
|
30
|
-
},
|
|
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 {
|
|
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.
|
|
6
|
-
SnarkJS: domain + '/0.3.
|
|
7
|
-
UTXO: domain + '/0.3.
|
|
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.
|
|
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
|
|
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");
|