@kapa123456789/sdk 0.0.67 → 0.0.69
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/constants/vite.constants.cjs +1 -1
- package/common/src/constants/vite.constants.mjs +6 -2
- package/common/src/crypto/BabyJubRN.cjs +1 -0
- package/common/src/crypto/BabyJubRN.d.ts +18 -0
- package/common/src/crypto/BabyJubRN.mjs +33 -0
- package/common/src/crypto/babyJub.cjs +1 -1
- package/common/src/crypto/babyJub.mjs +6 -34
- package/common/src/crypto/poseidon.cjs +1 -1
- package/common/src/crypto/poseidon.mjs +13 -14
- package/common/src/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDeposit.mjs +2 -35
- package/common/src/data-structures/Hinkal/hinkalSwap.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSwap.mjs +9 -49
- package/common/src/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalTransfer.mjs +12 -59
- package/common/src/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdraw.mjs +13 -58
- package/common/src/error-handling/logger.cjs +1 -1
- package/common/src/error-handling/logger.mjs +15 -7
- package/common/src/functions/index.cjs +1 -1
- package/common/src/functions/index.mjs +1 -0
- package/common/src/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +48 -161
- package/common/src/functions/snarkjs/generateZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/generateZkProof.mjs +1 -6
- package/common/src/functions/utils/bigint-math.utils.cjs +1 -0
- package/common/src/functions/utils/bigint-math.utils.d.ts +2 -0
- package/common/src/functions/utils/bigint-math.utils.mjs +12 -0
- package/common/src/functions/utils/index.cjs +1 -1
- package/common/src/functions/utils/index.d.ts +1 -0
- package/common/src/functions/utils/index.mjs +1 -0
- package/common/src/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallDirect.mjs +38 -159
- package/common/src/webworker/{logError-DlIdq8zv.js → logError-D7JCP4vy.js} +5 -5
- package/common/src/webworker/package.json +2 -2
- package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/snarkjsWorkerNode.cjs +1 -1
- package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/utxoWorkerNode.cjs +1 -1
- package/common/src/webworker/viteWorkerURL.constant.cjs +4 -4
- package/common/src/webworker/viteWorkerURL.constant.mjs +4 -4
- package/common/src/webworker/workerFactory.cjs +1 -1
- package/common/src/webworker/workerFactory.mjs +1 -1
- package/common/src/webworker/{workerProxy-Cr4zT_SW.js → workerProxy-C1ojG-04.js} +1 -1
- package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
- package/package.json +2 -2
- package/react-native/HinkalWebViewWorker.cjs +3 -3
- package/react-native/HinkalWebViewWorker.mjs +46 -68
- package/react-native/bridge/HinkalRNWorker.cjs +1 -0
- package/react-native/bridge/HinkalRNWorker.d.ts +13 -0
- package/react-native/bridge/HinkalRNWorker.mjs +26 -0
- package/react-native/bridge/serialization.utils.cjs +1 -0
- package/react-native/bridge/serialization.utils.d.ts +3 -0
- package/react-native/bridge/serialization.utils.mjs +13 -0
- package/react-native/metro-config.js +9 -7
- package/react-native/shims/circomlibjs-hinkal-fork.js +1 -1
- package/react-native/shims/circomlibjs.js +1 -1
- package/react-native/shims/crypto.js +23 -16
- package/react-native/shims/globals.js +6 -4
- package/react-native/shims/idb-keyval.js +13 -5
- package/react-native/shims/path.js +20 -7
- package/react-native/shims/snarkjs.js +7 -6
- package/react-native/workerCDNUrls.cjs +1 -1
- package/react-native/workerCDNUrls.mjs +2 -4
- package/sdk/package.json.cjs +1 -1
- package/sdk/package.json.mjs +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=``+(typeof document>`u`?require(`url`).pathToFileURL(__dirname+`/../../../../assets/zkProofWorkerLauncher-
|
|
1
|
+
var e=``+(typeof document>`u`?require(`url`).pathToFileURL(__dirname+`/../../../../assets/zkProofWorkerLauncher-DVF9ybkr.js`).href:new URL(`../../../../assets/zkProofWorkerLauncher-DVF9ybkr.js`,document.currentScript&&document.currentScript.tagName.toUpperCase()===`SCRIPT`&&document.currentScript.src||document.baseURI).href);exports.default=e;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
//#region libs/shared/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url
|
|
2
|
-
var e = "" + new URL("../../../../assets/zkProofWorkerLauncher-
|
|
2
|
+
var e = "" + new URL("../../../../assets/zkProofWorkerLauncher-DVF9ybkr.js", import.meta.url).href;
|
|
3
3
|
//#endregion
|
|
4
4
|
export { e as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./workerProxy-
|
|
1
|
+
const e=require(`./workerProxy-C1ojG-04.js`),t=require(`./logError-D7JCP4vy.js`);let n=require(`worker_threads`),r=require(`buffer`);var i=e.S(e._());Object.values({preHookContract:`0x0000000000000000000000000000000000000000`,hookContract:`0x0000000000000000000000000000000000000000`,preHookMetadata:`0x00`,postHookMetadata:`0x00`});var a=(e,t)=>{let n=[];for(let r=0;r<e.length;r+=1){n.push([]);for(let i=0;i<e[r].length;i+=1)n[r][i]=t.getSiblingHashesForVerification(BigInt(e[r][i].getCommitment())).map(e=>e.toString())}let r=[];for(let n=0;n<e.length;n+=1){r.push([]);for(let i=0;i<e[n].length;i+=1)r[n][i]=t.getSiblingSides(BigInt(e[n][i].getCommitment())).map(e=>e.toString())}return{inCommitmentSiblings:n,inCommitmentSiblingSides:r}},o=(e,t)=>({accessTokenSiblings:t.getSiblingHashesForVerification(BigInt(e)).map(e=>e.toString()),accessTokenSiblingSides:t.getSiblingSides(BigInt(e)).map(e=>e.toString())}),s=(e,t)=>o(e,t),c=function(e){return e[e.CALC_COMMITMENTS_SIBLING_AND_SIDES=0]=`CALC_COMMITMENTS_SIBLING_AND_SIDES`,e[e.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES=1]=`CALC_ACCESS_TOKEN_SIBLING_AND_SIDES`,e[e.BUILD_IN_NULLIFIERS=2]=`BUILD_IN_NULLIFIERS`,e}({}),l=class extends Error{constructor(){super(`Merkle tree is incomplete`),this.name=`MerkleTreeIncompleteError`}},u=class e{tree;count;index;reverseTree;static createWithData(t,n,r,i,a,o,s){return new e(a,o,s,t,n,r,i)}static create(n,r,i=t.F){return new e(n,i,r)}createReverseTree(){let e=new Map;for(let t=this.getStartIndex();t<this.getStartIndex()+this.count;t+=1n){let n=this.tree.get(t);n!==void 0&&e.set(n,t)}return e}constructor(e,t,n,r,i,a,o){this.hashFunction=e,this.levels=t,this.defaultNodeValue=n,this.tree=r??new Map,this.count=o??0n,this.index=a??2n**(t-1n),i?this.reverseTree=i:this.reverseTree=this.createReverseTree()}getStartIndex(){return 2n**(this.levels-1n)}logarithm2(e){let t=0n;for(;2n**t<e;)t+=1n;return t}bigIntMax(e,t){return e>t?e:t}forceInsert(e,t){if(t<this.getStartIndex())throw RangeError();this.tree.set(t,e),this.reverseTree.set(e,t);let n=this.index-this.getStartIndex(),r=this.logarithm2(n),i=t;for(let e=1n;e<=r;e+=1n){i/=2n;let e=this.hashFunction(this.tree.get(i*2n)||this.defaultNodeValue,this.tree.get(i*2n+1n)||this.defaultNodeValue);this.tree.set(i,e)}}insert(e,n){let r=!1;this.tree.has(n)&&(r=!0,t.t(`Editing commitment index: ${n} `)),r||(this.count+=1n),this.index=this.bigIntMax(this.index,n+1n),this.forceInsert(e,n)}remove(e){this.forceInsert(this.defaultNodeValue,e)}completenessCheck(){if(this.count!==this.index-this.getStartIndex())throw new l}getRootHash(){this.completenessCheck();for(let e=1n;e<2n**this.levels;e*=2n)if(this.tree.get(e))return this.tree.get(e);return this.defaultNodeValue}getMerkleData(){return this.completenessCheck(),new Map(this.tree)}getValue(e){return this.tree.get(e)}getSiblingIndex(e){return e===1n?1n:e%2n==1n?e-1n:e+1n}getSiblingHashesForVerification(e){this.completenessCheck();let t=this.reverseTree.get(e);if(t===void 0)return Array(25).fill(0n);let n=[];for(;t!==0n;)n.push(this.tree.get(this.getSiblingIndex(t))||this.defaultNodeValue),t/=2n;return n.slice(0,25)}getSiblingSides(e){this.completenessCheck();let t=this.reverseTree.get(e);if(t===void 0)return Array(25).fill(0n);let n=[];for(;t!==0n;){let e=t%2n==0n?0n:1n;n.push(e),t/=2n}return n.slice(0,25)}toJSON(){let{tree:e,reverseTree:t,count:n,index:r}=this;return{tree:Object.fromEntries(e),reverseTree:Object.fromEntries(t),count:n.toString(),index:r.toString()}}toJSONLite(){let{tree:e,count:t,index:n}=this;return{tree:Object.fromEntries(e),count:t.toString(),index:n.toString()}}clone(){return e.createWithData(new Map(this.tree),new Map(this.reverseTree),this.index,this.count,this.hashFunction,this.levels,this.defaultNodeValue)}getIndex(){return this.index}},d=e=>new Map(Object.entries(e).map(([e,t])=>[BigInt(e),BigInt(t)])),f=e=>{let n=d(e.tree),r=e.reverseTree?d(e.reverseTree):void 0;return u.createWithData(n,r,BigInt(e.index),BigInt(e.count),t.u,t.F,0n)},p=new e.t,m=e=>{let{inputUtxosSerialized:n,merkleTreeSerialized:r}=e.data,i=f(r),{inCommitmentSiblings:o,inCommitmentSiblingSides:s}=a(n.map(e=>e.map(e=>new t.i(e))),i);p.postMessageToMainThread({inCommitmentSiblings:o,inCommitmentSiblingSides:s})},h=e=>{let{accessKey:t,merkleTreeAccessTokenSerialized:n}=e.data,{accessTokenSiblings:r,accessTokenSiblingSides:i}=s(t,f(n));p.postMessageToMainThread({accessTokenSiblings:r,accessTokenSiblingSides:i})},g=e=>{let{inputUtxosSerialized:n}=e.data,r=n.map(e=>e.map(e=>new t.i(e))).map(e=>e.map(e=>e.amount===0n?`0`:e.getNullifier()));p.postMessageToMainThread(r)},_=async e=>{try{await t.l();let{type:n}=e.payload;switch(n){case c.CALC_COMMITMENTS_SIBLING_AND_SIDES:m(e.payload);return;case c.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES:h(e.payload);return;case c.BUILD_IN_NULLIFIERS:g(e.payload);return;default:throw Error(`Unknown worker message type ${n}`)}}catch(e){console.error(e),p.postErrorToMainThread(e)}};globalThis.process=i.default,globalThis.Buffer=r.Buffer,n.parentPort.on(`message`,async e=>{await _(e)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kapa123456789/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.69",
|
|
4
4
|
"homepage": "hinkal.io",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Hinkal Protocol"
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
16
|
"types": "./index.d.ts",
|
|
17
|
-
"main": "./index.cjs",
|
|
18
17
|
"react-native": "./index.cjs",
|
|
19
18
|
"import": "./index.mjs",
|
|
20
19
|
"default": "./index.cjs"
|
|
@@ -111,6 +110,7 @@
|
|
|
111
110
|
"ua-parser-js": "^1.0.37",
|
|
112
111
|
"uuid": "^9.0.1",
|
|
113
112
|
"node-forge": "^1.3.1",
|
|
113
|
+
"poseidon-lite": "^0.3.0",
|
|
114
114
|
"tronweb": "^6.2.0"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../common/src/webworker/workerFactory.cjs`),t=require(`./workerCDNUrls.cjs`),n=require(`./bridge/serialization.utils.cjs`),r=require(`./bridge/HinkalRNWorker.cjs`);let i=require(`react`),a=require(`react-native`),o=require(`react-native-webview`),s=require(`react/jsx-runtime`);var c=`${new URL(Object.values(t.WORKER_CDN_URLS)[0]).origin}/`;e.WorkerFactory.rnWorkerFactory=e=>new r.HinkalRNWorker(e);var l=`
|
|
2
2
|
if (!window.__hinkalPageBoot) (function(){
|
|
3
3
|
window.__hinkalPageBoot = true;
|
|
4
|
-
var URLS = ${JSON.stringify(
|
|
4
|
+
var URLS = ${JSON.stringify(t.WORKER_CDN_URLS)};
|
|
5
5
|
var BLOBS = {};
|
|
6
6
|
|
|
7
7
|
function replacer(_key, value){
|
|
@@ -95,4 +95,4 @@ if (!window.__hinkalPageBoot) (function(){
|
|
|
95
95
|
|
|
96
96
|
post({ type: 'READY' });
|
|
97
97
|
})();
|
|
98
|
-
true;`,
|
|
98
|
+
true;`,u=`<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body><script>${l}<\/script></body></html>`,d=a.StyleSheet.create({hiddenHost:{position:`absolute`,height:1,width:1,left:-9999,top:-9999,opacity:0}}),f=()=>{let e=(0,i.useRef)(null),t=(0,i.useRef)({ready:!1,queue:[]}),r=(0,i.useCallback)((t,r,i)=>{console.log(`inject`,t,r,i);let o;try{o=JSON.stringify({requestId:t,variant:r,message:i},n.bigIntReplacer)}catch(e){a.DeviceEventEmitter.emit(`FROM_WEBVIEW_WORKER`,{requestId:t,type:`ERROR`,error:`serialize failed: ${e?.message??e}`});return}e.current?.injectJavaScript(`window.handleMessage && window.handleMessage(${o}); true;`)},[]);(0,i.useEffect)(()=>{let e=a.DeviceEventEmitter.addListener(`TO_WEBVIEW_WORKER`,e=>{console.log(`TO_WEBVIEW_WORKER`,e);let n={requestId:e?.__requestId??``,variant:e?.variant??``,message:e?.message};t.current.ready?r(n.requestId,n.variant,n.message):t.current.queue.push(n)});return()=>e.remove()},[r]);let f=(0,i.useCallback)(e=>{console.log(`onMessage`,e),console.log(`event.nativeEvent.data`,e.nativeEvent.data);let i;try{i=n.reviveBigInts(JSON.parse(e.nativeEvent.data))}catch(e){a.DeviceEventEmitter.emit(`FROM_WEBVIEW_WORKER`,{type:`ERROR`,error:e?.message??`parse error`});return}if(i?.type===`READY`){t.current.ready=!0;let e=t.current.queue;t.current.queue=[],e.forEach(({requestId:e,variant:t,message:n})=>r(e,t,n));return}a.DeviceEventEmitter.emit(`FROM_WEBVIEW_WORKER`,i)},[r]);return(0,s.jsx)(a.View,{pointerEvents:`none`,style:d.hiddenHost,children:(0,s.jsx)(o.WebView,{ref:e,source:{html:u,baseUrl:c},originWhitelist:[`*`],javaScriptEnabled:!0,domStorageEnabled:!0,androidLayerType:`hardware`,onMessage:f,onLoad:()=>e.current?.injectJavaScript(l)})})};module.exports=f;
|
|
@@ -1,41 +1,14 @@
|
|
|
1
1
|
import { WorkerFactory as e } from "../common/src/webworker/workerFactory.mjs";
|
|
2
2
|
import { WORKER_CDN_URLS as t } from "./workerCDNUrls.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { bigIntReplacer as n, reviveBigInts as r } from "./bridge/serialization.utils.mjs";
|
|
4
|
+
import { HinkalRNWorker as i } from "./bridge/HinkalRNWorker.mjs";
|
|
5
|
+
import { useCallback as a, useEffect as o, useRef as s } from "react";
|
|
6
|
+
import { DeviceEventEmitter as c, StyleSheet as l, View as u } from "react-native";
|
|
7
|
+
import { WebView as d } from "react-native-webview";
|
|
8
|
+
import { jsx as f } from "react/jsx-runtime";
|
|
7
9
|
//#region libs/shared/sdk/src/react-native/HinkalWebViewWorker.tsx
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
let t = Object.keys(e);
|
|
11
|
-
if (t.length === 1) {
|
|
12
|
-
if (typeof e.__bigint == "string") return BigInt(e.__bigint);
|
|
13
|
-
if (Array.isArray(e.__set)) return new Set(e.__set.map(f));
|
|
14
|
-
if (Array.isArray(e.__map)) return new Map(e.__map.map((e) => [f(e[0]), f(e[1])]));
|
|
15
|
-
}
|
|
16
|
-
return Array.isArray(e) ? e.map(f) : Object.fromEntries(t.map((t) => [t, f(e[t])]));
|
|
17
|
-
}, p = class {
|
|
18
|
-
onmessage = null;
|
|
19
|
-
onerror = null;
|
|
20
|
-
requestId = u();
|
|
21
|
-
subscription;
|
|
22
|
-
constructor(e) {
|
|
23
|
-
this.variant = e, this.subscription = i.addListener("FROM_WEBVIEW_WORKER", (e) => {
|
|
24
|
-
!e || e.requestId !== this.requestId || (e.type === "RESULT" ? this.onmessage?.({ data: e.data }) : e.type === "ERROR" && this.onerror?.(Error(e.error ?? "WebView worker error")));
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
postMessage(e) {
|
|
28
|
-
i.emit("TO_WEBVIEW_WORKER", {
|
|
29
|
-
__requestId: this.requestId,
|
|
30
|
-
variant: this.variant,
|
|
31
|
-
message: e
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
terminate() {
|
|
35
|
-
this.subscription?.remove?.(), this.subscription = null;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
e.rnWorkerFactory = (e) => new p(e);
|
|
10
|
+
var p = `${new URL(Object.values(t)[0]).origin}/`;
|
|
11
|
+
e.rnWorkerFactory = (e) => new i(e);
|
|
39
12
|
var m = `
|
|
40
13
|
if (!window.__hinkalPageBoot) (function(){
|
|
41
14
|
window.__hinkalPageBoot = true;
|
|
@@ -120,7 +93,7 @@ if (!window.__hinkalPageBoot) (function(){
|
|
|
120
93
|
|
|
121
94
|
post({ type: 'READY' });
|
|
122
95
|
})();
|
|
123
|
-
true;`, h = `<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body><script>${m}<\/script></body></html>`, g =
|
|
96
|
+
true;`, h = `<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body><script>${m}<\/script></body></html>`, g = l.create({ hiddenHost: {
|
|
124
97
|
position: "absolute",
|
|
125
98
|
height: 1,
|
|
126
99
|
width: 1,
|
|
@@ -128,19 +101,20 @@ true;`, h = `<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body><scr
|
|
|
128
101
|
top: -9999,
|
|
129
102
|
opacity: 0
|
|
130
103
|
} }), _ = () => {
|
|
131
|
-
let e =
|
|
104
|
+
let e = s(null), t = s({
|
|
132
105
|
ready: !1,
|
|
133
106
|
queue: []
|
|
134
|
-
}),
|
|
107
|
+
}), i = a((t, r, i) => {
|
|
108
|
+
console.log("inject", t, r, i);
|
|
135
109
|
let a;
|
|
136
110
|
try {
|
|
137
111
|
a = JSON.stringify({
|
|
138
112
|
requestId: t,
|
|
139
|
-
variant:
|
|
140
|
-
message:
|
|
141
|
-
},
|
|
113
|
+
variant: r,
|
|
114
|
+
message: i
|
|
115
|
+
}, n);
|
|
142
116
|
} catch (e) {
|
|
143
|
-
|
|
117
|
+
c.emit("FROM_WEBVIEW_WORKER", {
|
|
144
118
|
requestId: t,
|
|
145
119
|
type: "ERROR",
|
|
146
120
|
error: `serialize failed: ${e?.message ?? e}`
|
|
@@ -148,49 +122,53 @@ true;`, h = `<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body><scr
|
|
|
148
122
|
return;
|
|
149
123
|
}
|
|
150
124
|
e.current?.injectJavaScript(`window.handleMessage && window.handleMessage(${a}); true;`);
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
let e =
|
|
125
|
+
}, []);
|
|
126
|
+
o(() => {
|
|
127
|
+
let e = c.addListener("TO_WEBVIEW_WORKER", (e) => {
|
|
128
|
+
console.log("TO_WEBVIEW_WORKER", e);
|
|
154
129
|
let n = {
|
|
155
130
|
requestId: e?.__requestId ?? "",
|
|
156
131
|
variant: e?.variant ?? "",
|
|
157
132
|
message: e?.message
|
|
158
133
|
};
|
|
159
|
-
t.current.ready ?
|
|
134
|
+
t.current.ready ? i(n.requestId, n.variant, n.message) : t.current.queue.push(n);
|
|
160
135
|
});
|
|
161
136
|
return () => e.remove();
|
|
162
|
-
}, [])
|
|
137
|
+
}, [i]);
|
|
138
|
+
let l = a((e) => {
|
|
139
|
+
console.log("onMessage", e), console.log("event.nativeEvent.data", e.nativeEvent.data);
|
|
140
|
+
let n;
|
|
141
|
+
try {
|
|
142
|
+
n = r(JSON.parse(e.nativeEvent.data));
|
|
143
|
+
} catch (e) {
|
|
144
|
+
c.emit("FROM_WEBVIEW_WORKER", {
|
|
145
|
+
type: "ERROR",
|
|
146
|
+
error: e?.message ?? "parse error"
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (n?.type === "READY") {
|
|
151
|
+
t.current.ready = !0;
|
|
152
|
+
let e = t.current.queue;
|
|
153
|
+
t.current.queue = [], e.forEach(({ requestId: e, variant: t, message: n }) => i(e, t, n));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
c.emit("FROM_WEBVIEW_WORKER", n);
|
|
157
|
+
}, [i]);
|
|
158
|
+
return /* @__PURE__ */ f(u, {
|
|
163
159
|
pointerEvents: "none",
|
|
164
160
|
style: g.hiddenHost,
|
|
165
|
-
children: /* @__PURE__ */
|
|
161
|
+
children: /* @__PURE__ */ f(d, {
|
|
166
162
|
ref: e,
|
|
167
163
|
source: {
|
|
168
164
|
html: h,
|
|
169
|
-
baseUrl:
|
|
165
|
+
baseUrl: p
|
|
170
166
|
},
|
|
171
167
|
originWhitelist: ["*"],
|
|
172
168
|
javaScriptEnabled: !0,
|
|
173
169
|
domStorageEnabled: !0,
|
|
174
170
|
androidLayerType: "hardware",
|
|
175
|
-
onMessage:
|
|
176
|
-
let n;
|
|
177
|
-
try {
|
|
178
|
-
n = f(JSON.parse(e.nativeEvent.data));
|
|
179
|
-
} catch (e) {
|
|
180
|
-
i.emit("FROM_WEBVIEW_WORKER", {
|
|
181
|
-
type: "ERROR",
|
|
182
|
-
error: e?.message ?? "parse error"
|
|
183
|
-
});
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
if (n?.type === "READY") {
|
|
187
|
-
t.current.ready = !0;
|
|
188
|
-
let e = t.current.queue;
|
|
189
|
-
t.current.queue = [], e.forEach(({ requestId: e, variant: t, message: n }) => a(e, t, n));
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
i.emit("FROM_WEBVIEW_WORKER", n);
|
|
193
|
-
},
|
|
171
|
+
onMessage: l,
|
|
194
172
|
onLoad: () => e.current?.injectJavaScript(m)
|
|
195
173
|
})
|
|
196
174
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`./serialization.utils.cjs`);let t=require(`react-native`);var n=class{onmessage=null;onerror=null;requestId=e.nextRequestId();subscription;constructor(e){this.variant=e,this.subscription=t.DeviceEventEmitter.addListener(`FROM_WEBVIEW_WORKER`,e=>{console.log(`FROM_WEBVIEW_WORKER`,e),!(!e||e.requestId!==this.requestId)&&(e.type===`RESULT`?this.onmessage?.({data:e.data}):e.type===`ERROR`&&this.onerror?.(Error(e.error??`WebView worker error`)))})}postMessage(e){console.log(`postMessage`,e),t.DeviceEventEmitter.emit(`TO_WEBVIEW_WORKER`,{__requestId:this.requestId,variant:this.variant,message:e})}terminate(){this.subscription?.remove?.(),this.subscription=null}};exports.HinkalRNWorker=n;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WorkerVariant } from '../../common/src/webworker/worker.registry';
|
|
2
|
+
export declare class HinkalRNWorker {
|
|
3
|
+
private variant;
|
|
4
|
+
onmessage: ((event: {
|
|
5
|
+
data: any;
|
|
6
|
+
}) => void) | null;
|
|
7
|
+
onerror: ((error: any) => void) | null;
|
|
8
|
+
private requestId;
|
|
9
|
+
private subscription;
|
|
10
|
+
constructor(variant: WorkerVariant);
|
|
11
|
+
postMessage(message: unknown): void;
|
|
12
|
+
terminate(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { nextRequestId as e } from "./serialization.utils.mjs";
|
|
2
|
+
import { DeviceEventEmitter as t } from "react-native";
|
|
3
|
+
//#region libs/shared/sdk/src/react-native/bridge/HinkalRNWorker.ts
|
|
4
|
+
var n = class {
|
|
5
|
+
onmessage = null;
|
|
6
|
+
onerror = null;
|
|
7
|
+
requestId = e();
|
|
8
|
+
subscription;
|
|
9
|
+
constructor(e) {
|
|
10
|
+
this.variant = e, this.subscription = t.addListener("FROM_WEBVIEW_WORKER", (e) => {
|
|
11
|
+
console.log("FROM_WEBVIEW_WORKER", e), !(!e || e.requestId !== this.requestId) && (e.type === "RESULT" ? this.onmessage?.({ data: e.data }) : e.type === "ERROR" && this.onerror?.(Error(e.error ?? "WebView worker error")));
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
postMessage(e) {
|
|
15
|
+
console.log("postMessage", e), t.emit("TO_WEBVIEW_WORKER", {
|
|
16
|
+
__requestId: this.requestId,
|
|
17
|
+
variant: this.variant,
|
|
18
|
+
message: e
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
terminate() {
|
|
22
|
+
this.subscription?.remove?.(), this.subscription = null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { n as HinkalRNWorker };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=(e,t)=>(console.log(`bigIntReplacer`,t),typeof t==`bigint`?{__bigint:t.toString()}:t instanceof Set?{__set:Array.from(t)}:t instanceof Map?{__map:Array.from(t.entries())}:t),t=e=>{if(console.log(`reviveBigInts`,e),typeof e!=`object`||!e)return e;let n=Object.keys(e);if(n.length===1){if(typeof e.__bigint==`string`)return BigInt(e.__bigint);if(Array.isArray(e.__set))return new Set(e.__set.map(t));if(Array.isArray(e.__map))return new Map(e.__map.map(e=>[t(e[0]),t(e[1])]))}return Array.isArray(e)?e.map(t):Object.fromEntries(n.map(n=>[n,t(e[n])]))},n=()=>`hinkal-rnw-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;exports.bigIntReplacer=e,exports.nextRequestId=n,exports.reviveBigInts=t;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region libs/shared/sdk/src/react-native/bridge/serialization.utils.ts
|
|
2
|
+
var e = (e, t) => (console.log("bigIntReplacer", t), typeof t == "bigint" ? { __bigint: t.toString() } : t instanceof Set ? { __set: Array.from(t) } : t instanceof Map ? { __map: Array.from(t.entries()) } : t), t = (e) => {
|
|
3
|
+
if (console.log("reviveBigInts", e), typeof e != "object" || !e) return e;
|
|
4
|
+
let n = Object.keys(e);
|
|
5
|
+
if (n.length === 1) {
|
|
6
|
+
if (typeof e.__bigint == "string") return BigInt(e.__bigint);
|
|
7
|
+
if (Array.isArray(e.__set)) return new Set(e.__set.map(t));
|
|
8
|
+
if (Array.isArray(e.__map)) return new Map(e.__map.map((e) => [t(e[0]), t(e[1])]));
|
|
9
|
+
}
|
|
10
|
+
return Array.isArray(e) ? e.map(t) : Object.fromEntries(n.map((n) => [n, t(e[n])]));
|
|
11
|
+
}, n = () => `hinkal-rnw-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { e as bigIntReplacer, n as nextRequestId, t as reviveBigInts };
|
|
@@ -17,13 +17,9 @@ const shim = (name) => ({
|
|
|
17
17
|
type: 'sourceFile',
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
const isFromHinkalSdk = (originPath) =>
|
|
21
|
-
!!originPath &&
|
|
22
|
-
(originPath.includes('/@hinkal/sdk/') ||
|
|
23
|
-
originPath.includes('/@sabaaa1/common/') ||
|
|
24
|
-
originPath.includes('/hi-test/'));
|
|
20
|
+
const isFromHinkalSdk = (originPath) => !!originPath && originPath.includes('/@hinkal/sdk/');
|
|
25
21
|
|
|
26
|
-
|
|
22
|
+
const applyHinkalMetroConfig = (config) => {
|
|
27
23
|
if (!config || !config.resolver) {
|
|
28
24
|
throw new Error('applyHinkalMetroConfig: pass a Metro config (e.g. from `getDefaultConfig(__dirname)`).');
|
|
29
25
|
}
|
|
@@ -46,10 +42,13 @@ function applyHinkalMetroConfig(config) {
|
|
|
46
42
|
assert: require.resolve('assert/'),
|
|
47
43
|
};
|
|
48
44
|
|
|
45
|
+
console.log('config.transformer', config.transformer);
|
|
46
|
+
|
|
49
47
|
const prevGetTransformOptions = config.transformer && config.transformer.getTransformOptions;
|
|
50
48
|
config.transformer = {
|
|
51
49
|
...(config.transformer || {}),
|
|
52
50
|
getTransformOptions: async (...args) => {
|
|
51
|
+
console.log('getTransformOptions', args);
|
|
53
52
|
const upstream = prevGetTransformOptions ? await prevGetTransformOptions(...args) : {};
|
|
54
53
|
return {
|
|
55
54
|
...upstream,
|
|
@@ -65,6 +64,9 @@ function applyHinkalMetroConfig(config) {
|
|
|
65
64
|
const upstreamResolve = config.resolver.resolveRequest;
|
|
66
65
|
|
|
67
66
|
config.resolver.resolveRequest = (context, moduleName, platform) => {
|
|
67
|
+
console.log('resolveRequest', moduleName);
|
|
68
|
+
console.log('context', context);
|
|
69
|
+
console.log('platform', platform);
|
|
68
70
|
if (moduleName === 'url') return shim('url');
|
|
69
71
|
if (moduleName === 'web-worker' || moduleName.startsWith('web-worker/')) return shim('web-worker');
|
|
70
72
|
if (moduleName === 'ffjavascript') return shim('ffjavascript');
|
|
@@ -89,6 +91,6 @@ function applyHinkalMetroConfig(config) {
|
|
|
89
91
|
};
|
|
90
92
|
|
|
91
93
|
return config;
|
|
92
|
-
}
|
|
94
|
+
};
|
|
93
95
|
|
|
94
96
|
module.exports = { applyHinkalMetroConfig };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
function notSupported(name) {
|
|
2
|
+
console.log('notSupported', name);
|
|
2
3
|
return () => {
|
|
3
4
|
throw new Error(
|
|
4
5
|
`[hinkal-rn] circomlibjs-hinkal-fork.${name} is not available on React Native. ` +
|
|
@@ -11,5 +12,4 @@ module.exports = {
|
|
|
11
12
|
buildPoseidon: notSupported('buildPoseidon'),
|
|
12
13
|
buildPoseidonReference: notSupported('buildPoseidonReference'),
|
|
13
14
|
buildBabyjub: notSupported('buildBabyjub'),
|
|
14
|
-
buildBabyJub: notSupported('buildBabyJub'),
|
|
15
15
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
function notSupported(name) {
|
|
2
|
+
console.log('notSupported', name);
|
|
2
3
|
return () => {
|
|
3
4
|
throw new Error(
|
|
4
5
|
`[hinkal-rn] circomlibjs.${name} is not available on React Native. ` +
|
|
@@ -12,5 +13,4 @@ module.exports = {
|
|
|
12
13
|
buildPoseidonReference: notSupported('buildPoseidonReference'),
|
|
13
14
|
buildPoseidonWasm: notSupported('buildPoseidonWasm'),
|
|
14
15
|
buildBabyjub: notSupported('buildBabyjub'),
|
|
15
|
-
buildBabyJub: notSupported('buildBabyJub'),
|
|
16
16
|
};
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
// Node `crypto` shim for React Native.
|
|
2
2
|
|
|
3
|
-
const { sha256, sha512, keccak256 } = require(
|
|
4
|
-
const { Buffer } = require(
|
|
3
|
+
const { sha256, sha512, keccak256 } = require('ethers');
|
|
4
|
+
const { Buffer } = require('buffer');
|
|
5
5
|
|
|
6
6
|
function ensureRng() {
|
|
7
|
-
if (!global.crypto || typeof global.crypto.getRandomValues !==
|
|
7
|
+
if (!global.crypto || typeof global.crypto.getRandomValues !== 'function') {
|
|
8
8
|
throw new Error(
|
|
9
|
-
|
|
9
|
+
'[hinkal-rn] global.crypto.getRandomValues is not available. ' +
|
|
10
10
|
"Import 'react-native-get-random-values' at the top of index.ts/js " +
|
|
11
|
-
|
|
11
|
+
'before any other module.',
|
|
12
12
|
);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
function randomBytes(size) {
|
|
17
17
|
ensureRng();
|
|
18
|
+
console.log('randomBytes', size);
|
|
18
19
|
const arr = new Uint8Array(size);
|
|
19
20
|
global.crypto.getRandomValues(arr);
|
|
20
21
|
return Buffer.from(arr);
|
|
@@ -22,6 +23,7 @@ function randomBytes(size) {
|
|
|
22
23
|
|
|
23
24
|
function randomFillSync(buf, offset, size) {
|
|
24
25
|
ensureRng();
|
|
26
|
+
console.log('randomFillSync', buf, offset, size);
|
|
25
27
|
const start = offset ?? 0;
|
|
26
28
|
const end = size != null ? start + size : buf.length;
|
|
27
29
|
const view = new Uint8Array(buf.buffer || buf, buf.byteOffset || 0, buf.length);
|
|
@@ -32,17 +34,19 @@ function randomFillSync(buf, offset, size) {
|
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
function randomUUID() {
|
|
37
|
+
console.log('randomUUID');
|
|
35
38
|
// RFC 4122 v4 UUID via crypto-secure bytes.
|
|
36
39
|
const b = randomBytes(16);
|
|
37
40
|
b[6] = (b[6] & 0x0f) | 0x40;
|
|
38
41
|
b[8] = (b[8] & 0x3f) | 0x80;
|
|
39
|
-
const hex = b.toString(
|
|
42
|
+
const hex = b.toString('hex');
|
|
40
43
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
function toBytesLike(input) {
|
|
47
|
+
console.log('toBytesLike', input);
|
|
44
48
|
if (input == null) return new Uint8Array(0);
|
|
45
|
-
if (typeof input ===
|
|
49
|
+
if (typeof input === 'string') return Buffer.from(input, 'utf8');
|
|
46
50
|
if (input instanceof Uint8Array) return input;
|
|
47
51
|
if (Buffer.isBuffer(input)) return input;
|
|
48
52
|
if (input.buffer) return new Uint8Array(input.buffer, input.byteOffset || 0, input.byteLength || input.length);
|
|
@@ -50,11 +54,13 @@ function toBytesLike(input) {
|
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
function hexToBuffer(hex) {
|
|
53
|
-
|
|
57
|
+
console.log('hexToBuffer', hex);
|
|
58
|
+
return Buffer.from(hex.replace(/^0x/, ''), 'hex');
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
function createHash(algorithm) {
|
|
57
|
-
|
|
62
|
+
console.log('createHash', algorithm);
|
|
63
|
+
const alg = String(algorithm).toLowerCase().replace('-', '');
|
|
58
64
|
const chunks = [];
|
|
59
65
|
return {
|
|
60
66
|
update(chunk) {
|
|
@@ -70,21 +76,22 @@ function createHash(algorithm) {
|
|
|
70
76
|
off += c.length;
|
|
71
77
|
}
|
|
72
78
|
let hex;
|
|
73
|
-
if (alg ===
|
|
74
|
-
else if (alg ===
|
|
75
|
-
else if (alg ===
|
|
79
|
+
if (alg === 'sha256') hex = sha256(merged);
|
|
80
|
+
else if (alg === 'sha512') hex = sha512(merged);
|
|
81
|
+
else if (alg === 'keccak256') hex = keccak256(merged);
|
|
76
82
|
else throw new Error(`[hinkal-rn] unsupported hash algorithm: ${algorithm}`);
|
|
77
83
|
const buf = hexToBuffer(hex);
|
|
78
84
|
if (!encoding) return buf;
|
|
79
|
-
if (encoding ===
|
|
80
|
-
if (encoding ===
|
|
85
|
+
if (encoding === 'hex') return buf.toString('hex');
|
|
86
|
+
if (encoding === 'base64') return buf.toString('base64');
|
|
81
87
|
return buf.toString(encoding);
|
|
82
88
|
},
|
|
83
89
|
};
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
function createHmac() {
|
|
87
|
-
|
|
93
|
+
console.log('createHmac');
|
|
94
|
+
throw new Error('[hinkal-rn] crypto.createHmac is not implemented in the RN shim. Use a JS implementation.');
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
module.exports = {
|
|
@@ -93,7 +100,7 @@ module.exports = {
|
|
|
93
100
|
randomUUID,
|
|
94
101
|
createHash,
|
|
95
102
|
createHmac,
|
|
96
|
-
webcrypto: typeof global.crypto !==
|
|
103
|
+
webcrypto: typeof global.crypto !== 'undefined' ? global.crypto : undefined,
|
|
97
104
|
getRandomValues: (arr) => {
|
|
98
105
|
ensureRng();
|
|
99
106
|
global.crypto.getRandomValues(arr);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { Buffer } from
|
|
2
|
-
import * as ReactNative from
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import * as ReactNative from 'react-native';
|
|
3
3
|
global.Buffer = Buffer;
|
|
4
4
|
|
|
5
|
-
if (typeof global.require ===
|
|
5
|
+
if (typeof global.require === 'undefined') {
|
|
6
|
+
console.log('global.require is undefined');
|
|
6
7
|
global.require = (m) => {
|
|
7
|
-
|
|
8
|
+
console.log('global.require', m);
|
|
9
|
+
if (m === 'react-native') return ReactNative;
|
|
8
10
|
throw new Error(`global.require shim: unsupported module "${m}"`);
|
|
9
11
|
};
|
|
10
12
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// idb-keyval shim for React Native
|
|
2
|
-
const AsyncStorage =
|
|
3
|
-
require("@react-native-async-storage/async-storage").default;
|
|
1
|
+
// idb-keyval shim for React Native
|
|
2
|
+
const AsyncStorage = require('@react-native-async-storage/async-storage').default;
|
|
4
3
|
|
|
5
|
-
const PREFIX =
|
|
6
|
-
const key = (k) => `${PREFIX}${typeof k ===
|
|
4
|
+
const PREFIX = '@hinkal/idb-keyval:';
|
|
5
|
+
const key = (k) => `${PREFIX}${typeof k === 'string' ? k : JSON.stringify(k)}`;
|
|
7
6
|
|
|
8
7
|
async function get(k) {
|
|
8
|
+
console.log('get', k);
|
|
9
9
|
const raw = await AsyncStorage.getItem(key(k));
|
|
10
10
|
if (raw == null) return undefined;
|
|
11
11
|
try {
|
|
@@ -16,6 +16,7 @@ async function get(k) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
async function set(k, value) {
|
|
19
|
+
console.log('set', k, value);
|
|
19
20
|
if (value === undefined) {
|
|
20
21
|
await AsyncStorage.removeItem(key(k));
|
|
21
22
|
return;
|
|
@@ -24,6 +25,7 @@ async function set(k, value) {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
async function update(k, updater) {
|
|
28
|
+
console.log('update', k, updater);
|
|
27
29
|
const current = await get(k);
|
|
28
30
|
const next = updater(current);
|
|
29
31
|
await set(k, next);
|
|
@@ -31,32 +33,38 @@ async function update(k, updater) {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
async function del(k) {
|
|
36
|
+
console.log('del', k);
|
|
34
37
|
await AsyncStorage.removeItem(key(k));
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
async function clear() {
|
|
41
|
+
console.log('clear');
|
|
38
42
|
const all = await AsyncStorage.getAllKeys();
|
|
39
43
|
const ours = all.filter((x) => x.startsWith(PREFIX));
|
|
40
44
|
if (ours.length) await AsyncStorage.multiRemove(ours);
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
async function keys() {
|
|
48
|
+
console.log('keys');
|
|
44
49
|
const all = await AsyncStorage.getAllKeys();
|
|
45
50
|
return all.filter((x) => x.startsWith(PREFIX)).map((x) => x.slice(PREFIX.length));
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
async function values() {
|
|
54
|
+
console.log('values');
|
|
49
55
|
const ks = await keys();
|
|
50
56
|
return Promise.all(ks.map(get));
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
async function entries() {
|
|
60
|
+
console.log('entries');
|
|
54
61
|
const ks = await keys();
|
|
55
62
|
const vs = await Promise.all(ks.map(get));
|
|
56
63
|
return ks.map((k, i) => [k, vs[i]]);
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
function createStore() {
|
|
67
|
+
console.log('createStore');
|
|
60
68
|
// idb-keyval lets callers create a store with a custom DB name; we ignore it
|
|
61
69
|
return undefined;
|
|
62
70
|
}
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
join: (...args) =>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
join: (...args) => {
|
|
3
|
+
console.log('join', args);
|
|
4
|
+
return args.join('/');
|
|
5
|
+
},
|
|
6
|
+
resolve: (...args) => {
|
|
7
|
+
console.log('resolve', args);
|
|
8
|
+
return args.join('/');
|
|
9
|
+
},
|
|
10
|
+
dirname: (p) => {
|
|
11
|
+
console.log('dirname', p);
|
|
12
|
+
return p.split('/').slice(0, -1).join('/');
|
|
13
|
+
},
|
|
14
|
+
basename: (p) => {
|
|
15
|
+
console.log('basename', p);
|
|
16
|
+
return p.split('/').pop();
|
|
17
|
+
},
|
|
6
18
|
extname: (p) => {
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
19
|
+
console.log('extname', p);
|
|
20
|
+
const base = p.split('/').pop();
|
|
21
|
+
const idx = base.lastIndexOf('.');
|
|
22
|
+
return idx < 0 ? '' : base.slice(idx);
|
|
10
23
|
},
|
|
11
24
|
};
|