@gurge/sdk-react-native 0.3.94 → 0.3.96
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/common/src/crypto/ecdh-sealed-keys.cjs +1 -1
- package/common/src/crypto/ecdh-sealed-keys.mjs +11 -12
- package/common/src/crypto/ecdh.cjs +1 -1
- package/common/src/crypto/ecdh.mjs +1 -4
- package/common/src/crypto/preProcessing.cjs +1 -1
- package/common/src/crypto/preProcessing.mjs +12 -13
- package/common/src/data-structures/crypto-keys/keys.cjs +1 -1
- package/common/src/data-structures/crypto-keys/keys.mjs +69 -70
- package/common/src/functions/utils/encryptInputForEnclave.cjs +1 -1
- package/common/src/functions/utils/encryptInputForEnclave.mjs +24 -25
- package/common/src/webworker/viteWorkerURL.constant.mjs +3 -3
- package/package.json +1 -1
- package/shims/libsodium-wrappers.cjs +2 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs")
|
|
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,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { ethers as n } from "ethers";
|
|
1
|
+
import { ethers as e } from "ethers";
|
|
2
|
+
import t from "libsodium-wrappers";
|
|
4
3
|
//#region common/src/crypto/ecdh-sealed-keys.ts
|
|
5
|
-
var
|
|
6
|
-
let
|
|
7
|
-
return a[o] =
|
|
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) => {
|
|
8
7
|
a.set(e, o), o += e.length;
|
|
9
|
-
}), a.set(
|
|
10
|
-
},
|
|
11
|
-
let
|
|
12
|
-
return
|
|
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({
|
|
13
12
|
nonce: o,
|
|
14
|
-
sealedKeys:
|
|
13
|
+
sealedKeys: i.map((n) => t.crypto_box_seal(a, e.getBytes(n))),
|
|
15
14
|
ciphertext: s
|
|
16
15
|
});
|
|
17
16
|
};
|
|
18
17
|
//#endregion
|
|
19
|
-
export {
|
|
18
|
+
export { i as encryptSealedKeys, r as pack };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require("../../../_virtual/_rolldown/runtime.cjs");
|
|
1
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs");require(`ethers`);let t=require(`libsodium-wrappers`);t=e.__toESM(t);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require(`./poseidon.cjs`),n=require(
|
|
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,18 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import o from "process";
|
|
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";
|
|
8
7
|
//#region common/src/crypto/preProcessing.ts
|
|
9
|
-
var
|
|
10
|
-
(typeof window < "u" || typeof self < "u") && (typeof window < "u" && (window.global = window), globalThis.Buffer =
|
|
11
|
-
|
|
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(),
|
|
12
12
|
t.init(),
|
|
13
|
-
|
|
14
|
-
...e ? [] : [i.init()]
|
|
13
|
+
...o ? [] : [n.init()]
|
|
15
14
|
]);
|
|
16
15
|
};
|
|
17
16
|
//#endregion
|
|
18
|
-
export {
|
|
17
|
+
export { o 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(
|
|
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,18 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import d from "
|
|
12
|
-
import f from "
|
|
13
|
-
import { Trx as p } from "tronweb";
|
|
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";
|
|
14
13
|
//#region common/src/data-structures/crypto-keys/keys.ts
|
|
15
|
-
var
|
|
14
|
+
var p = new i(), m = new i(), h = new i(), g = class {
|
|
16
15
|
signature;
|
|
17
16
|
nullifyingKey;
|
|
18
17
|
PREFIX_FOR_SPENDING_PAIR = "1";
|
|
@@ -33,118 +32,118 @@ var m = /* @__PURE__ */ e(r()), h = new o(), g = new o(), _ = new o(), v = class
|
|
|
33
32
|
if (!this.signature && !this.nullifyingKey) throw Error("No signature or private key provided");
|
|
34
33
|
}
|
|
35
34
|
verifyTronMessage(e, t) {
|
|
36
|
-
return this.requireSignature(), t ===
|
|
35
|
+
return this.requireSignature(), t === f.verifyMessageV2(e, this.signature);
|
|
37
36
|
}
|
|
38
|
-
getShieldedPrivateKey = () => (this.requireKeyMaterial(), this.nullifyingKey ||=
|
|
39
|
-
getShieldedPublicKey = () => (this.requireKeyMaterial(),
|
|
37
|
+
getShieldedPrivateKey = () => (this.requireKeyMaterial(), this.nullifyingKey ||= o.keccak256(this.signature), this.nullifyingKey);
|
|
38
|
+
getShieldedPublicKey = () => (this.requireKeyMaterial(), t(this.getShieldedPrivateKey()));
|
|
40
39
|
getSpendingKeyPair = () => {
|
|
41
40
|
this.requireSignature();
|
|
42
|
-
let e =
|
|
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);
|
|
43
42
|
return {
|
|
44
|
-
privSpendingKey:
|
|
45
|
-
pubSpendingBJJPoint: [BigInt(
|
|
43
|
+
privSpendingKey: a,
|
|
44
|
+
pubSpendingBJJPoint: [BigInt(i.F.toString(c[0])), BigInt(i.F.toString(c[1]))]
|
|
46
45
|
};
|
|
47
46
|
};
|
|
48
47
|
signEddsa = (e) => {
|
|
49
48
|
this.requireSignature();
|
|
50
|
-
let t =
|
|
49
|
+
let t = n(), i = r(), a = Buffer.from(o.getBytes(this.getSpendingKeyPair().privSpendingKey)), s = t.F.e(e), c = i.signPoseidon(a, s);
|
|
51
50
|
return {
|
|
52
|
-
R8: [BigInt(t.F.toString(
|
|
53
|
-
S: BigInt(
|
|
51
|
+
R8: [BigInt(t.F.toString(c.R8[0])), BigInt(t.F.toString(c.R8[1]))],
|
|
52
|
+
S: BigInt(c.S)
|
|
54
53
|
};
|
|
55
54
|
};
|
|
56
55
|
getShieldedPrivateKeyFromNonce = (e) => {
|
|
57
56
|
this.requireKeyMaterial();
|
|
58
|
-
let
|
|
59
|
-
return
|
|
57
|
+
let n = t(e, this.getShieldedPrivateKey(), this.getShieldedPublicKey());
|
|
58
|
+
return o.keccak256(o.toUtf8Bytes(`hinkal-offchain-shielded-key:${n}`));
|
|
60
59
|
};
|
|
61
60
|
getClaimableSignatureFromNonce = (e) => {
|
|
62
61
|
this.requireKeyMaterial();
|
|
63
|
-
let
|
|
64
|
-
return
|
|
62
|
+
let n = t(e, this.getShieldedPrivateKey(), this.getShieldedPublicKey());
|
|
63
|
+
return o.keccak256(o.toUtf8Bytes(`hinkal-claimable-utxo-signature:${n}`));
|
|
65
64
|
};
|
|
66
|
-
getDerivedEthereumAddress = () => (this.requireKeyMaterial(), new
|
|
67
|
-
getDerivedSolanaPublicKey = () => (this.requireKeyMaterial(),
|
|
65
|
+
getDerivedEthereumAddress = () => (this.requireKeyMaterial(), new o.Wallet(this.getShieldedPrivateKey()).address);
|
|
66
|
+
getDerivedSolanaPublicKey = () => (this.requireKeyMaterial(), s.fromSeed(o.getBytes(this.getShieldedPrivateKey())).publicKey.toBase58());
|
|
68
67
|
getNearIntentsAccountId = () => {
|
|
69
68
|
this.requireKeyMaterial();
|
|
70
|
-
let e =
|
|
71
|
-
return
|
|
69
|
+
let e = s.fromSeed(o.getBytes(this.getShieldedPrivateKey()));
|
|
70
|
+
return o.hexlify(e.publicKey.toBytes()).slice(2);
|
|
72
71
|
};
|
|
73
72
|
getNearIntentsKeyPairString = () => {
|
|
74
73
|
this.requireKeyMaterial();
|
|
75
|
-
let e =
|
|
76
|
-
return `ed25519:${
|
|
74
|
+
let e = s.fromSeed(o.getBytes(this.getShieldedPrivateKey()));
|
|
75
|
+
return `ed25519:${l.encode(e.secretKey)}`;
|
|
77
76
|
};
|
|
78
77
|
getSignerPrivateKeyFromNonce = (e) => {
|
|
79
78
|
this.requireKeyMaterial();
|
|
80
|
-
let
|
|
81
|
-
return
|
|
79
|
+
let n = t(e, this.getShieldedPrivateKey(), this.getShieldedPublicKey());
|
|
80
|
+
return o.keccak256(o.toUtf8Bytes(n));
|
|
82
81
|
};
|
|
83
82
|
getSignerSolanaPrivateKeyFromNonce = (e) => {
|
|
84
|
-
let t = this.getSignerPrivateKeyFromNonce(e), n =
|
|
85
|
-
return
|
|
83
|
+
let t = this.getSignerPrivateKeyFromNonce(e), n = o.getBytes(t), r = s.fromSeed(n);
|
|
84
|
+
return l.encode(r.secretKey);
|
|
86
85
|
};
|
|
87
86
|
verifyMessage(e) {
|
|
88
|
-
return this.requireSignature(),
|
|
87
|
+
return this.requireSignature(), o.verifyMessage(e, this.signature);
|
|
89
88
|
}
|
|
90
89
|
verifySolanaMessage(e, t) {
|
|
91
90
|
this.requireSignature();
|
|
92
|
-
let n = new TextEncoder().encode(e), r =
|
|
93
|
-
return
|
|
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);
|
|
94
93
|
}
|
|
95
|
-
static getRandomizedStealthPairOld =
|
|
96
|
-
let
|
|
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);
|
|
97
96
|
return {
|
|
98
|
-
H0: [BigInt(
|
|
99
|
-
H1: [BigInt(
|
|
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]))]
|
|
100
99
|
};
|
|
101
100
|
});
|
|
102
|
-
static getRandomizedStealthPair =
|
|
103
|
-
let
|
|
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);
|
|
104
103
|
return {
|
|
105
|
-
H0: [BigInt(
|
|
106
|
-
H1: [BigInt(
|
|
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]))]
|
|
107
106
|
};
|
|
108
107
|
});
|
|
109
108
|
static getStealthAddressCompressedPoints = (e, t) => {
|
|
110
|
-
let { H0: n, H1: r } = this.getRandomizedStealthPairOld(e, t), [i,
|
|
109
|
+
let { H0: n, H1: r } = this.getRandomizedStealthPairOld(e, t), [i, o] = [n, r].map((e) => BigInt(e[1]) + 2n ** 255n * a(e[0]));
|
|
111
110
|
return {
|
|
112
111
|
h0: i,
|
|
113
|
-
h1:
|
|
112
|
+
h1: o
|
|
114
113
|
};
|
|
115
114
|
};
|
|
116
115
|
static checkSignature = (e, t, n, r) => {
|
|
117
116
|
let { h0: i, h1: a } = this.getStealthAddressCompressedPoints(e, r);
|
|
118
117
|
return t === i && n === a;
|
|
119
118
|
};
|
|
120
|
-
static getStealthAddress =
|
|
121
|
-
let { H0: r, H1: i } = this.getRandomizedStealthPairOld(e,
|
|
122
|
-
return
|
|
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]);
|
|
123
122
|
});
|
|
124
|
-
static getH1FromH0 = (
|
|
125
|
-
let
|
|
126
|
-
return [BigInt(
|
|
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]))];
|
|
127
126
|
};
|
|
128
127
|
static verifyStealthPair = (e, t, n, r = !0) => {
|
|
129
128
|
let i = this.getH1FromH0(e, n);
|
|
130
129
|
return r ? i[1] === t[1] : i === t;
|
|
131
130
|
};
|
|
132
|
-
static getStealthAddressNewStyle = (e,
|
|
131
|
+
static getStealthAddressNewStyle = (e, n, r) => {
|
|
133
132
|
if (r?.length !== 2) throw Error("Spending public key must be an array of 2 elements");
|
|
134
|
-
let i = this.getH1FromH0(e,
|
|
135
|
-
return
|
|
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);
|
|
136
135
|
};
|
|
137
|
-
static findCorrectRandomization(
|
|
136
|
+
static findCorrectRandomization(t, n) {
|
|
138
137
|
if (!n) throw Error("No Private Shielded Key Provided");
|
|
139
|
-
let r = BigInt(n) %
|
|
138
|
+
let r = BigInt(n) % e, i, a, o = 0n;
|
|
140
139
|
do
|
|
141
|
-
i =
|
|
140
|
+
i = t * 10n ** o % e, a = i * r % e, o += 1n;
|
|
142
141
|
while (a >= 2n ** 253n || i >= 2n ** 253n);
|
|
143
142
|
return i;
|
|
144
143
|
}
|
|
145
144
|
static getH0FromRandomization = (e) => {
|
|
146
|
-
let t =
|
|
147
|
-
return [BigInt(t.F.toString(
|
|
145
|
+
let t = n(), r = t.mulPointEscalar(t.Base8, e);
|
|
146
|
+
return [BigInt(t.F.toString(r[0])), BigInt(t.F.toString(r[1]))];
|
|
148
147
|
};
|
|
149
148
|
static findH0(e, t) {
|
|
150
149
|
if (!t) return;
|
|
@@ -152,14 +151,14 @@ var m = /* @__PURE__ */ e(r()), h = new o(), g = new o(), _ = new o(), v = class
|
|
|
152
151
|
return n;
|
|
153
152
|
}
|
|
154
153
|
static getEncryptionKeyPair = (e) => {
|
|
155
|
-
let t =
|
|
154
|
+
let t = u.crypto_box_seed_keypair(o.getBytes(e));
|
|
156
155
|
return {
|
|
157
|
-
privateKey:
|
|
158
|
-
publicKey:
|
|
156
|
+
privateKey: o.hexlify(t.privateKey),
|
|
157
|
+
publicKey: o.hexlify(t.publicKey)
|
|
159
158
|
};
|
|
160
159
|
};
|
|
161
|
-
getAccessKey = () => (this.requireKeyMaterial(),
|
|
162
|
-
getBackendToken = () => (this.requireKeyMaterial(),
|
|
160
|
+
getAccessKey = () => (this.requireKeyMaterial(), t(this.getShieldedPrivateKey(), this.getShieldedPublicKey()));
|
|
161
|
+
getBackendToken = () => (this.requireKeyMaterial(), t(this.getAccessKey(), this.getShieldedPublicKey()));
|
|
163
162
|
};
|
|
164
163
|
//#endregion
|
|
165
|
-
export {
|
|
164
|
+
export { g as UserKeys, h as stealthAddressCacheDevice, p as stealthPairCacheDevice, m as stealthPairOldCacheDevice };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../../../_virtual/_rolldown/runtime.cjs"),t=require(`./serialize.utils.cjs`),n=require(
|
|
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,33 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import * as a from "node-forge";
|
|
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";
|
|
7
6
|
//#region common/src/functions/utils/encryptInputForEnclave.ts
|
|
8
|
-
var
|
|
7
|
+
var a = (e) => typeof e == "bigint" || typeof e == "number" ? e.toString() : e, o = (e) => i.util.hexToBytes(e.replace("0x", "")), s = (e) => {
|
|
9
8
|
let t = structuredClone(e);
|
|
10
9
|
return Object.entries(t).forEach(([e, n]) => {
|
|
11
|
-
t[e] =
|
|
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));
|
|
12
11
|
}), t;
|
|
13
|
-
},
|
|
14
|
-
let n =
|
|
15
|
-
md:
|
|
16
|
-
mgf1: { md:
|
|
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() }
|
|
17
16
|
});
|
|
18
|
-
return
|
|
19
|
-
},
|
|
20
|
-
let
|
|
21
|
-
return
|
|
22
|
-
},
|
|
23
|
-
let n =
|
|
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
|
+
}, u = (e, t) => {
|
|
22
|
+
let n = r.randombytes_buf(r.crypto_secretbox_KEYBYTES);
|
|
24
23
|
return {
|
|
25
|
-
keyCiphertext:
|
|
26
|
-
inputCiphertext:
|
|
24
|
+
keyCiphertext: c(t, n),
|
|
25
|
+
inputCiphertext: l(n, e)
|
|
27
26
|
};
|
|
28
|
-
},
|
|
29
|
-
let r = typeof
|
|
30
|
-
return
|
|
31
|
-
},
|
|
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());
|
|
32
31
|
//#endregion
|
|
33
|
-
export {
|
|
32
|
+
export { f as makeEnclaveHandshakeAndEncryptInput, p 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.96/' + 'zkProofWorkerLauncher.js',
|
|
6
|
+
SnarkJS: domain + '/0.3.96/' + 'snarkjsWorkerLauncher.js',
|
|
7
|
+
UTXO: domain + '/0.3.96/' + 'utxoWorkerLauncher.js',
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
// Returns a blob:// URL which points
|
package/package.json
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
);
|
|
1
|
+
// Static require so Metro can resolve it; subpath bypasses package "import" (ESM) exports.
|
|
2
|
+
module.exports = require("libsodium-wrappers/dist/modules/libsodium-wrappers.js");
|