@gurge/sdk-react-native 0.3.69 → 0.3.74
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/_virtual/_rolldown/runtime.mjs +11 -2
- package/common/src/constants/vite.constants.cjs +1 -1
- package/common/src/constants/vite.constants.mjs +1 -1
- package/common/src/crypto/babyJub.cjs +1 -1
- package/common/src/crypto/babyJub.mjs +7 -6
- package/common/src/crypto/eddsa.cjs +1 -1
- package/common/src/crypto/eddsa.mjs +7 -6
- package/common/src/crypto/poseidon.cjs +1 -1
- package/common/src/crypto/poseidon.mjs +13 -13
- package/common/src/data-structures/IndexedDB/activity-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/activity-db.mjs +38 -38
- package/common/src/data-structures/IndexedDB/balances-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/balances-db.mjs +18 -16
- package/common/src/data-structures/IndexedDB/contact-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/contact-db.mjs +16 -14
- package/common/src/data-structures/IndexedDB/key-val-store.cjs +1 -1
- package/common/src/data-structures/IndexedDB/key-val-store.mjs +12 -12
- package/common/src/data-structures/IndexedDB/pay-activity-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/pay-activity-db.mjs +10 -8
- package/common/src/data-structures/IndexedDB/signatures-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/signatures-db.mjs +23 -21
- package/common/src/data-structures/TokenDBs/AlchemyPublicTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/AlchemyPublicTokensDB.mjs +32 -31
- package/common/src/data-structures/TokenDBs/ArcPublicTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/ArcPublicTokensDB.mjs +25 -25
- package/common/src/data-structures/TokenDBs/EventsPublicTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/EventsPublicTokensDB.mjs +47 -46
- package/common/src/data-structures/TokenDBs/PrivateTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/PrivateTokensDB.mjs +20 -20
- package/common/src/data-structures/TokenDBs/TempoPublicTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/TempoPublicTokensDB.mjs +19 -19
- package/common/src/data-structures/TokenDBs/TronPublicTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/TronPublicTokensDB.mjs +19 -19
- package/common/src/data-structures/TokenDBs/token-visibility-db.cjs +1 -1
- package/common/src/data-structures/TokenDBs/token-visibility-db.mjs +45 -44
- package/common/src/data-structures/cacheDevices/FileCacheDevice.cjs +1 -1
- package/common/src/data-structures/cacheDevices/FileCacheDevice.mjs +1 -1
- package/common/src/functions/snarkjs/verifyCommitmentValidationData.cjs +1 -1
- package/common/src/functions/snarkjs/verifyCommitmentValidationData.mjs +4 -1
- package/common/src/functions/utils/cacheDevice.utils.cjs +1 -1
- package/common/src/functions/utils/cacheDevice.utils.mjs +1 -1
- package/common/src/functions/utils/cacheFunctions.cjs +1 -1
- package/common/src/functions/utils/cacheFunctions.mjs +13 -13
- package/common/src/functions/utils/ipfs.cjs +1 -1
- package/common/src/functions/utils/ipfs.mjs +3 -1
- package/common/src/webworker/viteWorkerURL.constant.mjs +3 -3
- package/common/src/webworker/workerFactory.cjs +1 -1
- package/common/src/webworker/workerFactory.mjs +3 -3
- package/package.json +1 -1
- package/shims/circomlibjs-hinkal-fork.cjs +14 -0
- package/shims/circomlibjs-hinkal-fork.mjs +3 -0
- package/shims/circomlibjs.cjs +15 -0
- package/shims/circomlibjs.mjs +3 -0
- package/shims/constants.cjs +7 -0
- package/shims/constants.mjs +3 -0
- package/shims/crypto.cjs +102 -0
- package/shims/crypto.mjs +3 -0
- package/shims/dotenv.cjs +3 -0
- package/shims/dotenv.mjs +3 -0
- package/shims/ffjavascript.cjs +5 -0
- package/shims/ffjavascript.mjs +3 -0
- package/shims/fs.cjs +5 -0
- package/shims/fs.mjs +3 -0
- package/shims/globals.cjs +15 -0
- package/shims/globals.mjs +3 -0
- package/shims/idb-keyval.cjs +75 -0
- package/shims/idb-keyval.mjs +3 -0
- package/shims/multiformats.cjs +1 -0
- package/shims/multiformats.mjs +3 -0
- package/shims/os.cjs +7 -0
- package/shims/os.mjs +3 -0
- package/shims/path.cjs +11 -0
- package/shims/path.mjs +3 -0
- package/shims/readline.cjs +6 -0
- package/shims/readline.mjs +3 -0
- package/shims/snarkjs.cjs +21 -0
- package/shims/snarkjs.mjs +3 -0
- package/shims/url.cjs +5 -0
- package/shims/url.mjs +3 -0
- package/shims/web-worker.cjs +7 -0
- package/shims/web-worker.mjs +3 -0
- package/shims/worker_threads.cjs +6 -0
- package/shims/worker_threads.mjs +3 -0
package/shims/crypto.cjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Node `crypto` shim for React Native.
|
|
2
|
+
|
|
3
|
+
const { sha256, sha512, keccak256 } = require('ethers');
|
|
4
|
+
const { Buffer } = require('buffer');
|
|
5
|
+
|
|
6
|
+
function ensureRng() {
|
|
7
|
+
if (!global.crypto || typeof global.crypto.getRandomValues !== 'function') {
|
|
8
|
+
throw new Error(
|
|
9
|
+
'[hinkal-rn] global.crypto.getRandomValues is not available. ' +
|
|
10
|
+
'Import @hinkal/sdk-react-native (HinkalProvider) before other SDK code.',
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function randomBytes(size) {
|
|
16
|
+
ensureRng();
|
|
17
|
+
const arr = new Uint8Array(size);
|
|
18
|
+
global.crypto.getRandomValues(arr);
|
|
19
|
+
return Buffer.from(arr);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function randomFillSync(buf, offset, size) {
|
|
23
|
+
ensureRng();
|
|
24
|
+
const start = offset ?? 0;
|
|
25
|
+
const end = size != null ? start + size : buf.length;
|
|
26
|
+
const view = new Uint8Array(buf.buffer || buf, buf.byteOffset || 0, buf.length);
|
|
27
|
+
const tmp = new Uint8Array(end - start);
|
|
28
|
+
global.crypto.getRandomValues(tmp);
|
|
29
|
+
view.set(tmp, start);
|
|
30
|
+
return buf;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function randomUUID() {
|
|
34
|
+
// RFC 4122 v4 UUID via crypto-secure bytes.
|
|
35
|
+
const b = randomBytes(16);
|
|
36
|
+
b[6] = (b[6] & 0x0f) | 0x40;
|
|
37
|
+
b[8] = (b[8] & 0x3f) | 0x80;
|
|
38
|
+
const hex = b.toString('hex');
|
|
39
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function toBytesLike(input) {
|
|
43
|
+
if (input == null) return new Uint8Array(0);
|
|
44
|
+
if (typeof input === 'string') return Buffer.from(input, 'utf8');
|
|
45
|
+
if (input instanceof Uint8Array) return input;
|
|
46
|
+
if (Buffer.isBuffer(input)) return input;
|
|
47
|
+
if (input.buffer) return new Uint8Array(input.buffer, input.byteOffset || 0, input.byteLength || input.length);
|
|
48
|
+
return Buffer.from(input);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function hexToBuffer(hex) {
|
|
52
|
+
return Buffer.from(hex.replace(/^0x/, ''), 'hex');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function createHash(algorithm) {
|
|
56
|
+
const alg = String(algorithm).toLowerCase().replace('-', '');
|
|
57
|
+
const chunks = [];
|
|
58
|
+
return {
|
|
59
|
+
update(chunk) {
|
|
60
|
+
chunks.push(toBytesLike(chunk));
|
|
61
|
+
return this;
|
|
62
|
+
},
|
|
63
|
+
digest(encoding) {
|
|
64
|
+
const total = chunks.reduce((acc, c) => acc + c.length, 0);
|
|
65
|
+
const merged = new Uint8Array(total);
|
|
66
|
+
let off = 0;
|
|
67
|
+
for (const c of chunks) {
|
|
68
|
+
merged.set(c, off);
|
|
69
|
+
off += c.length;
|
|
70
|
+
}
|
|
71
|
+
let hex;
|
|
72
|
+
if (alg === 'sha256') hex = sha256(merged);
|
|
73
|
+
else if (alg === 'sha512') hex = sha512(merged);
|
|
74
|
+
else if (alg === 'keccak256') hex = keccak256(merged);
|
|
75
|
+
else throw new Error(`[hinkal-rn] unsupported hash algorithm: ${algorithm}`);
|
|
76
|
+
const buf = hexToBuffer(hex);
|
|
77
|
+
if (!encoding) return buf;
|
|
78
|
+
if (encoding === 'hex') return buf.toString('hex');
|
|
79
|
+
if (encoding === 'base64') return buf.toString('base64');
|
|
80
|
+
return buf.toString(encoding);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function createHmac() {
|
|
86
|
+
throw new Error('[hinkal-rn] crypto.createHmac is not implemented in the RN shim. Use a JS implementation.');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = {
|
|
90
|
+
randomBytes,
|
|
91
|
+
randomFillSync,
|
|
92
|
+
randomUUID,
|
|
93
|
+
createHash,
|
|
94
|
+
createHmac,
|
|
95
|
+
webcrypto: typeof global.crypto !== 'undefined' ? global.crypto : undefined,
|
|
96
|
+
getRandomValues: (arr) => {
|
|
97
|
+
ensureRng();
|
|
98
|
+
global.crypto.getRandomValues(arr);
|
|
99
|
+
return arr;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
module.exports.default = module.exports;
|
package/shims/crypto.mjs
ADDED
package/shims/dotenv.cjs
ADDED
package/shims/dotenv.mjs
ADDED
package/shims/fs.cjs
ADDED
package/shims/fs.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Buffer } from "buffer";
|
|
2
|
+
import * as ReactNative from "react-native";
|
|
3
|
+
global.Buffer = Buffer;
|
|
4
|
+
|
|
5
|
+
// key-val-store probes indexedDB; without it the SDK falls back to FileKeyValStore (process.cwd).
|
|
6
|
+
if (typeof globalThis.indexedDB === "undefined") {
|
|
7
|
+
globalThis.indexedDB = {};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (typeof global.require === "undefined") {
|
|
11
|
+
global.require = (m) => {
|
|
12
|
+
if (m === "react-native") return ReactNative;
|
|
13
|
+
throw new Error(`global.require shim: unsupported module "${m}"`);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// idb-keyval shim for React Native
|
|
2
|
+
const AsyncStorage =
|
|
3
|
+
require("@react-native-async-storage/async-storage").default;
|
|
4
|
+
|
|
5
|
+
const PREFIX = "@hinkal/idb-keyval:";
|
|
6
|
+
const key = (k) => `${PREFIX}${typeof k === "string" ? k : JSON.stringify(k)}`;
|
|
7
|
+
|
|
8
|
+
async function get(k) {
|
|
9
|
+
const raw = await AsyncStorage.getItem(key(k));
|
|
10
|
+
if (raw == null) return undefined;
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(raw);
|
|
13
|
+
} catch {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function set(k, value) {
|
|
19
|
+
if (value === undefined) {
|
|
20
|
+
await AsyncStorage.removeItem(key(k));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
await AsyncStorage.setItem(key(k), JSON.stringify(value));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function update(k, updater) {
|
|
27
|
+
const current = await get(k);
|
|
28
|
+
const next = updater(current);
|
|
29
|
+
await set(k, next);
|
|
30
|
+
return next;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function del(k) {
|
|
34
|
+
await AsyncStorage.removeItem(key(k));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function clear() {
|
|
38
|
+
const all = await AsyncStorage.getAllKeys();
|
|
39
|
+
const ours = all.filter((x) => x.startsWith(PREFIX));
|
|
40
|
+
if (ours.length) await AsyncStorage.multiRemove(ours);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function keys() {
|
|
44
|
+
const all = await AsyncStorage.getAllKeys();
|
|
45
|
+
return all.filter((x) => x.startsWith(PREFIX)).map((x) => x.slice(PREFIX.length));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function values() {
|
|
49
|
+
const ks = await keys();
|
|
50
|
+
return Promise.all(ks.map(get));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function entries() {
|
|
54
|
+
const ks = await keys();
|
|
55
|
+
const vs = await Promise.all(ks.map(get));
|
|
56
|
+
return ks.map((k, i) => [k, vs[i]]);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function createStore() {
|
|
60
|
+
// idb-keyval lets callers create a store with a custom DB name; we ignore it
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
get,
|
|
66
|
+
set,
|
|
67
|
+
update,
|
|
68
|
+
del,
|
|
69
|
+
clear,
|
|
70
|
+
keys,
|
|
71
|
+
values,
|
|
72
|
+
entries,
|
|
73
|
+
createStore,
|
|
74
|
+
};
|
|
75
|
+
module.exports.default = module.exports;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = {};
|
package/shims/os.cjs
ADDED
package/shims/os.mjs
ADDED
package/shims/path.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
join: (...args) => args.join("/"),
|
|
3
|
+
resolve: (...args) => args.join("/"),
|
|
4
|
+
dirname: (p) => p.split("/").slice(0, -1).join("/"),
|
|
5
|
+
basename: (p) => p.split("/").pop(),
|
|
6
|
+
extname: (p) => {
|
|
7
|
+
const base = p.split("/").pop();
|
|
8
|
+
const idx = base.lastIndexOf(".");
|
|
9
|
+
return idx < 0 ? "" : base.slice(idx);
|
|
10
|
+
},
|
|
11
|
+
};
|
package/shims/path.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function notSupported(name) {
|
|
2
|
+
return () => {
|
|
3
|
+
throw new Error(
|
|
4
|
+
`[hinkal-rn] snarkjs.${name} is not available on the React Native JS thread. ` +
|
|
5
|
+
"All proof generation must go through the SnarkJS WebView bridge.",
|
|
6
|
+
);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
groth16: {
|
|
12
|
+
fullProve: notSupported("groth16.fullProve"),
|
|
13
|
+
prove: notSupported("groth16.prove"),
|
|
14
|
+
verify: notSupported("groth16.verify"),
|
|
15
|
+
exportSolidityCallData: notSupported("groth16.exportSolidityCallData"),
|
|
16
|
+
},
|
|
17
|
+
zKey: {
|
|
18
|
+
exportVerificationKey: notSupported("zKey.exportVerificationKey"),
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
module.exports.default = module.exports;
|
package/shims/url.cjs
ADDED
package/shims/url.mjs
ADDED