@argent/x-shared 1.74.1 → 1.75.0
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/dist/index.cjs +1 -1
- package/dist/index.js +212 -209
- package/dist/node_modules/.pnpm/@noble_curves@1.0.0/node_modules/@noble/curves/esm/abstract/modular.js +5 -5
- package/dist/node_modules/.pnpm/@noble_curves@1.0.0/node_modules/@noble/curves/esm/abstract/weierstrass.cjs +1 -1
- package/dist/node_modules/.pnpm/@noble_curves@1.0.0/node_modules/@noble/curves/esm/abstract/weierstrass.js +13 -14
- package/dist/node_modules/.pnpm/@noble_hashes@1.3.3/node_modules/@noble/hashes/esm/sha3.cjs +1 -1
- package/dist/node_modules/.pnpm/@noble_hashes@1.3.3/node_modules/@noble/hashes/esm/sha3.js +3 -3
- package/dist/node_modules/.pnpm/@noble_hashes@1.5.0/node_modules/@noble/hashes/esm/sha3.cjs +1 -1
- package/dist/node_modules/.pnpm/@noble_hashes@1.5.0/node_modules/@noble/hashes/esm/sha3.js +3 -3
- package/dist/node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getValue.cjs +1 -1
- package/dist/node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getValue.js +1 -1
- package/dist/node_modules/.pnpm/micro-starknet@0.2.3/node_modules/micro-starknet/lib/esm/index.js +6 -6
- package/dist/src/chains/starknet/address.cjs +1 -1
- package/dist/src/chains/starknet/address.js +17 -17
- package/dist/src/chains/starknet/services/deploymentData/findImplementationForAccount.js +1 -1
- package/dist/src/chains/starknet/services/deploymentData/getAccountClassHash.js +1 -1
- package/dist/src/features/defiDecomposition/helpers/computeCollateralizedDebtPositionsUsdValue.cjs +1 -1
- package/dist/src/features/defiDecomposition/helpers/computeCollateralizedDebtPositionsUsdValue.js +27 -27
- package/dist/src/features/defiDecomposition/helpers/computeConcentratedLiquidityPositionsUsdValue.cjs +1 -1
- package/dist/src/features/defiDecomposition/helpers/computeConcentratedLiquidityPositionsUsdValue.js +22 -22
- package/dist/src/features/defiDecomposition/helpers/computeDelegatedTokensPositionsUsdValue.cjs +1 -1
- package/dist/src/features/defiDecomposition/helpers/computeDelegatedTokensPositionsUsdValue.js +14 -14
- package/dist/src/features/defiDecomposition/helpers/computeStakingPositionsUsdValue.cjs +1 -1
- package/dist/src/features/defiDecomposition/helpers/computeStakingPositionsUsdValue.js +9 -9
- package/dist/src/features/defiDecomposition/helpers/computeStrkDelegatedStakingPositionsUsdValue.cjs +1 -1
- package/dist/src/features/defiDecomposition/helpers/computeStrkDelegatedStakingPositionsUsdValue.js +13 -13
- package/dist/src/features/defiDecomposition/helpers/parseCollateralizedDebtPositions.cjs +1 -1
- package/dist/src/features/defiDecomposition/helpers/parseCollateralizedDebtPositions.js +24 -25
- package/dist/src/features/simulation/activity/normalize.cjs +1 -1
- package/dist/src/features/simulation/activity/normalize.js +12 -13
- package/dist/src/features/simulation/activity/schema.cjs +1 -1
- package/dist/src/features/simulation/activity/schema.js +6 -6
- package/dist/src/features/simulation/activity/utils/createNativeActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/createNativeActivity.js +22 -24
- package/dist/src/features/simulation/activity/utils/getAnyActivityTitle.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/getAnyActivityTitle.js +11 -12
- package/dist/src/features/simulation/activity/utils/hasDelegationActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/hasDelegationActivity.js +2 -8
- package/dist/src/features/simulation/activity/utils/isAddMultisigSignersActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isAddMultisigSignersActivity.js +4 -8
- package/dist/src/features/simulation/activity/utils/isChangeMultisigThresholdActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isChangeMultisigThresholdActivity.js +4 -8
- package/dist/src/features/simulation/activity/utils/isMulticallWithDeploymentActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isMulticallWithDeploymentActivity.js +3 -9
- package/dist/src/features/simulation/activity/utils/isRejectOnChainActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isRejectOnChainActivity.js +15 -19
- package/dist/src/features/simulation/activity/utils/isRemoveMultisigSignersActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isRemoveMultisigSignersActivity.js +4 -8
- package/dist/src/features/simulation/activity/utils/isSwapActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isSwapActivity.js +9 -16
- package/dist/src/features/simulation/activity/utils/isUpgradeActivity.cjs +1 -1
- package/dist/src/features/simulation/activity/utils/isUpgradeActivity.js +4 -8
- package/dist/src/features/simulation/fees/schema.cjs +1 -1
- package/dist/src/features/simulation/fees/schema.d.ts +16 -0
- package/dist/src/features/simulation/fees/schema.js +8 -6
- package/dist/src/features/simulation/transactionReview/getErrorMessageAndLabelFromSimulation.cjs +1 -1
- package/dist/src/features/simulation/transactionReview/getErrorMessageAndLabelFromSimulation.js +10 -11
- package/dist/src/features/simulation/transactionReview/schema.cjs +1 -1
- package/dist/src/features/simulation/transactionReview/schema.d.ts +23 -0
- package/dist/src/features/simulation/transactionReview/schema.js +21 -19
- package/dist/src/features/swap/services/SwapTransactionService.cjs +1 -1
- package/dist/src/features/swap/services/SwapTransactionService.js +46 -49
- package/dist/src/http/HttpService.cjs +1 -1
- package/dist/src/http/HttpService.js +55 -55
- package/dist/src/knownDapps/utils/getDapplandUrl.cjs +1 -1
- package/dist/src/knownDapps/utils/getDapplandUrl.js +6 -8
- package/dist/src/nfts/BackendNftService.cjs +1 -1
- package/dist/src/nfts/BackendNftService.js +18 -19
- package/dist/src/tokens/service/implementation.cjs +1 -1
- package/dist/src/tokens/service/implementation.js +12 -12
- package/dist/src/tokens/service/types/backend.model.js +1 -1
- package/dist/src/transactions/estimate/utils.cjs +1 -1
- package/dist/src/transactions/estimate/utils.d.ts +33 -0
- package/dist/src/transactions/estimate/utils.js +80 -76
- package/dist/src/transactions/service/implementation.cjs +1 -1
- package/dist/src/transactions/service/implementation.d.ts +4 -0
- package/dist/src/transactions/service/implementation.js +89 -96
- package/dist/src/transactions/service/utils.cjs +1 -1
- package/dist/src/transactions/service/utils.d.ts +2 -3
- package/dist/src/transactions/service/utils.js +12 -11
- package/dist/src/transactions/transactionVersion.cjs +1 -1
- package/dist/src/transactions/transactionVersion.d.ts +2 -0
- package/dist/src/transactions/transactionVersion.js +12 -10
- package/dist/src/utils/base58.js +5 -5
- package/dist/src/utils/number/abbreviateNumber.d.ts +2 -1
- package/dist/src/utils/readFileAsString.cjs +1 -1
- package/dist/src/utils/readFileAsString.js +3 -6
- package/package.json +23 -23
- package/dist/node_modules/.pnpm/@starknet-io_types-js@0.7.7/node_modules/@starknet-io/types-js/dist/esm/api/nonspec.cjs +0 -1
- package/dist/node_modules/.pnpm/@starknet-io_types-js@0.7.7/node_modules/@starknet-io/types-js/dist/esm/api/nonspec.js +0 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { numberToBytesLE as L, numberToBytesBE as T, bitMask as _, bytesToNumberLE as y, bytesToNumberBE as m, ensureBytes as $, validateObject as C } from "./utils.js";
|
|
2
2
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
3
|
const f = BigInt(0), u = BigInt(1), w = BigInt(2), M = BigInt(3), E = BigInt(4), b = BigInt(5), I = BigInt(8);
|
|
4
4
|
BigInt(9);
|
|
@@ -109,7 +109,7 @@ function Q(e) {
|
|
|
109
109
|
BYTES: "isSafeInteger",
|
|
110
110
|
BITS: "isSafeInteger"
|
|
111
111
|
}, n = A.reduce((r, s) => (r[s] = "function", r), o);
|
|
112
|
-
return
|
|
112
|
+
return C(e, n);
|
|
113
113
|
}
|
|
114
114
|
function O(e, o, n) {
|
|
115
115
|
if (n < f)
|
|
@@ -141,7 +141,7 @@ function V(e, o, n = !1, r = {}) {
|
|
|
141
141
|
ORDER: e,
|
|
142
142
|
BITS: s,
|
|
143
143
|
BYTES: c,
|
|
144
|
-
MASK:
|
|
144
|
+
MASK: _(s),
|
|
145
145
|
ZERO: f,
|
|
146
146
|
ONE: u,
|
|
147
147
|
create: (t) => g(t, e),
|
|
@@ -171,7 +171,7 @@ function V(e, o, n = !1, r = {}) {
|
|
|
171
171
|
// TODO: do we really need constant cmov?
|
|
172
172
|
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
173
173
|
cmov: (t, l, a) => a ? l : t,
|
|
174
|
-
toBytes: (t) => n ?
|
|
174
|
+
toBytes: (t) => n ? L(t, c) : T(t, c),
|
|
175
175
|
fromBytes: (t) => {
|
|
176
176
|
if (t.length !== c)
|
|
177
177
|
throw new Error(`Fp.fromBytes: expected ${c}, got ${t.length}`);
|
|
@@ -181,7 +181,7 @@ function V(e, o, n = !1, r = {}) {
|
|
|
181
181
|
return Object.freeze(i);
|
|
182
182
|
}
|
|
183
183
|
function Y(e, o, n = !1) {
|
|
184
|
-
e =
|
|
184
|
+
e = $("privateHash", e);
|
|
185
185
|
const r = e.length, s = x(o).nByteLength + 8;
|
|
186
186
|
if (s < 24 || r < s || r > 1024)
|
|
187
187
|
throw new Error(`hashToPrivateScalar: expected ${s}-1024 bytes of input, got ${r}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("./modular.cjs"),m=require("./utils.cjs"),et=require("./curve.cjs");/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function at(v){const n=et.validateBasic(v);m.validateObject(n,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:t,Fp:x,a:O}=n;if(t){if(!x.eql(O,x.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...n})}const{bytesToNumberBE:ct,hexToBytes:ut}=m,$={Err:class extends Error{constructor(n=""){super(n)}},_parseInt(v){const{Err:n}=$;if(v.length<2||v[0]!==2)throw new n("Invalid signature integer tag");const t=v[1],x=v.subarray(2,t+2);if(!t||x.length!==t)throw new n("Invalid signature integer: wrong length");if(x[0]&128)throw new n("Invalid signature integer: negative");if(x[0]===0&&!(x[1]&128))throw new n("Invalid signature integer: unnecessary leading zero");return{d:ct(x),l:v.subarray(t+2)}},toSig(v){const{Err:n}=$,t=typeof v=="string"?ut(v):v;if(!(t instanceof Uint8Array))throw new Error("ui8a expected");let x=t.length;if(x<2||t[0]!=48)throw new n("Invalid signature tag");if(t[1]!==x-2)throw new n("Invalid signature: incorrect length");const{d:O,l:T}=$._parseInt(t.subarray(2)),{d:F,l:R}=$._parseInt(T);if(R.length)throw new n("Invalid signature: left bytes after parsing");return{r:O,s:F}},hexFromSig(v){const n=S=>Number.parseInt(S[0],16)&8?"00"+S:S,t=S=>{const V=S.toString(16);return V.length&1?`0${V}`:V},x=n(t(v.s)),O=n(t(v.r)),T=x.length/2,F=O.length/2,R=t(T),L=t(F);return`30${t(F+T+4)}02${L}${O}02${R}${x}`}},P=BigInt(0),U=BigInt(1);BigInt(2);const ot=BigInt(3);BigInt(4);function it(v){const n=at(v),{Fp:t}=n,x=n.toBytes||((y,r,i)=>{const o=r.toAffine();return m.concatBytes(Uint8Array.from([4]),t.toBytes(o.x),t.toBytes(o.y))}),O=n.fromBytes||(y=>{const r=y.subarray(1),i=t.fromBytes(r.subarray(0,t.BYTES)),o=t.fromBytes(r.subarray(t.BYTES,2*t.BYTES));return{x:i,y:o}});function T(y){const{a:r,b:i}=n,o=t.sqr(y),u=t.mul(o,y);return t.add(t.add(u,t.mul(y,r)),i)}if(!t.eql(t.sqr(n.Gy),T(n.Gx)))throw new Error("bad generator point: equation left != right");function F(y){return typeof y=="bigint"&&P<y&&y<n.n}function R(y){if(!F(y))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function L(y){const{allowedPrivateKeyLengths:r,nByteLength:i,wrapPrivateKey:o,n:u}=n;if(r&&typeof y!="bigint"){if(y instanceof Uint8Array&&(y=m.bytesToHex(y)),typeof y!="string"||!r.includes(y.length))throw new Error("Invalid key");y=y.padStart(i*2,"0")}let f;try{f=typeof y=="bigint"?y:m.bytesToNumberBE(m.ensureBytes("private key",y,i))}catch{throw new Error(`private key must be ${i} bytes, hex or bigint, not ${typeof y}`)}return o&&(f=_.mod(f,u)),R(f),f}const S=new Map;function V(y){if(!(y instanceof w))throw new Error("ProjectivePoint expected")}class w{constructor(r,i,o){if(this.px=r,this.py=i,this.pz=o,r==null||!t.isValid(r))throw new Error("x required");if(i==null||!t.isValid(i))throw new Error("y required");if(o==null||!t.isValid(o))throw new Error("z required")}static fromAffine(r){const{x:i,y:o}=r||{};if(!r||!t.isValid(i)||!t.isValid(o))throw new Error("invalid affine point");if(r instanceof w)throw new Error("projective point not allowed");const u=f=>t.eql(f,t.ZERO);return u(i)&&u(o)?w.ZERO:new w(i,o,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(r){const i=t.invertBatch(r.map(o=>o.pz));return r.map((o,u)=>o.toAffine(i[u])).map(w.fromAffine)}static fromHex(r){const i=w.fromAffine(O(m.ensureBytes("pointHex",r)));return i.assertValidity(),i}static fromPrivateKey(r){return w.BASE.multiply(L(r))}_setWindowSize(r){this._WINDOW_SIZE=r,S.delete(this)}assertValidity(){if(this.is0()){if(n.allowInfinityPoint)return;throw new Error("bad point: ZERO")}const{x:r,y:i}=this.toAffine();if(!t.isValid(r)||!t.isValid(i))throw new Error("bad point: x or y not FE");const o=t.sqr(i),u=T(r);if(!t.eql(o,u))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:r}=this.toAffine();if(t.isOdd)return!t.isOdd(r);throw new Error("Field doesn't support isOdd")}equals(r){V(r);const{px:i,py:o,pz:u}=this,{px:f,py:g,pz:h}=r,a=t.eql(t.mul(i,h),t.mul(f,u)),c=t.eql(t.mul(o,h),t.mul(g,u));return a&&c}negate(){return new w(this.px,t.neg(this.py),this.pz)}double(){const{a:r,b:i}=n,o=t.mul(i,ot),{px:u,py:f,pz:g}=this;let h=t.ZERO,a=t.ZERO,c=t.ZERO,d=t.mul(u,u),q=t.mul(f,f),B=t.mul(g,g),p=t.mul(u,f);return p=t.add(p,p),c=t.mul(u,g),c=t.add(c,c),h=t.mul(r,c),a=t.mul(o,B),a=t.add(h,a),h=t.sub(q,a),a=t.add(q,a),a=t.mul(h,a),h=t.mul(p,h),c=t.mul(o,c),B=t.mul(r,B),p=t.sub(d,B),p=t.mul(r,p),p=t.add(p,c),c=t.add(d,d),d=t.add(c,d),d=t.add(d,B),d=t.mul(d,p),a=t.add(a,d),B=t.mul(f,g),B=t.add(B,B),d=t.mul(B,p),h=t.sub(h,d),c=t.mul(B,q),c=t.add(c,c),c=t.add(c,c),new w(h,a,c)}add(r){V(r);const{px:i,py:o,pz:u}=this,{px:f,py:g,pz:h}=r;let a=t.ZERO,c=t.ZERO,d=t.ZERO;const q=n.a,B=t.mul(n.b,ot);let p=t.mul(i,f),N=t.mul(o,g),Z=t.mul(u,h),H=t.add(i,o),e=t.add(f,g);H=t.mul(H,e),e=t.add(p,N),H=t.sub(H,e),e=t.add(i,u);let s=t.add(f,h);return e=t.mul(e,s),s=t.add(p,Z),e=t.sub(e,s),s=t.add(o,u),a=t.add(g,h),s=t.mul(s,a),a=t.add(N,Z),s=t.sub(s,a),d=t.mul(q,e),a=t.mul(B,Z),d=t.add(a,d),a=t.sub(N,d),d=t.add(N,d),c=t.mul(a,d),N=t.add(p,p),N=t.add(N,p),Z=t.mul(q,Z),e=t.mul(B,e),N=t.add(N,Z),Z=t.sub(p,Z),Z=t.mul(q,Z),e=t.add(e,Z),p=t.mul(N,e),c=t.add(c,p),p=t.mul(s,e),a=t.mul(H,a),a=t.sub(a,p),p=t.mul(H,N),d=t.mul(s,d),d=t.add(d,p),new w(a,c,d)}subtract(r){return this.add(r.negate())}is0(){return this.equals(w.ZERO)}wNAF(r){return C.wNAFCached(this,S,r,i=>{const o=t.invertBatch(i.map(u=>u.pz));return i.map((u,f)=>u.toAffine(o[f])).map(w.fromAffine)})}multiplyUnsafe(r){const i=w.ZERO;if(r===P)return i;if(R(r),r===U)return this;const{endo:o}=n;if(!o)return C.unsafeLadder(this,r);let{k1neg:u,k1:f,k2neg:g,k2:h}=o.splitScalar(r),a=i,c=i,d=this;for(;f>P||h>P;)f&U&&(a=a.add(d)),h&U&&(c=c.add(d)),d=d.double(),f>>=U,h>>=U;return u&&(a=a.negate()),g&&(c=c.negate()),c=new w(t.mul(c.px,o.beta),c.py,c.pz),a.add(c)}multiply(r){R(r);let i=r,o,u;const{endo:f}=n;if(f){const{k1neg:g,k1:h,k2neg:a,k2:c}=f.splitScalar(i);let{p:d,f:q}=this.wNAF(h),{p:B,f:p}=this.wNAF(c);d=C.constTimeNegate(g,d),B=C.constTimeNegate(a,B),B=new w(t.mul(B.px,f.beta),B.py,B.pz),o=d.add(B),u=q.add(p)}else{const{p:g,f:h}=this.wNAF(i);o=g,u=h}return w.normalizeZ([o,u])[0]}multiplyAndAddUnsafe(r,i,o){const u=w.BASE,f=(h,a)=>a===P||a===U||!h.equals(u)?h.multiplyUnsafe(a):h.multiply(a),g=f(this,i).add(f(r,o));return g.is0()?void 0:g}toAffine(r){const{px:i,py:o,pz:u}=this,f=this.is0();r==null&&(r=f?t.ONE:t.inv(u));const g=t.mul(i,r),h=t.mul(o,r),a=t.mul(u,r);if(f)return{x:t.ZERO,y:t.ZERO};if(!t.eql(a,t.ONE))throw new Error("invZ was invalid");return{x:g,y:h}}isTorsionFree(){const{h:r,isTorsionFree:i}=n;if(r===U)return!0;if(i)return i(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:r,clearCofactor:i}=n;return r===U?this:i?i(w,this):this.multiplyUnsafe(n.h)}toRawBytes(r=!0){return this.assertValidity(),x(w,this,r)}toHex(r=!0){return m.bytesToHex(this.toRawBytes(r))}}w.BASE=new w(n.Gx,n.Gy,t.ONE),w.ZERO=new w(t.ZERO,t.ONE,t.ZERO);const W=n.nBitLength,C=et.wNAF(w,n.endo?Math.ceil(W/2):W);return{CURVE:n,ProjectivePoint:w,normPrivateKeyToScalar:L,weierstrassEquation:T,isWithinCurveOrder:F}}function lt(v){const n=et.validateBasic(v);return m.validateObject(n,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...n})}function ft(v){const n=lt(v),{Fp:t,n:x}=n,O=t.BYTES+1,T=2*t.BYTES+1;function F(e){return P<e&&e<t.ORDER}function R(e){return _.mod(e,x)}function L(e){return _.invert(e,x)}const{ProjectivePoint:S,normPrivateKeyToScalar:V,weierstrassEquation:w,isWithinCurveOrder:W}=it({...n,toBytes(e,s,l){const b=s.toAffine(),E=t.toBytes(b.x),A=m.concatBytes;return l?A(Uint8Array.from([s.hasEvenY()?2:3]),E):A(Uint8Array.from([4]),E,t.toBytes(b.y))},fromBytes(e){const s=e.length,l=e[0],b=e.subarray(1);if(s===O&&(l===2||l===3)){const E=m.bytesToNumberBE(b);if(!F(E))throw new Error("Point is not on curve");const A=w(E);let z=t.sqrt(A);const I=(z&U)===U;return(l&1)===1!==I&&(z=t.neg(z)),{x:E,y:z}}else if(s===T&&l===4){const E=t.fromBytes(b.subarray(0,t.BYTES)),A=t.fromBytes(b.subarray(t.BYTES,2*t.BYTES));return{x:E,y:A}}else throw new Error(`Point of length ${s} was invalid. Expected ${O} compressed bytes or ${T} uncompressed bytes`)}}),C=e=>m.bytesToHex(m.numberToBytesBE(e,n.nByteLength));function y(e){const s=x>>U;return e>s}function r(e){return y(e)?R(-e):e}const i=(e,s,l)=>m.bytesToNumberBE(e.slice(s,l));class o{constructor(s,l,b){this.r=s,this.s=l,this.recovery=b,this.assertValidity()}static fromCompact(s){const l=n.nByteLength;return s=m.ensureBytes("compactSignature",s,l*2),new o(i(s,0,l),i(s,l,2*l))}static fromDER(s){const{r:l,s:b}=$.toSig(m.ensureBytes("DER",s));return new o(l,b)}assertValidity(){if(!W(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!W(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(s){return new o(this.r,this.s,s)}recoverPublicKey(s){const{r:l,s:b,recovery:E}=this,A=c(m.ensureBytes("msgHash",s));if(E==null||![0,1,2,3].includes(E))throw new Error("recovery id invalid");const z=E===2||E===3?l+n.n:l;if(z>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");const I=E&1?"03":"02",D=S.fromHex(I+C(z)),j=L(z),X=R(-A*j),J=R(b*j),K=S.BASE.multiplyAndAddUnsafe(D,X,J);if(!K)throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new o(this.r,R(-this.s),this.recovery):this}toDERRawBytes(){return m.hexToBytes(this.toDERHex())}toDERHex(){return $.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return m.hexToBytes(this.toCompactHex())}toCompactHex(){return C(this.r)+C(this.s)}}const u={isValidPrivateKey(e){try{return V(e),!0}catch{return!1}},normPrivateKeyToScalar:V,randomPrivateKey:()=>{const e=n.randomBytes(t.BYTES+8),s=_.hashToPrivateScalar(e,x);return m.numberToBytesBE(s,n.nByteLength)},precompute(e=8,s=S.BASE){return s._setWindowSize(e),s.multiply(BigInt(3)),s}};function f(e,s=!0){return S.fromPrivateKey(e).toRawBytes(s)}function g(e){const s=e instanceof Uint8Array,l=typeof e=="string",b=(s||l)&&e.length;return s?b===O||b===T:l?b===2*O||b===2*T:e instanceof S}function h(e,s,l=!0){if(g(e))throw new Error("first arg must be private key");if(!g(s))throw new Error("second arg must be public key");return S.fromHex(s).multiply(V(e)).toRawBytes(l)}const a=n.bits2int||function(e){const s=m.bytesToNumberBE(e),l=e.length*8-n.nBitLength;return l>0?s>>BigInt(l):s},c=n.bits2int_modN||function(e){return R(a(e))},d=m.bitMask(n.nBitLength);function q(e){if(typeof e!="bigint")throw new Error("bigint expected");if(!(P<=e&&e<d))throw new Error(`bigint expected < 2^${n.nBitLength}`);return m.numberToBytesBE(e,n.nByteLength)}function B(e,s,l=p){if(["recovered","canonical"].some(k=>k in l))throw new Error("sign() legacy options not supported");const{hash:b,randomBytes:E}=n;let{lowS:A,prehash:z,extraEntropy:I}=l;A==null&&(A=!0),e=m.ensureBytes("msgHash",e),z&&(e=m.ensureBytes("prehashed msgHash",b(e)));const D=c(e),j=V(s),X=[q(j),q(D)];if(I!=null){const k=I===!0?E(t.BYTES):I;X.push(m.ensureBytes("extraEntropy",k,t.BYTES))}const J=m.concatBytes(...X),K=D;function tt(k){const G=a(k);if(!W(G))return;const rt=L(G),M=S.BASE.multiply(G).toAffine(),Y=R(M.x);if(Y===P)return;const Q=R(rt*R(K+Y*j));if(Q===P)return;let nt=(M.x===Y?0:2)|Number(M.y&U),st=Q;return A&&y(Q)&&(st=r(Q),nt^=1),new o(Y,st,nt)}return{seed:J,k2sig:tt}}const p={lowS:n.lowS,prehash:!1},N={lowS:n.lowS,prehash:!1};function Z(e,s,l=p){const{seed:b,k2sig:E}=B(e,s,l);return m.createHmacDrbg(n.hash.outputLen,n.nByteLength,n.hmac)(b,E)}S.BASE._setWindowSize(8);function H(e,s,l,b=N){var M;const E=e;if(s=m.ensureBytes("msgHash",s),l=m.ensureBytes("publicKey",l),"strict"in b)throw new Error("options.strict was renamed to lowS");const{lowS:A,prehash:z}=b;let I,D;try{if(typeof E=="string"||E instanceof Uint8Array)try{I=o.fromDER(E)}catch(Y){if(!(Y instanceof $.Err))throw Y;I=o.fromCompact(E)}else if(typeof E=="object"&&typeof E.r=="bigint"&&typeof E.s=="bigint"){const{r:Y,s:Q}=E;I=new o(Y,Q)}else throw new Error("PARSE");D=S.fromHex(l)}catch(Y){if(Y.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(A&&I.hasHighS())return!1;z&&(s=n.hash(s));const{r:j,s:X}=I,J=c(s),K=L(X),tt=R(J*K),k=R(j*K),G=(M=S.BASE.multiplyAndAddUnsafe(D,tt,k))==null?void 0:M.toAffine();return G?R(G.x)===j:!1}return{CURVE:n,getPublicKey:f,getSharedSecret:h,sign:Z,verify:H,ProjectivePoint:S,Signature:o,utils:u}}exports.DER=$;exports.weierstrass=ft;exports.weierstrassPoints=it;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("./modular.cjs"),m=require("./utils.cjs"),et=require("./curve.cjs");/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function at(v){const n=et.validateBasic(v);m.validateObject(n,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:t,Fp:x,a:O}=n;if(t){if(!x.eql(O,x.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...n})}const{bytesToNumberBE:ct,hexToBytes:ut}=m,$={Err:class extends Error{constructor(n=""){super(n)}},_parseInt(v){const{Err:n}=$;if(v.length<2||v[0]!==2)throw new n("Invalid signature integer tag");const t=v[1],x=v.subarray(2,t+2);if(!t||x.length!==t)throw new n("Invalid signature integer: wrong length");if(x[0]&128)throw new n("Invalid signature integer: negative");if(x[0]===0&&!(x[1]&128))throw new n("Invalid signature integer: unnecessary leading zero");return{d:ct(x),l:v.subarray(t+2)}},toSig(v){const{Err:n}=$,t=typeof v=="string"?ut(v):v;if(!(t instanceof Uint8Array))throw new Error("ui8a expected");let x=t.length;if(x<2||t[0]!=48)throw new n("Invalid signature tag");if(t[1]!==x-2)throw new n("Invalid signature: incorrect length");const{d:O,l:T}=$._parseInt(t.subarray(2)),{d:F,l:R}=$._parseInt(T);if(R.length)throw new n("Invalid signature: left bytes after parsing");return{r:O,s:F}},hexFromSig(v){const n=S=>Number.parseInt(S[0],16)&8?"00"+S:S,t=S=>{const V=S.toString(16);return V.length&1?`0${V}`:V},x=n(t(v.s)),O=n(t(v.r)),T=x.length/2,F=O.length/2,R=t(T),L=t(F);return`30${t(F+T+4)}02${L}${O}02${R}${x}`}},P=BigInt(0),U=BigInt(1);BigInt(2);const ot=BigInt(3);BigInt(4);function it(v){const n=at(v),{Fp:t}=n,x=n.toBytes||((y,r,i)=>{const o=r.toAffine();return m.concatBytes(Uint8Array.from([4]),t.toBytes(o.x),t.toBytes(o.y))}),O=n.fromBytes||(y=>{const r=y.subarray(1),i=t.fromBytes(r.subarray(0,t.BYTES)),o=t.fromBytes(r.subarray(t.BYTES,2*t.BYTES));return{x:i,y:o}});function T(y){const{a:r,b:i}=n,o=t.sqr(y),u=t.mul(o,y);return t.add(t.add(u,t.mul(y,r)),i)}if(!t.eql(t.sqr(n.Gy),T(n.Gx)))throw new Error("bad generator point: equation left != right");function F(y){return typeof y=="bigint"&&P<y&&y<n.n}function R(y){if(!F(y))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function L(y){const{allowedPrivateKeyLengths:r,nByteLength:i,wrapPrivateKey:o,n:u}=n;if(r&&typeof y!="bigint"){if(y instanceof Uint8Array&&(y=m.bytesToHex(y)),typeof y!="string"||!r.includes(y.length))throw new Error("Invalid key");y=y.padStart(i*2,"0")}let f;try{f=typeof y=="bigint"?y:m.bytesToNumberBE(m.ensureBytes("private key",y,i))}catch{throw new Error(`private key must be ${i} bytes, hex or bigint, not ${typeof y}`)}return o&&(f=_.mod(f,u)),R(f),f}const S=new Map;function V(y){if(!(y instanceof w))throw new Error("ProjectivePoint expected")}class w{constructor(r,i,o){if(this.px=r,this.py=i,this.pz=o,r==null||!t.isValid(r))throw new Error("x required");if(i==null||!t.isValid(i))throw new Error("y required");if(o==null||!t.isValid(o))throw new Error("z required")}static fromAffine(r){const{x:i,y:o}=r||{};if(!r||!t.isValid(i)||!t.isValid(o))throw new Error("invalid affine point");if(r instanceof w)throw new Error("projective point not allowed");const u=f=>t.eql(f,t.ZERO);return u(i)&&u(o)?w.ZERO:new w(i,o,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(r){const i=t.invertBatch(r.map(o=>o.pz));return r.map((o,u)=>o.toAffine(i[u])).map(w.fromAffine)}static fromHex(r){const i=w.fromAffine(O(m.ensureBytes("pointHex",r)));return i.assertValidity(),i}static fromPrivateKey(r){return w.BASE.multiply(L(r))}_setWindowSize(r){this._WINDOW_SIZE=r,S.delete(this)}assertValidity(){if(this.is0()){if(n.allowInfinityPoint)return;throw new Error("bad point: ZERO")}const{x:r,y:i}=this.toAffine();if(!t.isValid(r)||!t.isValid(i))throw new Error("bad point: x or y not FE");const o=t.sqr(i),u=T(r);if(!t.eql(o,u))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:r}=this.toAffine();if(t.isOdd)return!t.isOdd(r);throw new Error("Field doesn't support isOdd")}equals(r){V(r);const{px:i,py:o,pz:u}=this,{px:f,py:g,pz:h}=r,a=t.eql(t.mul(i,h),t.mul(f,u)),c=t.eql(t.mul(o,h),t.mul(g,u));return a&&c}negate(){return new w(this.px,t.neg(this.py),this.pz)}double(){const{a:r,b:i}=n,o=t.mul(i,ot),{px:u,py:f,pz:g}=this;let h=t.ZERO,a=t.ZERO,c=t.ZERO,d=t.mul(u,u),q=t.mul(f,f),B=t.mul(g,g),p=t.mul(u,f);return p=t.add(p,p),c=t.mul(u,g),c=t.add(c,c),h=t.mul(r,c),a=t.mul(o,B),a=t.add(h,a),h=t.sub(q,a),a=t.add(q,a),a=t.mul(h,a),h=t.mul(p,h),c=t.mul(o,c),B=t.mul(r,B),p=t.sub(d,B),p=t.mul(r,p),p=t.add(p,c),c=t.add(d,d),d=t.add(c,d),d=t.add(d,B),d=t.mul(d,p),a=t.add(a,d),B=t.mul(f,g),B=t.add(B,B),d=t.mul(B,p),h=t.sub(h,d),c=t.mul(B,q),c=t.add(c,c),c=t.add(c,c),new w(h,a,c)}add(r){V(r);const{px:i,py:o,pz:u}=this,{px:f,py:g,pz:h}=r;let a=t.ZERO,c=t.ZERO,d=t.ZERO;const q=n.a,B=t.mul(n.b,ot);let p=t.mul(i,f),N=t.mul(o,g),Z=t.mul(u,h),H=t.add(i,o),e=t.add(f,g);H=t.mul(H,e),e=t.add(p,N),H=t.sub(H,e),e=t.add(i,u);let s=t.add(f,h);return e=t.mul(e,s),s=t.add(p,Z),e=t.sub(e,s),s=t.add(o,u),a=t.add(g,h),s=t.mul(s,a),a=t.add(N,Z),s=t.sub(s,a),d=t.mul(q,e),a=t.mul(B,Z),d=t.add(a,d),a=t.sub(N,d),d=t.add(N,d),c=t.mul(a,d),N=t.add(p,p),N=t.add(N,p),Z=t.mul(q,Z),e=t.mul(B,e),N=t.add(N,Z),Z=t.sub(p,Z),Z=t.mul(q,Z),e=t.add(e,Z),p=t.mul(N,e),c=t.add(c,p),p=t.mul(s,e),a=t.mul(H,a),a=t.sub(a,p),p=t.mul(H,N),d=t.mul(s,d),d=t.add(d,p),new w(a,c,d)}subtract(r){return this.add(r.negate())}is0(){return this.equals(w.ZERO)}wNAF(r){return C.wNAFCached(this,S,r,i=>{const o=t.invertBatch(i.map(u=>u.pz));return i.map((u,f)=>u.toAffine(o[f])).map(w.fromAffine)})}multiplyUnsafe(r){const i=w.ZERO;if(r===P)return i;if(R(r),r===U)return this;const{endo:o}=n;if(!o)return C.unsafeLadder(this,r);let{k1neg:u,k1:f,k2neg:g,k2:h}=o.splitScalar(r),a=i,c=i,d=this;for(;f>P||h>P;)f&U&&(a=a.add(d)),h&U&&(c=c.add(d)),d=d.double(),f>>=U,h>>=U;return u&&(a=a.negate()),g&&(c=c.negate()),c=new w(t.mul(c.px,o.beta),c.py,c.pz),a.add(c)}multiply(r){R(r);let i=r,o,u;const{endo:f}=n;if(f){const{k1neg:g,k1:h,k2neg:a,k2:c}=f.splitScalar(i);let{p:d,f:q}=this.wNAF(h),{p:B,f:p}=this.wNAF(c);d=C.constTimeNegate(g,d),B=C.constTimeNegate(a,B),B=new w(t.mul(B.px,f.beta),B.py,B.pz),o=d.add(B),u=q.add(p)}else{const{p:g,f:h}=this.wNAF(i);o=g,u=h}return w.normalizeZ([o,u])[0]}multiplyAndAddUnsafe(r,i,o){const u=w.BASE,f=(h,a)=>a===P||a===U||!h.equals(u)?h.multiplyUnsafe(a):h.multiply(a),g=f(this,i).add(f(r,o));return g.is0()?void 0:g}toAffine(r){const{px:i,py:o,pz:u}=this,f=this.is0();r==null&&(r=f?t.ONE:t.inv(u));const g=t.mul(i,r),h=t.mul(o,r),a=t.mul(u,r);if(f)return{x:t.ZERO,y:t.ZERO};if(!t.eql(a,t.ONE))throw new Error("invZ was invalid");return{x:g,y:h}}isTorsionFree(){const{h:r,isTorsionFree:i}=n;if(r===U)return!0;if(i)return i(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:r,clearCofactor:i}=n;return r===U?this:i?i(w,this):this.multiplyUnsafe(n.h)}toRawBytes(r=!0){return this.assertValidity(),x(w,this,r)}toHex(r=!0){return m.bytesToHex(this.toRawBytes(r))}}w.BASE=new w(n.Gx,n.Gy,t.ONE),w.ZERO=new w(t.ZERO,t.ONE,t.ZERO);const W=n.nBitLength,C=et.wNAF(w,n.endo?Math.ceil(W/2):W);return{CURVE:n,ProjectivePoint:w,normPrivateKeyToScalar:L,weierstrassEquation:T,isWithinCurveOrder:F}}function lt(v){const n=et.validateBasic(v);return m.validateObject(n,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...n})}function ft(v){const n=lt(v),{Fp:t,n:x}=n,O=t.BYTES+1,T=2*t.BYTES+1;function F(e){return P<e&&e<t.ORDER}function R(e){return _.mod(e,x)}function L(e){return _.invert(e,x)}const{ProjectivePoint:S,normPrivateKeyToScalar:V,weierstrassEquation:w,isWithinCurveOrder:W}=it({...n,toBytes(e,s,l){const b=s.toAffine(),E=t.toBytes(b.x),A=m.concatBytes;return l?A(Uint8Array.from([s.hasEvenY()?2:3]),E):A(Uint8Array.from([4]),E,t.toBytes(b.y))},fromBytes(e){const s=e.length,l=e[0],b=e.subarray(1);if(s===O&&(l===2||l===3)){const E=m.bytesToNumberBE(b);if(!F(E))throw new Error("Point is not on curve");const A=w(E);let z=t.sqrt(A);const I=(z&U)===U;return(l&1)===1!==I&&(z=t.neg(z)),{x:E,y:z}}else if(s===T&&l===4){const E=t.fromBytes(b.subarray(0,t.BYTES)),A=t.fromBytes(b.subarray(t.BYTES,2*t.BYTES));return{x:E,y:A}}else throw new Error(`Point of length ${s} was invalid. Expected ${O} compressed bytes or ${T} uncompressed bytes`)}}),C=e=>m.bytesToHex(m.numberToBytesBE(e,n.nByteLength));function y(e){const s=x>>U;return e>s}function r(e){return y(e)?R(-e):e}const i=(e,s,l)=>m.bytesToNumberBE(e.slice(s,l));class o{constructor(s,l,b){this.r=s,this.s=l,this.recovery=b,this.assertValidity()}static fromCompact(s){const l=n.nByteLength;return s=m.ensureBytes("compactSignature",s,l*2),new o(i(s,0,l),i(s,l,2*l))}static fromDER(s){const{r:l,s:b}=$.toSig(m.ensureBytes("DER",s));return new o(l,b)}assertValidity(){if(!W(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!W(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(s){return new o(this.r,this.s,s)}recoverPublicKey(s){const{r:l,s:b,recovery:E}=this,A=c(m.ensureBytes("msgHash",s));if(E==null||![0,1,2,3].includes(E))throw new Error("recovery id invalid");const z=E===2||E===3?l+n.n:l;if(z>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");const I=(E&1)===0?"02":"03",D=S.fromHex(I+C(z)),j=L(z),X=R(-A*j),Q=R(b*j),K=S.BASE.multiplyAndAddUnsafe(D,X,Q);if(!K)throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new o(this.r,R(-this.s),this.recovery):this}toDERRawBytes(){return m.hexToBytes(this.toDERHex())}toDERHex(){return $.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return m.hexToBytes(this.toCompactHex())}toCompactHex(){return C(this.r)+C(this.s)}}const u={isValidPrivateKey(e){try{return V(e),!0}catch{return!1}},normPrivateKeyToScalar:V,randomPrivateKey:()=>{const e=n.randomBytes(t.BYTES+8),s=_.hashToPrivateScalar(e,x);return m.numberToBytesBE(s,n.nByteLength)},precompute(e=8,s=S.BASE){return s._setWindowSize(e),s.multiply(BigInt(3)),s}};function f(e,s=!0){return S.fromPrivateKey(e).toRawBytes(s)}function g(e){const s=e instanceof Uint8Array,l=typeof e=="string",b=(s||l)&&e.length;return s?b===O||b===T:l?b===2*O||b===2*T:e instanceof S}function h(e,s,l=!0){if(g(e))throw new Error("first arg must be private key");if(!g(s))throw new Error("second arg must be public key");return S.fromHex(s).multiply(V(e)).toRawBytes(l)}const a=n.bits2int||function(e){const s=m.bytesToNumberBE(e),l=e.length*8-n.nBitLength;return l>0?s>>BigInt(l):s},c=n.bits2int_modN||function(e){return R(a(e))},d=m.bitMask(n.nBitLength);function q(e){if(typeof e!="bigint")throw new Error("bigint expected");if(!(P<=e&&e<d))throw new Error(`bigint expected < 2^${n.nBitLength}`);return m.numberToBytesBE(e,n.nByteLength)}function B(e,s,l=p){if(["recovered","canonical"].some(k=>k in l))throw new Error("sign() legacy options not supported");const{hash:b,randomBytes:E}=n;let{lowS:A,prehash:z,extraEntropy:I}=l;A==null&&(A=!0),e=m.ensureBytes("msgHash",e),z&&(e=m.ensureBytes("prehashed msgHash",b(e)));const D=c(e),j=V(s),X=[q(j),q(D)];if(I!=null){const k=I===!0?E(t.BYTES):I;X.push(m.ensureBytes("extraEntropy",k,t.BYTES))}const Q=m.concatBytes(...X),K=D;function tt(k){const G=a(k);if(!W(G))return;const rt=L(G),Y=S.BASE.multiply(G).toAffine(),M=R(Y.x);if(M===P)return;const J=R(rt*R(K+M*j));if(J===P)return;let nt=(Y.x===M?0:2)|Number(Y.y&U),st=J;return A&&y(J)&&(st=r(J),nt^=1),new o(M,st,nt)}return{seed:Q,k2sig:tt}}const p={lowS:n.lowS,prehash:!1},N={lowS:n.lowS,prehash:!1};function Z(e,s,l=p){const{seed:b,k2sig:E}=B(e,s,l);return m.createHmacDrbg(n.hash.outputLen,n.nByteLength,n.hmac)(b,E)}S.BASE._setWindowSize(8);function H(e,s,l,b=N){const E=e;if(s=m.ensureBytes("msgHash",s),l=m.ensureBytes("publicKey",l),"strict"in b)throw new Error("options.strict was renamed to lowS");const{lowS:A,prehash:z}=b;let I,D;try{if(typeof E=="string"||E instanceof Uint8Array)try{I=o.fromDER(E)}catch(Y){if(!(Y instanceof $.Err))throw Y;I=o.fromCompact(E)}else if(typeof E=="object"&&typeof E.r=="bigint"&&typeof E.s=="bigint"){const{r:Y,s:M}=E;I=new o(Y,M)}else throw new Error("PARSE");D=S.fromHex(l)}catch(Y){if(Y.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(A&&I.hasHighS())return!1;z&&(s=n.hash(s));const{r:j,s:X}=I,Q=c(s),K=L(X),tt=R(Q*K),k=R(j*K),G=S.BASE.multiplyAndAddUnsafe(D,tt,k)?.toAffine();return G?R(G.x)===j:!1}return{CURVE:n,getPublicKey:f,getSharedSecret:h,sign:Z,verify:H,ProjectivePoint:S,Signature:o,utils:u}}exports.DER=$;exports.weierstrass=ft;exports.weierstrassPoints=it;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mod as ut, hashToPrivateScalar as dt, invert as ht } from "./modular.js";
|
|
2
2
|
import * as mt from "./utils.js";
|
|
3
|
-
import {
|
|
3
|
+
import { bytesToNumberBE as _, bitMask as yt, validateObject as lt, concatBytes as et, numberToBytesBE as rt, ensureBytes as Y, bytesToHex as nt, hexToBytes as at, createHmacDrbg as pt } from "./utils.js";
|
|
4
4
|
import { validateBasic as ft, wNAF as wt } from "./curve.js";
|
|
5
5
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
6
6
|
function Et(B) {
|
|
@@ -414,7 +414,7 @@ function Ot(B) {
|
|
|
414
414
|
const q = w === 2 || w === 3 ? l + n.n : l;
|
|
415
415
|
if (q >= t.ORDER)
|
|
416
416
|
throw new Error("recovery id 2 or 3 invalid");
|
|
417
|
-
const I = w & 1 ? "
|
|
417
|
+
const I = (w & 1) === 0 ? "02" : "03", D = x.fromHex(I + C(q)), K = P(q), X = S(-R * K), Q = S(g * K), $ = x.BASE.multiplyAndAddUnsafe(D, X, Q);
|
|
418
418
|
if (!$)
|
|
419
419
|
throw new Error("point at infinify");
|
|
420
420
|
return $.assertValidity(), $;
|
|
@@ -508,21 +508,21 @@ function Ot(B) {
|
|
|
508
508
|
const j = I === !0 ? w(t.BYTES) : I;
|
|
509
509
|
X.push(Y("extraEntropy", j, t.BYTES));
|
|
510
510
|
}
|
|
511
|
-
const
|
|
511
|
+
const Q = et(...X), $ = D;
|
|
512
512
|
function tt(j) {
|
|
513
513
|
const G = a(j);
|
|
514
514
|
if (!W(G))
|
|
515
515
|
return;
|
|
516
|
-
const ot = P(G),
|
|
517
|
-
if (
|
|
516
|
+
const ot = P(G), V = x.BASE.multiply(G).toAffine(), M = S(V.x);
|
|
517
|
+
if (M === L)
|
|
518
518
|
return;
|
|
519
|
-
const
|
|
520
|
-
if (
|
|
519
|
+
const J = S(ot * S($ + M * K));
|
|
520
|
+
if (J === L)
|
|
521
521
|
return;
|
|
522
|
-
let st = (
|
|
523
|
-
return R && m(
|
|
522
|
+
let st = (V.x === M ? 0 : 2) | Number(V.y & z), it = J;
|
|
523
|
+
return R && m(J) && (it = e(J), st ^= 1), new s(M, it, st);
|
|
524
524
|
}
|
|
525
|
-
return { seed:
|
|
525
|
+
return { seed: Q, k2sig: tt };
|
|
526
526
|
}
|
|
527
527
|
const p = { lowS: n.lowS, prehash: !1 }, T = { lowS: n.lowS, prehash: !1 };
|
|
528
528
|
function Z(r, o, l = p) {
|
|
@@ -531,7 +531,6 @@ function Ot(B) {
|
|
|
531
531
|
}
|
|
532
532
|
x.BASE._setWindowSize(8);
|
|
533
533
|
function H(r, o, l, g = T) {
|
|
534
|
-
var M;
|
|
535
534
|
const w = r;
|
|
536
535
|
if (o = Y("msgHash", o), l = Y("publicKey", l), "strict" in g)
|
|
537
536
|
throw new Error("options.strict was renamed to lowS");
|
|
@@ -547,8 +546,8 @@ function Ot(B) {
|
|
|
547
546
|
I = s.fromCompact(w);
|
|
548
547
|
}
|
|
549
548
|
else if (typeof w == "object" && typeof w.r == "bigint" && typeof w.s == "bigint") {
|
|
550
|
-
const { r: V, s:
|
|
551
|
-
I = new s(V,
|
|
549
|
+
const { r: V, s: M } = w;
|
|
550
|
+
I = new s(V, M);
|
|
552
551
|
} else
|
|
553
552
|
throw new Error("PARSE");
|
|
554
553
|
D = x.fromHex(l);
|
|
@@ -560,7 +559,7 @@ function Ot(B) {
|
|
|
560
559
|
if (R && I.hasHighS())
|
|
561
560
|
return !1;
|
|
562
561
|
q && (o = n.hash(o));
|
|
563
|
-
const { r: K, s: X } = I,
|
|
562
|
+
const { r: K, s: X } = I, Q = c(o), $ = P(X), tt = S(Q * $), j = S(K * $), G = x.BASE.multiplyAndAddUnsafe(D, tt, j)?.toAffine();
|
|
564
563
|
return G ? S(G.x) === K : !1;
|
|
565
564
|
}
|
|
566
565
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./_assert.cjs"),f=require("./_u64.cjs"),k=require("./utils.cjs"),[y,b,_]=[[],[],[]],B=BigInt(0),l=BigInt(1),A=BigInt(2),H=BigInt(7),S=BigInt(256),T=BigInt(113);for(let i=0,t=l,s=1,n=0;i<24;i++){[s,n]=[n,(2*s+3*n)%5],y.push(2*(5*n+s)),b.push((i+1)*(i+2)/2%64);let o=B;for(let r=0;r<7;r++)t=(t<<l^(t>>H)*T)%S,t&A&&(o^=l<<(l<<BigInt(r))-l);_.push(o)}const[m,F]=f.split(_,!0),I=(i,t,s)=>s>32?f.rotlBH(i,t,s):f.rotlSH(i,t,s),O=(i,t,s)=>s>32?f.rotlBL(i,t,s):f.rotlSL(i,t,s);function w(i,t=24){const s=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let e=0;e<10;e++)s[e]=i[e]^i[e+10]^i[e+20]^i[e+30]^i[e+40];for(let e=0;e<10;e+=2){const h=(e+8)%10,a=(e+2)%10,p=s[a],c=s[a+1],g=I(p,c,1)^s[h],L=O(p,c,1)^s[h+1];for(let d=0;d<50;d+=10)i[e+d]^=g,i[e+d+1]^=L}let o=i[2],r=i[3];for(let e=0;e<24;e++){const h=b[e],a=I(o,r,h),p=O(o,r,h),c=y[e];o=i[c],r=i[c+1],i[c]=a,i[c+1]=p}for(let e=0;e<50;e+=10){for(let h=0;h<10;h++)s[h]=i[e+h];for(let h=0;h<10;h++)i[e+h]^=~s[(h+2)%10]&s[(h+4)%10]}i[0]^=m[n],i[1]^=F[n]}s.fill(0)}class x extends k.Hash{constructor(t,s,n,o=!1,r=24){if(super(),this.blockLen=t,this.suffix=s,this.outputLen=n,this.enableXOF=o,this.rounds=r,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,u.number(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=k.u32(this.state)}keccak(){w(this.state32,this.rounds),this.posOut=0,this.pos=0}update(t){u.exists(this);const{blockLen:s,state:n}=this;t=k.toBytes(t);const o=t.length;for(let r=0;r<o;){const e=Math.min(s-this.pos,o-r);for(let h=0;h<e;h++)n[this.pos++]^=t[r++];this.pos===s&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:s,pos:n,blockLen:o}=this;t[n]^=s,s&128&&n===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){u.exists(this,!1),u.bytes(t),this.finish();const s=this.state,{blockLen:n}=this;for(let o=0,r=t.length;o<r;){this.posOut>=n&&this.keccak();const e=Math.min(n-this.posOut,r-o);t.set(s.subarray(this.posOut,this.posOut+e),o),this.posOut+=e,o+=e}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return u.number(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(u.output(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:s,suffix:n,outputLen:o,rounds:r,enableXOF:e}=this;return t||(t=new x(s,n,o,e,r)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=r,t.suffix=n,t.outputLen=o,t.enableXOF=e,t.destroyed=this.destroyed,t}}const P=(i,t,s)=>k.wrapConstructor(()=>new x(t,i,s)),X=P(1,136,256/8);exports.Keccak=x;exports.keccakP=w;exports.keccak_256=X;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./_assert.cjs"),f=require("./_u64.cjs"),k=require("./utils.cjs"),[y,b,_]=[[],[],[]],B=BigInt(0),l=BigInt(1),A=BigInt(2),H=BigInt(7),S=BigInt(256),T=BigInt(113);for(let i=0,t=l,s=1,n=0;i<24;i++){[s,n]=[n,(2*s+3*n)%5],y.push(2*(5*n+s)),b.push((i+1)*(i+2)/2%64);let o=B;for(let r=0;r<7;r++)t=(t<<l^(t>>H)*T)%S,t&A&&(o^=l<<(l<<BigInt(r))-l);_.push(o)}const[m,F]=f.split(_,!0),I=(i,t,s)=>s>32?f.rotlBH(i,t,s):f.rotlSH(i,t,s),O=(i,t,s)=>s>32?f.rotlBL(i,t,s):f.rotlSL(i,t,s);function w(i,t=24){const s=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let e=0;e<10;e++)s[e]=i[e]^i[e+10]^i[e+20]^i[e+30]^i[e+40];for(let e=0;e<10;e+=2){const h=(e+8)%10,a=(e+2)%10,p=s[a],c=s[a+1],g=I(p,c,1)^s[h],L=O(p,c,1)^s[h+1];for(let d=0;d<50;d+=10)i[e+d]^=g,i[e+d+1]^=L}let o=i[2],r=i[3];for(let e=0;e<24;e++){const h=b[e],a=I(o,r,h),p=O(o,r,h),c=y[e];o=i[c],r=i[c+1],i[c]=a,i[c+1]=p}for(let e=0;e<50;e+=10){for(let h=0;h<10;h++)s[h]=i[e+h];for(let h=0;h<10;h++)i[e+h]^=~s[(h+2)%10]&s[(h+4)%10]}i[0]^=m[n],i[1]^=F[n]}s.fill(0)}class x extends k.Hash{constructor(t,s,n,o=!1,r=24){if(super(),this.blockLen=t,this.suffix=s,this.outputLen=n,this.enableXOF=o,this.rounds=r,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,u.number(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=k.u32(this.state)}keccak(){w(this.state32,this.rounds),this.posOut=0,this.pos=0}update(t){u.exists(this);const{blockLen:s,state:n}=this;t=k.toBytes(t);const o=t.length;for(let r=0;r<o;){const e=Math.min(s-this.pos,o-r);for(let h=0;h<e;h++)n[this.pos++]^=t[r++];this.pos===s&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:s,pos:n,blockLen:o}=this;t[n]^=s,(s&128)!==0&&n===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){u.exists(this,!1),u.bytes(t),this.finish();const s=this.state,{blockLen:n}=this;for(let o=0,r=t.length;o<r;){this.posOut>=n&&this.keccak();const e=Math.min(n-this.posOut,r-o);t.set(s.subarray(this.posOut,this.posOut+e),o),this.posOut+=e,o+=e}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return u.number(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(u.output(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:s,suffix:n,outputLen:o,rounds:r,enableXOF:e}=this;return t||(t=new x(s,n,o,e,r)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=r,t.suffix=n,t.outputLen=o,t.enableXOF=e,t.destroyed=this.destroyed,t}}const P=(i,t,s)=>k.wrapConstructor(()=>new x(t,i,s)),X=P(1,136,256/8);exports.Keccak=x;exports.keccakP=w;exports.keccak_256=X;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { number as d, exists as k, bytes as _, output as g } from "./_assert.js";
|
|
2
|
-
import {
|
|
2
|
+
import { rotlSH as B, rotlSL as A, rotlBH as H, rotlBL as m, split as S } from "./_u64.js";
|
|
3
3
|
import { wrapConstructor as T, Hash as F, u32 as X, toBytes as U } from "./utils.js";
|
|
4
4
|
const [O, w, y] = [[], [], []], E = /* @__PURE__ */ BigInt(0), f = /* @__PURE__ */ BigInt(1), P = /* @__PURE__ */ BigInt(2), M = /* @__PURE__ */ BigInt(7), R = /* @__PURE__ */ BigInt(256), j = /* @__PURE__ */ BigInt(113);
|
|
5
5
|
for (let i = 0, t = f, s = 1, n = 0; i < 24; i++) {
|
|
@@ -9,7 +9,7 @@ for (let i = 0, t = f, s = 1, n = 0; i < 24; i++) {
|
|
|
9
9
|
t = (t << f ^ (t >> M) * j) % R, t & P && (o ^= f << (f << /* @__PURE__ */ BigInt(r)) - f);
|
|
10
10
|
y.push(o);
|
|
11
11
|
}
|
|
12
|
-
const [C, q] = /* @__PURE__ */ S(y, !0), x = (i, t, s) => s > 32 ?
|
|
12
|
+
const [C, q] = /* @__PURE__ */ S(y, !0), x = (i, t, s) => s > 32 ? H(i, t, s) : B(i, t, s), I = (i, t, s) => s > 32 ? m(i, t, s) : A(i, t, s);
|
|
13
13
|
function v(i, t = 24) {
|
|
14
14
|
const s = new Uint32Array(10);
|
|
15
15
|
for (let n = 24 - t; n < 24; n++) {
|
|
@@ -63,7 +63,7 @@ class p extends F {
|
|
|
63
63
|
return;
|
|
64
64
|
this.finished = !0;
|
|
65
65
|
const { state: t, suffix: s, pos: n, blockLen: o } = this;
|
|
66
|
-
t[n] ^= s, s & 128 && n === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
|
|
66
|
+
t[n] ^= s, (s & 128) !== 0 && n === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
|
|
67
67
|
}
|
|
68
68
|
writeInto(t) {
|
|
69
69
|
k(this, !1), _(t), this.finish();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./_assert.cjs"),a=require("./_u64.cjs"),c=require("./utils.cjs"),I=[],O=[],w=[],B=BigInt(0),f=BigInt(1),A=BigInt(2),S=BigInt(7),H=BigInt(256),T=BigInt(113);for(let i=0,t=f,s=1,n=0;i<24;i++){[s,n]=[n,(2*s+3*n)%5],I.push(2*(5*n+s)),O.push((i+1)*(i+2)/2%64);let o=B;for(let r=0;r<7;r++)t=(t<<f^(t>>S)*T)%H,t&A&&(o^=f<<(f<<BigInt(r))-f);w.push(o)}const[m,E]=a.split(w,!0),y=(i,t,s)=>s>32?a.rotlBH(i,t,s):a.rotlSH(i,t,s),b=(i,t,s)=>s>32?a.rotlBL(i,t,s):a.rotlSL(i,t,s);function L(i,t=24){const s=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let e=0;e<10;e++)s[e]=i[e]^i[e+10]^i[e+20]^i[e+30]^i[e+40];for(let e=0;e<10;e+=2){const h=(e+8)%10,p=(e+2)%10,d=s[p],u=s[p+1],_=y(d,u,1)^s[h],g=b(d,u,1)^s[h+1];for(let k=0;k<50;k+=10)i[e+k]^=_,i[e+k+1]^=g}let o=i[2],r=i[3];for(let e=0;e<24;e++){const h=O[e],p=y(o,r,h),d=b(o,r,h),u=I[e];o=i[u],r=i[u+1],i[u]=p,i[u+1]=d}for(let e=0;e<50;e+=10){for(let h=0;h<10;h++)s[h]=i[e+h];for(let h=0;h<10;h++)i[e+h]^=~s[(h+2)%10]&s[(h+4)%10]}i[0]^=m[n],i[1]^=E[n]}s.fill(0)}class x extends c.Hash{constructor(t,s,n,o=!1,r=24){if(super(),this.blockLen=t,this.suffix=s,this.outputLen=n,this.enableXOF=o,this.rounds=r,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,l.number(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=c.u32(this.state)}keccak(){c.isLE||c.byteSwap32(this.state32),L(this.state32,this.rounds),c.isLE||c.byteSwap32(this.state32),this.posOut=0,this.pos=0}update(t){l.exists(this);const{blockLen:s,state:n}=this;t=c.toBytes(t);const o=t.length;for(let r=0;r<o;){const e=Math.min(s-this.pos,o-r);for(let h=0;h<e;h++)n[this.pos++]^=t[r++];this.pos===s&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:s,pos:n,blockLen:o}=this;t[n]^=s,s&128&&n===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){l.exists(this,!1),l.bytes(t),this.finish();const s=this.state,{blockLen:n}=this;for(let o=0,r=t.length;o<r;){this.posOut>=n&&this.keccak();const e=Math.min(n-this.posOut,r-o);t.set(s.subarray(this.posOut,this.posOut+e),o),this.posOut+=e,o+=e}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return l.number(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(l.output(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:s,suffix:n,outputLen:o,rounds:r,enableXOF:e}=this;return t||(t=new x(s,n,o,e,r)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=r,t.suffix=n,t.outputLen=o,t.enableXOF=e,t.destroyed=this.destroyed,t}}const F=(i,t,s)=>c.wrapConstructor(()=>new x(t,i,s)),P=F(1,136,256/8);exports.Keccak=x;exports.keccakP=L;exports.keccak_256=P;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./_assert.cjs"),a=require("./_u64.cjs"),c=require("./utils.cjs"),I=[],O=[],w=[],B=BigInt(0),f=BigInt(1),A=BigInt(2),S=BigInt(7),H=BigInt(256),T=BigInt(113);for(let i=0,t=f,s=1,n=0;i<24;i++){[s,n]=[n,(2*s+3*n)%5],I.push(2*(5*n+s)),O.push((i+1)*(i+2)/2%64);let o=B;for(let r=0;r<7;r++)t=(t<<f^(t>>S)*T)%H,t&A&&(o^=f<<(f<<BigInt(r))-f);w.push(o)}const[m,E]=a.split(w,!0),y=(i,t,s)=>s>32?a.rotlBH(i,t,s):a.rotlSH(i,t,s),b=(i,t,s)=>s>32?a.rotlBL(i,t,s):a.rotlSL(i,t,s);function L(i,t=24){const s=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let e=0;e<10;e++)s[e]=i[e]^i[e+10]^i[e+20]^i[e+30]^i[e+40];for(let e=0;e<10;e+=2){const h=(e+8)%10,p=(e+2)%10,d=s[p],u=s[p+1],_=y(d,u,1)^s[h],g=b(d,u,1)^s[h+1];for(let k=0;k<50;k+=10)i[e+k]^=_,i[e+k+1]^=g}let o=i[2],r=i[3];for(let e=0;e<24;e++){const h=O[e],p=y(o,r,h),d=b(o,r,h),u=I[e];o=i[u],r=i[u+1],i[u]=p,i[u+1]=d}for(let e=0;e<50;e+=10){for(let h=0;h<10;h++)s[h]=i[e+h];for(let h=0;h<10;h++)i[e+h]^=~s[(h+2)%10]&s[(h+4)%10]}i[0]^=m[n],i[1]^=E[n]}s.fill(0)}class x extends c.Hash{constructor(t,s,n,o=!1,r=24){if(super(),this.blockLen=t,this.suffix=s,this.outputLen=n,this.enableXOF=o,this.rounds=r,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,l.number(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=c.u32(this.state)}keccak(){c.isLE||c.byteSwap32(this.state32),L(this.state32,this.rounds),c.isLE||c.byteSwap32(this.state32),this.posOut=0,this.pos=0}update(t){l.exists(this);const{blockLen:s,state:n}=this;t=c.toBytes(t);const o=t.length;for(let r=0;r<o;){const e=Math.min(s-this.pos,o-r);for(let h=0;h<e;h++)n[this.pos++]^=t[r++];this.pos===s&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:s,pos:n,blockLen:o}=this;t[n]^=s,(s&128)!==0&&n===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){l.exists(this,!1),l.bytes(t),this.finish();const s=this.state,{blockLen:n}=this;for(let o=0,r=t.length;o<r;){this.posOut>=n&&this.keccak();const e=Math.min(n-this.posOut,r-o);t.set(s.subarray(this.posOut,this.posOut+e),o),this.posOut+=e,o+=e}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return l.number(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(l.output(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:s,suffix:n,outputLen:o,rounds:r,enableXOF:e}=this;return t||(t=new x(s,n,o,e,r)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=r,t.suffix=n,t.outputLen=o,t.enableXOF=e,t.destroyed=this.destroyed,t}}const F=(i,t,s)=>c.wrapConstructor(()=>new x(t,i,s)),P=F(1,136,256/8);exports.Keccak=x;exports.keccakP=L;exports.keccak_256=P;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { number as d, exists as k, bytes as B, output as A } from "./_assert.js";
|
|
2
|
-
import {
|
|
2
|
+
import { rotlSH as H, rotlSL as m, rotlBH as S, rotlBL as T, split as F } from "./_u64.js";
|
|
3
3
|
import { wrapConstructor as X, Hash as E, u32 as U, isLE as x, byteSwap32 as I, toBytes as P } from "./utils.js";
|
|
4
4
|
const y = [], L = [], b = [], M = /* @__PURE__ */ BigInt(0), f = /* @__PURE__ */ BigInt(1), R = /* @__PURE__ */ BigInt(2), j = /* @__PURE__ */ BigInt(7), C = /* @__PURE__ */ BigInt(256), q = /* @__PURE__ */ BigInt(113);
|
|
5
5
|
for (let e = 0, t = f, s = 1, n = 0; e < 24; e++) {
|
|
@@ -9,7 +9,7 @@ for (let e = 0, t = f, s = 1, n = 0; e < 24; e++) {
|
|
|
9
9
|
t = (t << f ^ (t >> j) * q) % C, t & R && (o ^= f << (f << /* @__PURE__ */ BigInt(r)) - f);
|
|
10
10
|
b.push(o);
|
|
11
11
|
}
|
|
12
|
-
const [v, z] = /* @__PURE__ */ F(b, !0), O = (e, t, s) => s > 32 ?
|
|
12
|
+
const [v, z] = /* @__PURE__ */ F(b, !0), O = (e, t, s) => s > 32 ? S(e, t, s) : H(e, t, s), w = (e, t, s) => s > 32 ? T(e, t, s) : m(e, t, s);
|
|
13
13
|
function D(e, t = 24) {
|
|
14
14
|
const s = new Uint32Array(10);
|
|
15
15
|
for (let n = 24 - t; n < 24; n++) {
|
|
@@ -63,7 +63,7 @@ class p extends E {
|
|
|
63
63
|
return;
|
|
64
64
|
this.finished = !0;
|
|
65
65
|
const { state: t, suffix: s, pos: n, blockLen: o } = this;
|
|
66
|
-
t[n] ^= s, s & 128 && n === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
|
|
66
|
+
t[n] ^= s, (s & 128) !== 0 && n === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
|
|
67
67
|
}
|
|
68
68
|
writeInto(t) {
|
|
69
69
|
k(this, !1), B(t), this.finish();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function t(e,u){return e
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function t(e,u){return e?.[u]}exports.default=t;
|
package/dist/node_modules/.pnpm/micro-starknet@0.2.3/node_modules/micro-starknet/lib/esm/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { keccak_256 as P } from "../../../../../@noble_hashes@1.3.3/node_modules/@noble/hashes/esm/sha3.js";
|
|
2
2
|
import { sha256 as B } from "../../../../../@noble_hashes@1.3.3/node_modules/@noble/hashes/esm/sha256.js";
|
|
3
3
|
import { utf8ToBytes as S } from "../../../../../@noble_hashes@1.3.3/node_modules/@noble/hashes/esm/utils.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Field as l, mod as h, validateField as b } from "../../../../../@noble_curves@1.0.0/node_modules/@noble/curves/esm/abstract/modular.js";
|
|
5
5
|
import { poseidon as R } from "../../../../../@noble_curves@1.0.0/node_modules/@noble/curves/esm/abstract/poseidon.js";
|
|
6
6
|
import { weierstrass as N } from "../../../../../@noble_curves@1.0.0/node_modules/@noble/curves/esm/abstract/weierstrass.js";
|
|
7
|
-
import { bytesToNumberBE as c,
|
|
7
|
+
import { bytesToNumberBE as c, bytesToHex as x, bitMask as F, ensureBytes as v, hexToBytes as T } from "../../../../../@noble_curves@1.0.0/node_modules/@noble/curves/esm/abstract/utils.js";
|
|
8
8
|
import { getHash as _ } from "../../../../../@noble_curves@1.0.0/node_modules/@noble/curves/esm/_shortw_utils.js";
|
|
9
9
|
const d = BigInt("3618502788666131213697322783095070105526743751716087489154079457884512865583"), w = 252;
|
|
10
10
|
function m(n) {
|
|
@@ -14,7 +14,7 @@ function m(n) {
|
|
|
14
14
|
return e > 0 ? t >> BigInt(e) : t;
|
|
15
15
|
}
|
|
16
16
|
function I(n) {
|
|
17
|
-
return typeof n == "string" && (n = k(n), n.length & 1 && (n = "0" + n)),
|
|
17
|
+
return typeof n == "string" && (n = k(n), n.length & 1 && (n = "0" + n)), T(n);
|
|
18
18
|
}
|
|
19
19
|
const E = N({
|
|
20
20
|
a: BigInt(1),
|
|
@@ -34,11 +34,11 @@ const E = N({
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
function $(n) {
|
|
37
|
-
return
|
|
37
|
+
return v("", typeof n == "string" ? I(n) : n);
|
|
38
38
|
}
|
|
39
39
|
const { ProjectivePoint: s } = E;
|
|
40
40
|
function D(n) {
|
|
41
|
-
return `0x${
|
|
41
|
+
return `0x${x(n.subarray(1)).replace(/^0+/gm, "")}`;
|
|
42
42
|
}
|
|
43
43
|
function k(n) {
|
|
44
44
|
return n.replace(/^0x/i, "");
|
|
@@ -89,7 +89,7 @@ function Q(n, e) {
|
|
|
89
89
|
let t = u[0];
|
|
90
90
|
return t = g(t, n, A), t = g(t, e, C), D(t.toRawBytes(!0));
|
|
91
91
|
}
|
|
92
|
-
const M =
|
|
92
|
+
const M = F(250), Y = (n) => c(P(n)) & M;
|
|
93
93
|
l(BigInt("14474011154664525231415395255581126252639794253786371766033694892385558855681"));
|
|
94
94
|
const j = l(BigInt("3618502788666131213697322783095070105623107215331596699973092056135872020481"));
|
|
95
95
|
function H(n, e, t) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("lodash-es"),n=require("starknet"),d=require("zod"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("lodash-es"),n=require("starknet"),d=require("zod"),B=require("../../utils/base58.cjs"),f=d.z.string().refine(e=>{if(e.toLowerCase()===e)return!0;try{return n.validateChecksumAddress(e)&&$(e)}catch{}return!1},{message:"Invalid address (checksum error)"}),v=d.z.string().refine(e=>{try{return n.validateAndParseAddress(e)}catch{}return!1},{message:"Invalid address (validation error)"}),c=d.z.string().regex(/^0x[0-9a-fA-F]+$/,"Invalid address"),p=c.min(50,"Address must at least be 50 characters long").max(66,"Address must at most be 66 characters long"),P=c.length(66,"Address must be 66 characters long"),h=p.pipe(f).transform(e=>`0x${(e.startsWith("0x")?e.slice(2):e).padStart(64,"0")}`),E=h.or(d.z.literal("")).transform(e=>e===""?void 0:e).optional(),b=c.transform(e=>`0x${e.replace(/^0x/,"").toLowerCase().padStart(64,"0")}`),l=e=>d.z.string().refine(s=>{if(s.toLowerCase()===s)return!0;try{return n.validateChecksumAddress(s)&&$(s)}catch{}return!1},{message:e("validation.address.invalidChecksum")}),x=e=>d.z.string().refine(s=>{try{return n.validateAndParseAddress(s)}catch{}return!1},{message:e("validation.address.validationError")}),o=e=>d.z.string().regex(/^0x[0-9a-fA-F]+$/,e("validation.address.invalidFormat")),u=e=>o(e).min(50,e("validation.address.tooShort")).max(66,e("validation.address.tooLong")),L=e=>o(e).length(66,e("validation.address.exactLength")),g=e=>{const s=u(e),r=l(e);return s.pipe(r).transform(t=>`0x${(t.startsWith("0x")?t.slice(2):t).padStart(64,"0")}`)},k=e=>g(e).or(d.z.literal("")).transform(r=>r===""?void 0:r).optional(),w=e=>o(e).transform(r=>`0x${r.replace(/^0x/,"").toLowerCase().padStart(64,"0")}`),V=e=>({validChecksumAddressSchema:l(e),validateAddressRangeSchema:x(e),addressSchemaBase:o(e),addressSchemaLooseLength:u(e),addressSchemaStrictLength:L(e),addressSchema:g(e),addressOrEmptyUndefinedSchema:k(e),addressSchemaArgentBackend:w(e)}),z=e=>h.safeParse(e).success,C=z,A=e=>n.getChecksumAddress(e),F=e=>{if(!e)return!1;try{const s=B.decodeBase58(e);return C(s)}catch{return!1}},O=e=>{const s=A(e),r=s.slice(0,2),t=s.slice(2,6),a=s.slice(-4);return`${r}${t}…${a}`},T=e=>{const s=A(e),r=s.slice(0,2),a=s.slice(2).match(/.{1,4}/g)||[];return`${r} ${a.join(" ")}`},$=e=>!/^0x[0-9a-f]{63,64}$/.test(e),i=e=>e.toLowerCase().replace(/^[0x]+/,""),m=e=>{try{return/^(0x)?[0-9a-f]+$/i.test(e)}catch{}return!1},y=(e,s)=>{try{return!e||!s||!m(e)||!m(s)?!1:i(e)===i(s)}catch{}return!1},q=e=>{try{return n.num.toBigInt(c.parse(e))===n.constants.ZERO}catch{}return!1},R=(e,s)=>!!s?.some(r=>y(r,e)),U=S.memoize(e=>{const s=e.slice(0,6),r=e.slice(-4);return`${s}…${r}`}),Z=S.memoize((e,s)=>{if(e.length<s)return e;const r=Math.floor((s-1)/2),t=e.slice(0,r),a=e.slice(-r);return`${t}…${a}`});exports.addressOrEmptyUndefinedSchema=E;exports.addressSchema=h;exports.addressSchemaArgentBackend=b;exports.addressSchemaBase=c;exports.addressSchemaLooseLength=p;exports.addressSchemaStrictLength=P;exports.formatFullAddress=T;exports.formatTruncatedAddress=O;exports.formatTruncatedSignerKey=U;exports.formatTruncatedString=Z;exports.getAddressOrEmptyUndefinedSchema=k;exports.getAddressSchema=g;exports.getAddressSchemaArgentBackend=w;exports.getAddressSchemaBase=o;exports.getAddressSchemaLooseLength=u;exports.getAddressSchemaStrictLength=L;exports.getAddressValidationSchemas=V;exports.getValidChecksumAddressSchema=l;exports.getValidateAddressRangeSchema=x;exports.includesAddress=R;exports.isAddress=z;exports.isBase58Address=F;exports.isEqualAddress=y;exports.isValidAddress=C;exports.isValidHexString=m;exports.isZeroAddress=q;exports.normalizeAddress=A;exports.normalizeAddressForCompare=i;exports.validChecksumAddressSchema=f;exports.validateAddressRangeSchema=v;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { memoize as m } from "lodash-es";
|
|
2
|
-
import {
|
|
2
|
+
import { getChecksumAddress as x, validateChecksumAddress as h, validateAndParseAddress as l, num as L, constants as w } from "starknet";
|
|
3
3
|
import { z as a } from "zod";
|
|
4
4
|
import { decodeBase58 as $ } from "../../utils/base58.js";
|
|
5
5
|
const C = a.string().refine((e) => {
|
|
@@ -16,7 +16,7 @@ const C = a.string().refine((e) => {
|
|
|
16
16
|
} catch {
|
|
17
17
|
}
|
|
18
18
|
return !1;
|
|
19
|
-
}, { message: "Invalid address (validation error)" }), n = a.string().regex(/^0x[0-9a-fA-F]+$/, "Invalid address"),
|
|
19
|
+
}, { message: "Invalid address (validation error)" }), n = a.string().regex(/^0x[0-9a-fA-F]+$/, "Invalid address"), k = n.min(50, "Address must at least be 50 characters long").max(66, "Address must at most be 66 characters long"), T = n.length(66, "Address must be 66 characters long"), u = k.pipe(C).transform((e) => `0x${(e.startsWith("0x") ? e.slice(2) : e).padStart(64, "0")}`), U = u.or(a.literal("")).transform((e) => e === "" ? void 0 : e).optional(), W = n.transform((e) => `0x${e.replace(/^0x/, "").toLowerCase().padStart(64, "0")}`), f = (e) => a.string().refine((s) => {
|
|
20
20
|
if (s.toLowerCase() === s)
|
|
21
21
|
return !0;
|
|
22
22
|
try {
|
|
@@ -24,25 +24,25 @@ const C = a.string().refine((e) => {
|
|
|
24
24
|
} catch {
|
|
25
25
|
}
|
|
26
26
|
return !1;
|
|
27
|
-
}, { message: e("validation.address.invalidChecksum") }),
|
|
27
|
+
}, { message: e("validation.address.invalidChecksum") }), y = (e) => a.string().refine((s) => {
|
|
28
28
|
try {
|
|
29
29
|
return l(s);
|
|
30
30
|
} catch {
|
|
31
31
|
}
|
|
32
32
|
return !1;
|
|
33
|
-
}, { message: e("validation.address.validationError") }), o = (e) => a.string().regex(/^0x[0-9a-fA-F]+$/, e("validation.address.invalidFormat")), g = (e) => o(e).min(50, e("validation.address.tooShort")).max(66, e("validation.address.tooLong")),
|
|
33
|
+
}, { message: e("validation.address.validationError") }), o = (e) => a.string().regex(/^0x[0-9a-fA-F]+$/, e("validation.address.invalidFormat")), g = (e) => o(e).min(50, e("validation.address.tooShort")).max(66, e("validation.address.tooLong")), B = (e) => o(e).length(66, e("validation.address.exactLength")), S = (e) => {
|
|
34
34
|
const s = g(e), r = f(e);
|
|
35
35
|
return s.pipe(r).transform((t) => `0x${(t.startsWith("0x") ? t.slice(2) : t).padStart(64, "0")}`);
|
|
36
|
-
},
|
|
36
|
+
}, P = (e) => S(e).or(a.literal("")).transform((r) => r === "" ? void 0 : r).optional(), v = (e) => o(e).transform((r) => `0x${r.replace(/^0x/, "").toLowerCase().padStart(64, "0")}`), j = (e) => ({
|
|
37
37
|
validChecksumAddressSchema: f(e),
|
|
38
|
-
validateAddressRangeSchema:
|
|
38
|
+
validateAddressRangeSchema: y(e),
|
|
39
39
|
addressSchemaBase: o(e),
|
|
40
40
|
addressSchemaLooseLength: g(e),
|
|
41
|
-
addressSchemaStrictLength:
|
|
41
|
+
addressSchemaStrictLength: B(e),
|
|
42
42
|
addressSchema: S(e),
|
|
43
|
-
addressOrEmptyUndefinedSchema:
|
|
44
|
-
addressSchemaArgentBackend:
|
|
45
|
-
}),
|
|
43
|
+
addressOrEmptyUndefinedSchema: P(e),
|
|
44
|
+
addressSchemaArgentBackend: v(e)
|
|
45
|
+
}), b = (e) => u.safeParse(e).success, E = b, A = (e) => x(e), q = (e) => {
|
|
46
46
|
if (!e)
|
|
47
47
|
return !1;
|
|
48
48
|
try {
|
|
@@ -75,7 +75,7 @@ const C = a.string().refine((e) => {
|
|
|
75
75
|
} catch {
|
|
76
76
|
}
|
|
77
77
|
return !1;
|
|
78
|
-
}, G = (e, s) => !!
|
|
78
|
+
}, G = (e, s) => !!s?.some((r) => z(r, e)), J = m((e) => {
|
|
79
79
|
const s = e.slice(0, 6), r = e.slice(-4);
|
|
80
80
|
return `${s}…${r}`;
|
|
81
81
|
}), K = m((e, s) => {
|
|
@@ -89,23 +89,23 @@ export {
|
|
|
89
89
|
u as addressSchema,
|
|
90
90
|
W as addressSchemaArgentBackend,
|
|
91
91
|
n as addressSchemaBase,
|
|
92
|
-
|
|
92
|
+
k as addressSchemaLooseLength,
|
|
93
93
|
T as addressSchemaStrictLength,
|
|
94
94
|
M as formatFullAddress,
|
|
95
95
|
H as formatTruncatedAddress,
|
|
96
96
|
J as formatTruncatedSignerKey,
|
|
97
97
|
K as formatTruncatedString,
|
|
98
|
-
|
|
98
|
+
P as getAddressOrEmptyUndefinedSchema,
|
|
99
99
|
S as getAddressSchema,
|
|
100
|
-
|
|
100
|
+
v as getAddressSchemaArgentBackend,
|
|
101
101
|
o as getAddressSchemaBase,
|
|
102
102
|
g as getAddressSchemaLooseLength,
|
|
103
|
-
|
|
103
|
+
B as getAddressSchemaStrictLength,
|
|
104
104
|
j as getAddressValidationSchemas,
|
|
105
105
|
f as getValidChecksumAddressSchema,
|
|
106
|
-
|
|
106
|
+
y as getValidateAddressRangeSchema,
|
|
107
107
|
G as includesAddress,
|
|
108
|
-
|
|
108
|
+
b as isAddress,
|
|
109
109
|
q as isBase58Address,
|
|
110
110
|
z as isEqualAddress,
|
|
111
111
|
E as isValidAddress,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import g from "../../../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/uniqWith.js";
|
|
2
|
-
import {
|
|
2
|
+
import { CallData as f, CairoOption as p, CairoOptionVariant as u, hash as h } from "starknet";
|
|
3
3
|
import { z as H } from "zod";
|
|
4
4
|
import { getSignerForMultiSigner as d, MultiSigner as A } from "../../../../signer/multisigner.js";
|
|
5
5
|
import { AccountError as D } from "../../../../errors/account.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import s from "../../../../../_virtual/semver.js";
|
|
2
2
|
import { isEqualAddress as i } from "../../address.js";
|
|
3
|
-
import {
|
|
3
|
+
import { C0_PROXY_CONTRACT_CLASS_HASHES as a, ARGENT_ACCOUNT_CONTRACT_CLASS_HASHES as n, ARGENT_MULTISIG_CONTRACT_CLASS_HASHES as c } from "./constants.js";
|
|
4
4
|
function A(t) {
|
|
5
5
|
if (i(t, a[0]))
|
|
6
6
|
return "0.2.4";
|
package/dist/src/features/defiDecomposition/helpers/computeCollateralizedDebtPositionsUsdValue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./computeUsdValueForPosition.cjs"),p=require("./sortDescendingByUsdValue.cjs"),n=require("../../../bigdecimal/parseUnits.cjs"),u=require("../../../bigdecimal/lib.cjs"),c=require("../../../bigdecimal/formatUnits.cjs"),U=(e,s,i)=>{const t=g.computeUsdValueForPosition(e.token,s,i);if(t)return{...e,token:{...e.token,usdValue:t}}},m=(e,s,i)=>{let t=n.parseUnits("0"),l=n.parseUnits("0");const o=e.collateralizedPositions.map(r=>{const d=U(r,s,i);return t=u.add(t,n.parseUnits(d?.token.usdValue||"0")),d}),a=e.debtPositions.map(r=>{const d=U(r,s,i);return l=u.add(l,n.parseUnits(d?.token.usdValue||"0")),d}),V=o.filter(r=>r!==void 0),P=a.filter(r=>r!==void 0);if(!V.length||!P.length)return;const b=u.sub(t,l);return{...e,totalUsdValue:c.formatUnits(b),collateralizedPositionsTotalUsdValue:c.formatUnits(t),debtPositionsTotalUsdValue:c.formatUnits(l),collateralizedPositions:V,debtPositions:P}},f=(e,s,i)=>{let t=n.parseUnits("0");const l=e.map(o=>{const a=U(o,s,i);return t=u.add(t,n.parseUnits(a?.token.usdValue||"0")),a}).filter(o=>o!==void 0).sort(p.sortDescendingByUsdValue)||[];return{totalUsdValue:c.formatUnits(t),positions:l}},z=(e,s,i)=>{let t=n.parseUnits("0");const l=e.map(o=>{const a=m(o,s,i);return t=u.add(t,n.parseUnits(a?.totalUsdValue||"0")),a}).filter(o=>o!==void 0).sort(p.sortDescendingByUsdValue)||[];return{totalUsdValue:c.formatUnits(t),positions:l}};exports.computeCollateralizedDebtBorrowingPositionUsdValue=m;exports.computeCollateralizedDebtBorrowingPositionsUsdValue=z;exports.computeCollateralizedDebtLendingPositionUsdValue=U;exports.computeCollateralizedDebtLendingPositionsUsdValue=f;
|
package/dist/src/features/defiDecomposition/helpers/computeCollateralizedDebtPositionsUsdValue.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { computeUsdValueForPosition as
|
|
2
|
-
import { sortDescendingByUsdValue as
|
|
1
|
+
import { computeUsdValueForPosition as p } from "./computeUsdValueForPosition.js";
|
|
2
|
+
import { sortDescendingByUsdValue as U } from "./sortDescendingByUsdValue.js";
|
|
3
3
|
import { parseUnits as n } from "../../../bigdecimal/parseUnits.js";
|
|
4
4
|
import { add as c, sub as b } from "../../../bigdecimal/lib.js";
|
|
5
5
|
import { formatUnits as u } from "../../../bigdecimal/formatUnits.js";
|
|
6
|
-
const V = (o,
|
|
7
|
-
const t =
|
|
6
|
+
const V = (o, l, s) => {
|
|
7
|
+
const t = p(o.token, l, s);
|
|
8
8
|
if (t)
|
|
9
9
|
return {
|
|
10
10
|
...o,
|
|
@@ -13,42 +13,42 @@ const V = (o, a, r) => {
|
|
|
13
13
|
usdValue: t
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
}, z = (o,
|
|
16
|
+
}, z = (o, l, s) => {
|
|
17
17
|
let t = n("0"), i = n("0");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
return t = c(t, n(
|
|
21
|
-
}),
|
|
22
|
-
const
|
|
23
|
-
return i = c(i, n(
|
|
24
|
-
}), m =
|
|
25
|
-
if (!m.length || !
|
|
18
|
+
const e = o.collateralizedPositions.map((r) => {
|
|
19
|
+
const d = V(r, l, s);
|
|
20
|
+
return t = c(t, n(d?.token.usdValue || "0")), d;
|
|
21
|
+
}), a = o.debtPositions.map((r) => {
|
|
22
|
+
const d = V(r, l, s);
|
|
23
|
+
return i = c(i, n(d?.token.usdValue || "0")), d;
|
|
24
|
+
}), m = e.filter((r) => r !== void 0), P = a.filter((r) => r !== void 0);
|
|
25
|
+
if (!m.length || !P.length)
|
|
26
26
|
return;
|
|
27
|
-
const
|
|
27
|
+
const f = b(t, i);
|
|
28
28
|
return {
|
|
29
29
|
...o,
|
|
30
|
-
totalUsdValue: u(
|
|
30
|
+
totalUsdValue: u(f),
|
|
31
31
|
collateralizedPositionsTotalUsdValue: u(t),
|
|
32
32
|
debtPositionsTotalUsdValue: u(i),
|
|
33
33
|
collateralizedPositions: m,
|
|
34
|
-
debtPositions:
|
|
34
|
+
debtPositions: P
|
|
35
35
|
};
|
|
36
|
-
}, T = (o,
|
|
36
|
+
}, T = (o, l, s) => {
|
|
37
37
|
let t = n("0");
|
|
38
|
-
const i = o.map((
|
|
39
|
-
const
|
|
40
|
-
return t = c(t, n(
|
|
41
|
-
}).filter((
|
|
38
|
+
const i = o.map((e) => {
|
|
39
|
+
const a = V(e, l, s);
|
|
40
|
+
return t = c(t, n(a?.token.usdValue || "0")), a;
|
|
41
|
+
}).filter((e) => e !== void 0).sort(U) || [];
|
|
42
42
|
return {
|
|
43
43
|
totalUsdValue: u(t),
|
|
44
44
|
positions: i
|
|
45
45
|
};
|
|
46
|
-
},
|
|
46
|
+
}, w = (o, l, s) => {
|
|
47
47
|
let t = n("0");
|
|
48
|
-
const i = o.map((
|
|
49
|
-
const
|
|
50
|
-
return t = c(t, n(
|
|
51
|
-
}).filter((
|
|
48
|
+
const i = o.map((e) => {
|
|
49
|
+
const a = z(e, l, s);
|
|
50
|
+
return t = c(t, n(a?.totalUsdValue || "0")), a;
|
|
51
|
+
}).filter((e) => e !== void 0).sort(U) || [];
|
|
52
52
|
return {
|
|
53
53
|
totalUsdValue: u(t),
|
|
54
54
|
positions: i
|
|
@@ -56,7 +56,7 @@ const V = (o, a, r) => {
|
|
|
56
56
|
};
|
|
57
57
|
export {
|
|
58
58
|
z as computeCollateralizedDebtBorrowingPositionUsdValue,
|
|
59
|
-
|
|
59
|
+
w as computeCollateralizedDebtBorrowingPositionsUsdValue,
|
|
60
60
|
V as computeCollateralizedDebtLendingPositionUsdValue,
|
|
61
61
|
T as computeCollateralizedDebtLendingPositionsUsdValue
|
|
62
62
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./computeUsdValueForPosition.cjs"),V=require("./sortDescendingByUsdValue.cjs"),d=require("../../../bigdecimal/lib.cjs"),u=require("../../../bigdecimal/parseUnits.cjs"),l=require("../../../bigdecimal/formatUnits.cjs"),c=(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./computeUsdValueForPosition.cjs"),V=require("./sortDescendingByUsdValue.cjs"),d=require("../../../bigdecimal/lib.cjs"),u=require("../../../bigdecimal/parseUnits.cjs"),l=require("../../../bigdecimal/formatUnits.cjs"),c=(e,n,i)=>{const{token0:s,token1:a}=e,t=r.computeUsdValueForPosition(e.token0,n,i),o=r.computeUsdValueForPosition(e.token1,n,i);if(!t||!o)return;const U=d.add(u.parseUnits(t),u.parseUnits(o));return{...e,totalUsdValue:l.formatUnits(U),token0:{...s,usdValue:t},token1:{...a,usdValue:o}}},p=(e,n,i)=>{let s=u.parseUnits("0");const a=e.map(t=>{const o=c(t,n,i);return s=d.add(s,u.parseUnits(o?.totalUsdValue||"0")),o});return{totalUsdValue:l.formatUnits(s),positions:a.filter(t=>t!==void 0).sort(V.sortDescendingByUsdValue)}};exports.computeConcentratedLiquidityPositionUsdValue=c;exports.computeConcentratedLiquidityPositionsUsdValue=p;
|