@gardenfi/core 0.2.0-beta.70 → 0.2.0-beta.71
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 -31
- package/dist/index.js +27 -7808
- package/dist/index10.cjs +1 -0
- package/dist/index10.js +101 -0
- package/dist/index100.cjs +1 -0
- package/dist/index100.js +37 -0
- package/dist/index101.cjs +1 -0
- package/dist/index101.js +369 -0
- package/dist/index102.cjs +1 -0
- package/dist/index102.js +23 -0
- package/dist/index103.cjs +1 -0
- package/dist/index103.js +58 -0
- package/dist/index104.cjs +1 -0
- package/dist/index104.js +5 -0
- package/dist/index105.cjs +1 -0
- package/dist/index105.js +51 -0
- package/dist/index106.cjs +1 -0
- package/dist/index106.js +28 -0
- package/dist/index107.cjs +1 -0
- package/dist/index107.js +4 -0
- package/dist/index108.cjs +1 -0
- package/dist/index108.js +4 -0
- package/dist/index109.cjs +1 -0
- package/dist/index109.js +64 -0
- package/dist/index11.cjs +20 -0
- package/dist/index11.js +380 -0
- package/dist/index110.cjs +1 -0
- package/dist/index110.js +37 -0
- package/dist/index111.cjs +1 -0
- package/dist/index111.js +4 -0
- package/dist/index112.cjs +1 -0
- package/dist/index112.js +60 -0
- package/dist/index113.cjs +1 -0
- package/dist/index113.js +4 -0
- package/dist/index114.cjs +1 -0
- package/dist/index114.js +42 -0
- package/dist/index115.cjs +1 -0
- package/dist/index115.js +45 -0
- package/dist/index116.cjs +1 -0
- package/dist/index116.js +20 -0
- package/dist/index117.cjs +1 -0
- package/dist/index117.js +111 -0
- package/dist/index118.cjs +1 -0
- package/dist/index118.js +23 -0
- package/dist/index119.cjs +1 -0
- package/dist/index119.js +228 -0
- package/dist/index12.cjs +1 -0
- package/dist/index12.js +22 -0
- package/dist/index120.cjs +1 -0
- package/dist/index120.js +6 -0
- package/dist/index121.cjs +1 -0
- package/dist/index121.js +160 -0
- package/dist/index122.cjs +1 -0
- package/dist/index122.js +4 -0
- package/dist/index123.cjs +1 -0
- package/dist/index123.js +75 -0
- package/dist/index124.cjs +1 -0
- package/dist/index124.js +7 -0
- package/dist/index125.cjs +1 -0
- package/dist/index125.js +107 -0
- package/dist/index126.cjs +1 -0
- package/dist/index126.js +15 -0
- package/dist/index127.cjs +1 -0
- package/dist/index127.js +35 -0
- package/dist/index128.cjs +1 -0
- package/dist/index128.js +32 -0
- package/dist/index129.cjs +1 -0
- package/dist/index129.js +4 -0
- package/dist/index13.cjs +1 -0
- package/dist/index13.js +396 -0
- package/dist/index130.cjs +1 -0
- package/dist/index130.js +21 -0
- package/dist/index131.cjs +1 -0
- package/dist/index131.js +4 -0
- package/dist/index132.cjs +1 -0
- package/dist/index132.js +358 -0
- package/dist/index133.cjs +1 -0
- package/dist/index133.js +241 -0
- package/dist/index134.cjs +1 -0
- package/dist/index134.js +70 -0
- package/dist/index135.cjs +1 -0
- package/dist/index135.js +64 -0
- package/dist/index136.cjs +1 -0
- package/dist/index136.js +14 -0
- package/dist/index137.cjs +1 -0
- package/dist/index137.js +47 -0
- package/dist/index138.cjs +1 -0
- package/dist/index138.js +65 -0
- package/dist/index139.cjs +1 -0
- package/dist/index139.js +228 -0
- package/dist/index14.cjs +1 -0
- package/dist/index14.js +23 -0
- package/dist/index140.cjs +1 -0
- package/dist/index140.js +5 -0
- package/dist/index141.cjs +1 -0
- package/dist/index141.js +171 -0
- package/dist/index142.cjs +1 -0
- package/dist/index142.js +30 -0
- package/dist/index143.cjs +1 -0
- package/dist/index143.js +23 -0
- package/dist/index144.cjs +1 -0
- package/dist/index144.js +72 -0
- package/dist/index145.cjs +1 -0
- package/dist/index145.js +130 -0
- package/dist/index146.cjs +1 -0
- package/dist/index146.js +9 -0
- package/dist/index147.cjs +1 -0
- package/dist/index147.js +4 -0
- package/dist/index148.cjs +1 -0
- package/dist/index148.js +28 -0
- package/dist/index149.cjs +1 -0
- package/dist/index149.js +4 -0
- package/dist/index15.cjs +1 -0
- package/dist/index15.js +4 -0
- package/dist/index16.cjs +1 -0
- package/dist/index16.js +34 -0
- package/dist/index17.cjs +1 -0
- package/dist/index17.js +27 -0
- package/dist/index18.cjs +1 -0
- package/dist/index18.js +33 -0
- package/dist/index19.cjs +1 -0
- package/dist/index19.js +32 -0
- package/dist/index2.cjs +1 -0
- package/dist/index2.js +412 -0
- package/dist/index20.cjs +1 -0
- package/dist/index20.js +55 -0
- package/dist/index21.cjs +1 -0
- package/dist/index21.js +30 -0
- package/dist/index22.cjs +1 -0
- package/dist/index22.js +17 -0
- package/dist/index23.cjs +1 -0
- package/dist/index23.js +11 -0
- package/dist/index24.cjs +1 -0
- package/dist/index24.js +11 -0
- package/dist/index25.cjs +1 -0
- package/dist/index25.js +140 -0
- package/dist/index26.cjs +1 -0
- package/dist/index26.js +4 -0
- package/dist/index27.cjs +1 -0
- package/dist/index27.js +15 -0
- package/dist/index28.cjs +1 -0
- package/dist/index28.js +39 -0
- package/dist/index29.cjs +1 -0
- package/dist/index29.js +44 -0
- package/dist/index3.cjs +1 -0
- package/dist/index3.js +5 -0
- package/dist/index30.cjs +1 -0
- package/dist/index30.js +26 -0
- package/dist/index31.cjs +1 -0
- package/dist/index31.js +28 -0
- package/dist/index32.cjs +1 -0
- package/dist/index32.js +57 -0
- package/dist/index33.cjs +1 -0
- package/dist/index33.js +30 -0
- package/dist/index34.cjs +3 -0
- package/dist/index34.js +30 -0
- package/dist/index35.cjs +1 -0
- package/dist/index35.js +17 -0
- package/dist/index36.cjs +2 -0
- package/dist/index36.js +27 -0
- package/dist/index37.cjs +1 -0
- package/dist/index37.js +43 -0
- package/dist/index38.cjs +1 -0
- package/dist/index38.js +201 -0
- package/dist/index39.cjs +1 -0
- package/dist/index39.js +4 -0
- package/dist/index4.cjs +1 -0
- package/dist/index4.js +18 -0
- package/dist/index40.cjs +1 -0
- package/dist/index40.js +4 -0
- package/dist/index41.cjs +1 -0
- package/dist/index41.js +4 -0
- package/dist/index42.cjs +1 -0
- package/dist/index42.js +15 -0
- package/dist/index43.cjs +1 -0
- package/dist/index43.js +14 -0
- package/dist/index44.cjs +1 -0
- package/dist/index44.js +6 -0
- package/dist/index45.cjs +1 -0
- package/dist/index45.js +48 -0
- package/dist/index46.cjs +1 -0
- package/dist/index46.js +45 -0
- package/dist/index47.cjs +1 -0
- package/dist/index47.js +174 -0
- package/dist/index48.cjs +1 -0
- package/dist/index48.js +15 -0
- package/dist/index49.cjs +1 -0
- package/dist/index49.js +7 -0
- package/dist/index5.cjs +1 -0
- package/dist/index5.js +110 -0
- package/dist/index50.cjs +1 -0
- package/dist/index50.js +19 -0
- package/dist/index51.cjs +1 -0
- package/dist/index51.js +14 -0
- package/dist/index52.cjs +1 -0
- package/dist/index52.js +177 -0
- package/dist/index53.cjs +1 -0
- package/dist/index53.js +24 -0
- package/dist/index54.cjs +1 -0
- package/dist/index54.js +4 -0
- package/dist/index55.cjs +1 -0
- package/dist/index55.js +37 -0
- package/dist/index56.cjs +1 -0
- package/dist/index56.js +11 -0
- package/dist/index57.cjs +1 -0
- package/dist/index57.js +37 -0
- package/dist/index58.cjs +1 -0
- package/dist/index58.js +58 -0
- package/dist/index59.cjs +2 -0
- package/dist/index59.js +62 -0
- package/dist/index6.cjs +1 -0
- package/dist/index6.js +5 -0
- package/dist/index60.cjs +1 -0
- package/dist/index60.js +6 -0
- package/dist/index61.cjs +1 -0
- package/dist/index61.js +130 -0
- package/dist/index62.cjs +2 -0
- package/dist/index62.js +45 -0
- package/dist/index63.cjs +1 -0
- package/dist/index63.js +11 -0
- package/dist/index64.cjs +1 -0
- package/dist/index64.js +13 -0
- package/dist/index65.cjs +1 -0
- package/dist/index65.js +14 -0
- package/dist/index66.cjs +1 -0
- package/dist/index66.js +16 -0
- package/dist/index67.cjs +1 -0
- package/dist/index67.js +9 -0
- package/dist/index68.cjs +1 -0
- package/dist/index68.js +20 -0
- package/dist/index69.cjs +1 -0
- package/dist/index69.js +81 -0
- package/dist/index7.cjs +1 -0
- package/dist/index7.js +76 -0
- package/dist/index70.cjs +1 -0
- package/dist/index70.js +17 -0
- package/dist/index71.cjs +1 -0
- package/dist/index71.js +21 -0
- package/dist/index72.cjs +1 -0
- package/dist/index72.js +24 -0
- package/dist/index73.cjs +1 -0
- package/dist/index73.js +16 -0
- package/dist/index74.cjs +1 -0
- package/dist/index74.js +4 -0
- package/dist/index75.cjs +1 -0
- package/dist/index75.js +4 -0
- package/dist/index76.cjs +1 -0
- package/dist/index76.js +9 -0
- package/dist/index77.cjs +2 -0
- package/dist/index77.js +37 -0
- package/dist/index78.cjs +1 -0
- package/dist/index78.js +8 -0
- package/dist/index79.cjs +1 -0
- package/dist/index79.js +22 -0
- package/dist/index8.cjs +1 -0
- package/dist/index8.js +62 -0
- package/dist/index80.cjs +1 -0
- package/dist/index80.js +34 -0
- package/dist/index81.cjs +1 -0
- package/dist/index81.js +4 -0
- package/dist/index82.cjs +6 -0
- package/dist/index82.js +949 -0
- package/dist/index83.cjs +1 -0
- package/dist/index83.js +4 -0
- package/dist/index84.cjs +1 -0
- package/dist/index84.js +64 -0
- package/dist/index85.cjs +1 -0
- package/dist/index85.js +35 -0
- package/dist/index86.cjs +1 -0
- package/dist/index86.js +89 -0
- package/dist/index87.cjs +1 -0
- package/dist/index87.js +15 -0
- package/dist/index88.cjs +1 -0
- package/dist/index88.js +9 -0
- package/dist/index89.cjs +1 -0
- package/dist/index89.js +115 -0
- package/dist/index9.cjs +1 -0
- package/dist/index9.js +63 -0
- package/dist/index90.cjs +1 -0
- package/dist/index90.js +9 -0
- package/dist/index91.cjs +1 -0
- package/dist/index91.js +35 -0
- package/dist/index92.cjs +1 -0
- package/dist/index92.js +4 -0
- package/dist/index93.cjs +1 -0
- package/dist/index93.js +40 -0
- package/dist/index94.cjs +1 -0
- package/dist/index94.js +31 -0
- package/dist/index95.cjs +1 -0
- package/dist/index95.js +23 -0
- package/dist/index96.cjs +1 -0
- package/dist/index96.js +9 -0
- package/dist/index97.cjs +1 -0
- package/dist/index97.js +7 -0
- package/dist/index98.cjs +1 -0
- package/dist/index98.js +13 -0
- package/dist/index99.cjs +1 -0
- package/dist/index99.js +22 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const d=require("./index108.cjs");/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */d.__exports.read=function(w,a,_,x,M){var t,r,h=M*8-x-1,s=(1<<h)-1,N=s>>1,i=-7,o=_?M-1:0,c=_?-1:1,p=w[a+o];for(o+=c,t=p&(1<<-i)-1,p>>=-i,i+=h;i>0;t=t*256+w[a+o],o+=c,i-=8);for(r=t&(1<<-i)-1,t>>=-i,i+=x;i>0;r=r*256+w[a+o],o+=c,i-=8);if(t===0)t=1-N;else{if(t===s)return r?NaN:(p?-1:1)*(1/0);r=r+Math.pow(2,x),t=t-N}return(p?-1:1)*r*Math.pow(2,t-x)};d.__exports.write=function(w,a,_,x,M,t){var r,h,s,N=t*8-M-1,i=(1<<N)-1,o=i>>1,c=M===23?Math.pow(2,-24)-Math.pow(2,-77):0,p=x?0:t-1,f=x?1:-1,n=a<0||a===0&&1/a<0?1:0;for(a=Math.abs(a),isNaN(a)||a===1/0?(h=isNaN(a)?1:0,r=i):(r=Math.floor(Math.log(a)/Math.LN2),a*(s=Math.pow(2,-r))<1&&(r--,s*=2),r+o>=1?a+=c/s:a+=c*Math.pow(2,1-o),a*s>=2&&(r++,s/=2),r+o>=i?(h=0,r=i):r+o>=1?(h=(a*s-1)*Math.pow(2,M),r=r+o):(h=a*Math.pow(2,o-1)*Math.pow(2,M),r=0));M>=8;w[_+p]=h&255,p+=f,h/=256,M-=8);for(r=r<<M|h,N+=M;N>0;w[_+p]=r&255,p+=f,r/=256,N-=8);w[_+p-f]|=n*128};module.exports=d.__exports;
|
package/dist/index106.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { __exports as v } from "./index108.js";
|
|
2
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
3
|
+
v.read = function(s, a, x, f, M) {
|
|
4
|
+
var t, r, h = M * 8 - f - 1, w = (1 << h) - 1, N = w >> 1, i = -7, o = x ? M - 1 : 0, d = x ? -1 : 1, p = s[a + o];
|
|
5
|
+
for (o += d, t = p & (1 << -i) - 1, p >>= -i, i += h; i > 0; t = t * 256 + s[a + o], o += d, i -= 8)
|
|
6
|
+
;
|
|
7
|
+
for (r = t & (1 << -i) - 1, t >>= -i, i += f; i > 0; r = r * 256 + s[a + o], o += d, i -= 8)
|
|
8
|
+
;
|
|
9
|
+
if (t === 0)
|
|
10
|
+
t = 1 - N;
|
|
11
|
+
else {
|
|
12
|
+
if (t === w)
|
|
13
|
+
return r ? NaN : (p ? -1 : 1) * (1 / 0);
|
|
14
|
+
r = r + Math.pow(2, f), t = t - N;
|
|
15
|
+
}
|
|
16
|
+
return (p ? -1 : 1) * r * Math.pow(2, t - f);
|
|
17
|
+
};
|
|
18
|
+
v.write = function(s, a, x, f, M, t) {
|
|
19
|
+
var r, h, w, N = t * 8 - M - 1, i = (1 << N) - 1, o = i >> 1, d = M === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, p = f ? 0 : t - 1, c = f ? 1 : -1, I = a < 0 || a === 0 && 1 / a < 0 ? 1 : 0;
|
|
20
|
+
for (a = Math.abs(a), isNaN(a) || a === 1 / 0 ? (h = isNaN(a) ? 1 : 0, r = i) : (r = Math.floor(Math.log(a) / Math.LN2), a * (w = Math.pow(2, -r)) < 1 && (r--, w *= 2), r + o >= 1 ? a += d / w : a += d * Math.pow(2, 1 - o), a * w >= 2 && (r++, w /= 2), r + o >= i ? (h = 0, r = i) : r + o >= 1 ? (h = (a * w - 1) * Math.pow(2, M), r = r + o) : (h = a * Math.pow(2, o - 1) * Math.pow(2, M), r = 0)); M >= 8; s[x + p] = h & 255, p += c, h /= 256, M -= 8)
|
|
21
|
+
;
|
|
22
|
+
for (r = r << M | h, N += M; N > 0; s[x + p] = r & 255, p += c, r /= 256, N -= 8)
|
|
23
|
+
;
|
|
24
|
+
s[x + p - c] |= I * 128;
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
v as default
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={};exports.__exports=e;
|
package/dist/index107.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={};exports.__exports=e;
|
package/dist/index108.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./index128.cjs"),u=require("./index110.cjs");function a(o,t,s,i){if(typeof o.setBigUint64=="function")return o.setBigUint64(t,s,i);const n=BigInt(32),h=BigInt(4294967295),e=Number(s>>n&h),r=Number(s&h),c=i?4:0,l=i?0:4;o.setUint32(t+c,e,i),o.setUint32(t+l,r,i)}const d=(o,t,s)=>o&t^~o&s,b=(o,t,s)=>o&t^o&s^t&s;class w extends u.Hash{constructor(t,s,i,n){super(),this.blockLen=t,this.outputLen=s,this.padOffset=i,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=u.createView(this.buffer)}update(t){p.exists(this);const{view:s,buffer:i,blockLen:n}=this;t=u.toBytes(t);const h=t.length;for(let e=0;e<h;){const r=Math.min(n-this.pos,h-e);if(r===n){const c=u.createView(t);for(;n<=h-e;e+=n)this.process(c,e);continue}i.set(t.subarray(e,e+r),this.pos),this.pos+=r,e+=r,this.pos===n&&(this.process(s,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){p.exists(this),p.output(t,this),this.finished=!0;const{buffer:s,view:i,blockLen:n,isLE:h}=this;let{pos:e}=this;s[e++]=128,this.buffer.subarray(e).fill(0),this.padOffset>n-e&&(this.process(i,0),e=0);for(let f=e;f<n;f++)s[f]=0;a(i,n-8,BigInt(this.length*8),h),this.process(i,0);const r=u.createView(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,g=this.get();if(l>g.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)r.setUint32(4*f,g[f],h)}digest(){const{buffer:t,outputLen:s}=this;this.digestInto(t);const i=t.slice(0,s);return this.destroy(),i}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:s,buffer:i,length:n,finished:h,destroyed:e,pos:r}=this;return t.length=n,t.pos=r,t.finished=h,t.destroyed=e,n%s&&t.buffer.set(i),t}}exports.Chi=d;exports.HashMD=w;exports.Maj=b;
|
package/dist/index109.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { exists as g, output as d } from "./index128.js";
|
|
2
|
+
import { Hash as b, createView as p, toBytes as a } from "./index110.js";
|
|
3
|
+
function w(o, t, s, i) {
|
|
4
|
+
if (typeof o.setBigUint64 == "function")
|
|
5
|
+
return o.setBigUint64(t, s, i);
|
|
6
|
+
const n = BigInt(32), h = BigInt(4294967295), e = Number(s >> n & h), r = Number(s & h), c = i ? 4 : 0, u = i ? 0 : 4;
|
|
7
|
+
o.setUint32(t + c, e, i), o.setUint32(t + u, r, i);
|
|
8
|
+
}
|
|
9
|
+
const B = (o, t, s) => o & t ^ ~o & s, L = (o, t, s) => o & t ^ o & s ^ t & s;
|
|
10
|
+
class U extends b {
|
|
11
|
+
constructor(t, s, i, n) {
|
|
12
|
+
super(), this.blockLen = t, this.outputLen = s, this.padOffset = i, this.isLE = n, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view = p(this.buffer);
|
|
13
|
+
}
|
|
14
|
+
update(t) {
|
|
15
|
+
g(this);
|
|
16
|
+
const { view: s, buffer: i, blockLen: n } = this;
|
|
17
|
+
t = a(t);
|
|
18
|
+
const h = t.length;
|
|
19
|
+
for (let e = 0; e < h; ) {
|
|
20
|
+
const r = Math.min(n - this.pos, h - e);
|
|
21
|
+
if (r === n) {
|
|
22
|
+
const c = p(t);
|
|
23
|
+
for (; n <= h - e; e += n)
|
|
24
|
+
this.process(c, e);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
i.set(t.subarray(e, e + r), this.pos), this.pos += r, e += r, this.pos === n && (this.process(s, 0), this.pos = 0);
|
|
28
|
+
}
|
|
29
|
+
return this.length += t.length, this.roundClean(), this;
|
|
30
|
+
}
|
|
31
|
+
digestInto(t) {
|
|
32
|
+
g(this), d(t, this), this.finished = !0;
|
|
33
|
+
const { buffer: s, view: i, blockLen: n, isLE: h } = this;
|
|
34
|
+
let { pos: e } = this;
|
|
35
|
+
s[e++] = 128, this.buffer.subarray(e).fill(0), this.padOffset > n - e && (this.process(i, 0), e = 0);
|
|
36
|
+
for (let f = e; f < n; f++)
|
|
37
|
+
s[f] = 0;
|
|
38
|
+
w(i, n - 8, BigInt(this.length * 8), h), this.process(i, 0);
|
|
39
|
+
const r = p(t), c = this.outputLen;
|
|
40
|
+
if (c % 4)
|
|
41
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
42
|
+
const u = c / 4, l = this.get();
|
|
43
|
+
if (u > l.length)
|
|
44
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
45
|
+
for (let f = 0; f < u; f++)
|
|
46
|
+
r.setUint32(4 * f, l[f], h);
|
|
47
|
+
}
|
|
48
|
+
digest() {
|
|
49
|
+
const { buffer: t, outputLen: s } = this;
|
|
50
|
+
this.digestInto(t);
|
|
51
|
+
const i = t.slice(0, s);
|
|
52
|
+
return this.destroy(), i;
|
|
53
|
+
}
|
|
54
|
+
_cloneInto(t) {
|
|
55
|
+
t || (t = new this.constructor()), t.set(...this.get());
|
|
56
|
+
const { blockLen: s, buffer: i, length: n, finished: h, destroyed: e, pos: r } = this;
|
|
57
|
+
return t.length = n, t.pos = r, t.finished = h, t.destroyed = e, n % s && t.buffer.set(i), t;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
B as Chi,
|
|
62
|
+
U as HashMD,
|
|
63
|
+
L as Maj
|
|
64
|
+
};
|
package/dist/index11.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("@catalogfi/wallets"),H=require("bitcoinjs-lib"),O=require("tiny-secp256k1"),P=require("./index21.cjs"),f=require("./index10.cjs"),u=require("./index22.cjs");function S(p){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(p){for(const r in p)if(r!=="default"){const t=Object.getOwnPropertyDescriptor(p,r);Object.defineProperty(e,r,t.get?t:{enumerable:!0,get:()=>p[r]})}}return e.default=p,Object.freeze(e)}const h=S(H),k=S(O),m=192;h.initEccLib(k);class v{constructor(e,r,t,s,i,a,d,o){this.secretHash=t,this.redeemerPubkey=s,this.initiatorPubkey=i,this.expiry=a,this.signer=e,this.network=d,this.internalPubkey=P.generateInternalkey(),this.initiateAmount=r,this.utxoHashes=o}static async from(e,r,t,s,i,a,d){t=t.startsWith("0x")?t.slice(2):t,f.assert(t.length===64,u.htlcErrors.secretHashLenMismatch),f.assert(s.length===64||s.length===66,`initiator ${u.htlcErrors.pubkeyLenMismatch}`),f.assert(i.length===64||i.length===66,`redeemer ${u.htlcErrors.pubkeyLenMismatch}`),f.assert(a>0,u.htlcErrors.zeroOrNegativeExpiry);const o=await e.getNetwork();return new v(e,r,t,f.xOnlyPubkey(i).toString("hex"),f.xOnlyPubkey(s).toString("hex"),a,o,d)}address(){const{address:e}=h.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!e)throw new Error(u.htlcErrors.htlcAddressGenerationFailed);return e}id(){return this.address()}async _buildRawTx(e,r){const t=new h.Transaction;t.version=2;const s=this.address(),i=await this.signer.getProvider();let a=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const o of this.utxoHashes){const l=await i.getTransaction(o);for(let g=0;g<l.vout.length;g++){const n=l.vout[g];n.scriptpubkey_address===s&&a.push({txid:l.txid,vout:g,value:n.value,status:{confirmed:!1}})}}else a=await i.getUTXOs(s);const d=a.reduce((o,l)=>o+l.value,0);if(d===0)throw new Error(`${s} ${u.htlcErrors.notFunded}`);for(let o=0;o<a.length;o++)t.addInput(Buffer.from(a[o].txid,"hex").reverse(),a[o].vout);return r??(r=await i.suggestFee(s,d,b.Urgency.MEDIUM)),t.addOutput(h.address.toOutputScript(e,this.network),d-r),{tx:t,usedUtxos:a}}async buildRawTx(e){return await this._buildRawTx(await this.signer.getAddress(),e)}getOutputScript(){return h.address.toOutputScript(this.address(),this.network)}async init(e){return e??(e=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,b.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,e)}async instantRefund(e,r){f.assert(e.length>0,u.htlcErrors.noCounterpartySigs);const{tx:t,usedUtxos:s}=await this.buildRawTx(r);for(const n of s)if(!e.find(c=>c.utxo===n.txid))throw new Error(u.htlcErrors.counterPartySigNotFound(n.txid));const i=this.getOutputScript(),a=h.Transaction.SIGHASH_DEFAULT,d=this.leafHash(2),o=s.map(n=>n.value),l=y(i,s.length);for(let n=0;n<t.ins.length;n++){const c=t.hashForWitnessV1(n,l,o,a,d);if(!k.verifySchnorr(c,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(e[n].sig,"hex")))throw new Error(u.htlcErrors.invalidCounterpartySigForUTXO(e[n].utxo));const w=await this.signer.signSchnorr(c),x=Buffer.from(t.ins[n].hash).reverse().toString("hex"),E=e.find(L=>L.utxo===x);if(!E)throw new Error(u.htlcErrors.counterPartySigNotFound(x));t.setWitness(n,[Buffer.from(E.sig,"hex"),w,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(t.toHex())}async redeem(e,r,t){f.assert(h.crypto.sha256(Buffer.from(e,"hex")).toString("hex")===this.secretHash,u.htlcErrors.secretMismatch);const{tx:s,usedUtxos:i}=await this._buildRawTx(r??await this.signer.getAddress(),t),a=this.leafHash(1),d=i.map(n=>n.value),o=y(this.getOutputScript(),i.length),l=h.Transaction.SIGHASH_DEFAULT;for(let n=0;n<s.ins.length;n++){const c=s.hashForWitnessV1(n,o,d,l,a),w=await this.signer.signSchnorr(c);s.setWitness(n,[w,Buffer.from(e,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(s.toHex())}async refund(e,r){const{tx:t,usedUtxos:s}=await this._buildRawTx(e??await this.signer.getAddress(),r),[i,a]=await this.canRefund(s);if(!i)throw new Error(u.htlcErrors.htlcNotExpired(a));const d=this.leafHash(0),o=s.map(c=>c.value),l=y(this.getOutputScript(),s.length),g=h.Transaction.SIGHASH_DEFAULT;for(let c=0;c<t.ins.length;c++){t.ins[c].sequence=this.expiry;const w=t.hashForWitnessV1(c,l,o,g,d),x=await this.signer.signSchnorr(w);t.setWitness(c,[x,this.refundLeaf(),this.generateControlBlockFor(0)])}return await(await this.signer.getProvider()).broadcast(t.toHex())}async canRefund(e){const t=await(await this.signer.getProvider()).getLatestTip();for(const s of e){let i=0;if(s.status.confirmed&&s.status.block_height+this.expiry>t?i=s.status.block_height+this.expiry-t+1:s.status.confirmed||(i=this.expiry+1),i>0)return[!1,i]}return[!0,0]}generateControlBlockFor(e){let r;switch(e){case 1:r=this.redeemLeaf();break;case 0:r=this.refundLeaf();break;case 2:r=this.instantRefundLeaf();break;default:throw new Error(u.htlcErrors.invalidLeaf)}const t=h.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:m}});if(!t.witness)throw new Error(u.htlcErrors.controlBlockGenerationFailed);return t.witness[t.witness.length-1]}leafHash(e){let r=this.redeemLeaf();return e===0&&(r=this.refundLeaf()),e===2&&(r=this.instantRefundLeaf()),h.crypto.taggedHash("TapLeaf",f.serializeScript(r))}refundLeaf(){return h.script.fromASM(`
|
|
2
|
+
${h.script.number.encode(this.expiry).toString("hex")}
|
|
3
|
+
OP_CHECKSEQUENCEVERIFY
|
|
4
|
+
OP_DROP
|
|
5
|
+
${this.initiatorPubkey}
|
|
6
|
+
OP_CHECKSIG
|
|
7
|
+
`.trim().replace(/\s+/g," "))}redeemLeaf(){return h.script.fromASM(`
|
|
8
|
+
OP_SHA256
|
|
9
|
+
${this.secretHash}
|
|
10
|
+
OP_EQUALVERIFY
|
|
11
|
+
${this.redeemerPubkey}
|
|
12
|
+
OP_CHECKSIG
|
|
13
|
+
`.trim().replace(/\s+/g," "))}instantRefundLeaf(){return h.script.fromASM(`
|
|
14
|
+
${this.initiatorPubkey}
|
|
15
|
+
OP_CHECKSIG
|
|
16
|
+
${this.redeemerPubkey}
|
|
17
|
+
OP_CHECKSIGADD
|
|
18
|
+
OP_2
|
|
19
|
+
OP_NUMEQUAL
|
|
20
|
+
`.trim().replace(/\s+/g," "))}leaves(){return[{version:m,output:this.redeemLeaf()},[{version:m,output:this.refundLeaf()},{version:m,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(e){const r=this.leafHash(1),t=this.leafHash(2),s=this.leafHash(0);switch(e){case 1:{const i=f.sortLeaves(s,t);return[h.crypto.taggedHash("TapBranch",Buffer.concat(i))]}case 0:return[t,r];case 2:return[s,r];default:throw new Error(u.htlcErrors.invalidLeaf)}}}function y(p,e){const r=[];for(let t=0;t<e;t++)r.push(p);return r}exports.GardenHTLC=v;
|
package/dist/index11.js
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { Urgency as y } from "@catalogfi/wallets";
|
|
2
|
+
import * as h from "bitcoinjs-lib";
|
|
3
|
+
import * as k from "tiny-secp256k1";
|
|
4
|
+
import { generateInternalkey as b } from "./index21.js";
|
|
5
|
+
import { assert as g, xOnlyPubkey as L, serializeScript as P, sortLeaves as O } from "./index10.js";
|
|
6
|
+
import { htlcErrors as u } from "./index22.js";
|
|
7
|
+
const m = 192;
|
|
8
|
+
h.initEccLib(k);
|
|
9
|
+
class H {
|
|
10
|
+
/**
|
|
11
|
+
* Note: redeemerAddress and initiatorAddress should be x-only public key without 02 or 03 prefix
|
|
12
|
+
*/
|
|
13
|
+
constructor(e, r, t, s, i, a, d, o) {
|
|
14
|
+
this.secretHash = t, this.redeemerPubkey = s, this.initiatorPubkey = i, this.expiry = a, this.signer = e, this.network = d, this.internalPubkey = b(), this.initiateAmount = r, this.utxoHashes = o;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a GardenHTLC instance
|
|
18
|
+
* @param signer Bitcoin wallet of the initiator or redeemer
|
|
19
|
+
* @param secretHash 32 bytes secret hash
|
|
20
|
+
* @param initiatorPubkey initiator's x-only public key without 02 or 03 prefix
|
|
21
|
+
* @param redeemerPubkey redeemer's x-only public key without 02 or 03 prefix
|
|
22
|
+
* @param expiry block height after which the funds can be refunded
|
|
23
|
+
* @returns GardenHTLC instance
|
|
24
|
+
*
|
|
25
|
+
*
|
|
26
|
+
* Note: When the signer is the initiator, only refund and instant refund can be done
|
|
27
|
+
* When the signer is the redeemer, only redeem can be done
|
|
28
|
+
*/
|
|
29
|
+
static async from(e, r, t, s, i, a, d) {
|
|
30
|
+
t = t.startsWith("0x") ? t.slice(2) : t, g(t.length === 64, u.secretHashLenMismatch), g(
|
|
31
|
+
s.length === 64 || s.length === 66,
|
|
32
|
+
`initiator ${u.pubkeyLenMismatch}`
|
|
33
|
+
), g(
|
|
34
|
+
i.length === 64 || i.length === 66,
|
|
35
|
+
`redeemer ${u.pubkeyLenMismatch}`
|
|
36
|
+
), g(a > 0, u.zeroOrNegativeExpiry);
|
|
37
|
+
const o = await e.getNetwork();
|
|
38
|
+
return new H(
|
|
39
|
+
e,
|
|
40
|
+
r,
|
|
41
|
+
t,
|
|
42
|
+
L(i).toString("hex"),
|
|
43
|
+
L(s).toString("hex"),
|
|
44
|
+
a,
|
|
45
|
+
o,
|
|
46
|
+
d
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Generates a taproot address for receiving the funds
|
|
51
|
+
*/
|
|
52
|
+
address() {
|
|
53
|
+
const { address: e } = h.payments.p2tr({
|
|
54
|
+
internalPubkey: this.internalPubkey,
|
|
55
|
+
network: this.network,
|
|
56
|
+
scriptTree: this.leaves()
|
|
57
|
+
});
|
|
58
|
+
if (!e) throw new Error(u.htlcAddressGenerationFailed);
|
|
59
|
+
return e;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* returns the address of the HTLC
|
|
63
|
+
*/
|
|
64
|
+
id() {
|
|
65
|
+
return this.address();
|
|
66
|
+
}
|
|
67
|
+
async _buildRawTx(e, r) {
|
|
68
|
+
const t = new h.Transaction();
|
|
69
|
+
t.version = 2;
|
|
70
|
+
const s = this.address(), i = await this.signer.getProvider();
|
|
71
|
+
let a = [];
|
|
72
|
+
if (this.utxoHashes && this.utxoHashes.length > 0)
|
|
73
|
+
for (const o of this.utxoHashes) {
|
|
74
|
+
const f = await i.getTransaction(o);
|
|
75
|
+
for (let l = 0; l < f.vout.length; l++) {
|
|
76
|
+
const n = f.vout[l];
|
|
77
|
+
n.scriptpubkey_address === s && a.push({
|
|
78
|
+
txid: f.txid,
|
|
79
|
+
vout: l,
|
|
80
|
+
value: n.value,
|
|
81
|
+
status: { confirmed: !1 }
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
a = await i.getUTXOs(s);
|
|
87
|
+
const d = a.reduce((o, f) => o + f.value, 0);
|
|
88
|
+
if (d === 0) throw new Error(`${s} ${u.notFunded}`);
|
|
89
|
+
for (let o = 0; o < a.length; o++)
|
|
90
|
+
t.addInput(Buffer.from(a[o].txid, "hex").reverse(), a[o].vout);
|
|
91
|
+
return r ?? (r = await i.suggestFee(s, d, y.MEDIUM)), t.addOutput(
|
|
92
|
+
h.address.toOutputScript(e, this.network),
|
|
93
|
+
d - r
|
|
94
|
+
), { tx: t, usedUtxos: a };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Builds a raw unsigned transaction with utxos from gardenHTLC address
|
|
98
|
+
* and uses signer's address as the output address
|
|
99
|
+
*/
|
|
100
|
+
async buildRawTx(e) {
|
|
101
|
+
return await this._buildRawTx(await this.signer.getAddress(), e);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* prevout script for the gardenHTLC address
|
|
105
|
+
*/
|
|
106
|
+
getOutputScript() {
|
|
107
|
+
return h.address.toOutputScript(this.address(), this.network);
|
|
108
|
+
}
|
|
109
|
+
async init(e) {
|
|
110
|
+
return e ?? (e = await (await this.signer.getProvider()).suggestFee(
|
|
111
|
+
await this.signer.getAddress(),
|
|
112
|
+
this.initiateAmount,
|
|
113
|
+
y.MEDIUM
|
|
114
|
+
)), await this.signer.send(this.address(), this.initiateAmount, e);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Instantly refunds the funds to the initiator given the counterparty's signatures and pubkey
|
|
118
|
+
*
|
|
119
|
+
* Note: If there are multiple UTXOs being spend, there should be a signature for each UTXO in counterPartySigs
|
|
120
|
+
*/
|
|
121
|
+
async instantRefund(e, r) {
|
|
122
|
+
g(e.length > 0, u.noCounterpartySigs);
|
|
123
|
+
const { tx: t, usedUtxos: s } = await this.buildRawTx(r);
|
|
124
|
+
for (const n of s)
|
|
125
|
+
if (!e.find((c) => c.utxo === n.txid))
|
|
126
|
+
throw new Error(u.counterPartySigNotFound(n.txid));
|
|
127
|
+
const i = this.getOutputScript(), a = h.Transaction.SIGHASH_DEFAULT, d = this.leafHash(
|
|
128
|
+
2
|
|
129
|
+
/* INSTANT_REFUND */
|
|
130
|
+
), o = s.map((n) => n.value), f = x(i, s.length);
|
|
131
|
+
for (let n = 0; n < t.ins.length; n++) {
|
|
132
|
+
const c = t.hashForWitnessV1(
|
|
133
|
+
n,
|
|
134
|
+
f,
|
|
135
|
+
o,
|
|
136
|
+
a,
|
|
137
|
+
d
|
|
138
|
+
);
|
|
139
|
+
if (!k.verifySchnorr(
|
|
140
|
+
c,
|
|
141
|
+
Buffer.from(this.redeemerPubkey, "hex"),
|
|
142
|
+
Buffer.from(e[n].sig, "hex")
|
|
143
|
+
))
|
|
144
|
+
throw new Error(
|
|
145
|
+
u.invalidCounterpartySigForUTXO(e[n].utxo)
|
|
146
|
+
);
|
|
147
|
+
const p = await this.signer.signSchnorr(c), w = Buffer.from(t.ins[n].hash).reverse().toString("hex"), v = e.find((E) => E.utxo === w);
|
|
148
|
+
if (!v)
|
|
149
|
+
throw new Error(u.counterPartySigNotFound(w));
|
|
150
|
+
t.setWitness(n, [
|
|
151
|
+
Buffer.from(v.sig, "hex"),
|
|
152
|
+
p,
|
|
153
|
+
this.instantRefundLeaf(),
|
|
154
|
+
this.generateControlBlockFor(
|
|
155
|
+
2
|
|
156
|
+
/* INSTANT_REFUND */
|
|
157
|
+
)
|
|
158
|
+
]);
|
|
159
|
+
}
|
|
160
|
+
return await (await this.signer.getProvider()).broadcast(t.toHex());
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Reveals the secret and redeems the HTLC
|
|
164
|
+
*/
|
|
165
|
+
async redeem(e, r, t) {
|
|
166
|
+
g(
|
|
167
|
+
h.crypto.sha256(Buffer.from(e, "hex")).toString("hex") === this.secretHash,
|
|
168
|
+
u.secretMismatch
|
|
169
|
+
);
|
|
170
|
+
const { tx: s, usedUtxos: i } = await this._buildRawTx(
|
|
171
|
+
r ?? await this.signer.getAddress(),
|
|
172
|
+
t
|
|
173
|
+
), a = this.leafHash(
|
|
174
|
+
1
|
|
175
|
+
/* REDEEM */
|
|
176
|
+
), d = i.map((n) => n.value), o = x(this.getOutputScript(), i.length), f = h.Transaction.SIGHASH_DEFAULT;
|
|
177
|
+
for (let n = 0; n < s.ins.length; n++) {
|
|
178
|
+
const c = s.hashForWitnessV1(
|
|
179
|
+
n,
|
|
180
|
+
o,
|
|
181
|
+
d,
|
|
182
|
+
f,
|
|
183
|
+
a
|
|
184
|
+
), p = await this.signer.signSchnorr(c);
|
|
185
|
+
s.setWitness(n, [
|
|
186
|
+
p,
|
|
187
|
+
Buffer.from(e, "hex"),
|
|
188
|
+
this.redeemLeaf(),
|
|
189
|
+
this.generateControlBlockFor(
|
|
190
|
+
1
|
|
191
|
+
/* REDEEM */
|
|
192
|
+
)
|
|
193
|
+
]);
|
|
194
|
+
}
|
|
195
|
+
return await (await this.signer.getProvider()).broadcast(s.toHex());
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Refunds the funds back to the initiator if the expiry block height + 1 is reached
|
|
199
|
+
*/
|
|
200
|
+
async refund(e, r) {
|
|
201
|
+
const { tx: t, usedUtxos: s } = await this._buildRawTx(
|
|
202
|
+
e ?? await this.signer.getAddress(),
|
|
203
|
+
r
|
|
204
|
+
), [i, a] = await this.canRefund(s);
|
|
205
|
+
if (!i)
|
|
206
|
+
throw new Error(u.htlcNotExpired(a));
|
|
207
|
+
const d = this.leafHash(
|
|
208
|
+
0
|
|
209
|
+
/* REFUND */
|
|
210
|
+
), o = s.map((c) => c.value), f = x(this.getOutputScript(), s.length), l = h.Transaction.SIGHASH_DEFAULT;
|
|
211
|
+
for (let c = 0; c < t.ins.length; c++) {
|
|
212
|
+
t.ins[c].sequence = this.expiry;
|
|
213
|
+
const p = t.hashForWitnessV1(
|
|
214
|
+
c,
|
|
215
|
+
f,
|
|
216
|
+
o,
|
|
217
|
+
l,
|
|
218
|
+
d
|
|
219
|
+
), w = await this.signer.signSchnorr(p);
|
|
220
|
+
t.setWitness(c, [
|
|
221
|
+
w,
|
|
222
|
+
this.refundLeaf(),
|
|
223
|
+
this.generateControlBlockFor(
|
|
224
|
+
0
|
|
225
|
+
/* REFUND */
|
|
226
|
+
)
|
|
227
|
+
]);
|
|
228
|
+
}
|
|
229
|
+
return await (await this.signer.getProvider()).broadcast(t.toHex());
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Given a list of UTXOs, checks if the HTLC can be refunded
|
|
233
|
+
*/
|
|
234
|
+
async canRefund(e) {
|
|
235
|
+
const t = await (await this.signer.getProvider()).getLatestTip();
|
|
236
|
+
for (const s of e) {
|
|
237
|
+
let i = 0;
|
|
238
|
+
if (s.status.confirmed && s.status.block_height + this.expiry > t ? i = s.status.block_height + this.expiry - t + 1 : s.status.confirmed || (i = this.expiry + 1), i > 0)
|
|
239
|
+
return [!1, i];
|
|
240
|
+
}
|
|
241
|
+
return [!0, 0];
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Given a leaf, generates the control block necessary for spending the leaf
|
|
245
|
+
*/
|
|
246
|
+
generateControlBlockFor(e) {
|
|
247
|
+
let r;
|
|
248
|
+
switch (e) {
|
|
249
|
+
case 1:
|
|
250
|
+
r = this.redeemLeaf();
|
|
251
|
+
break;
|
|
252
|
+
case 0:
|
|
253
|
+
r = this.refundLeaf();
|
|
254
|
+
break;
|
|
255
|
+
case 2:
|
|
256
|
+
r = this.instantRefundLeaf();
|
|
257
|
+
break;
|
|
258
|
+
default:
|
|
259
|
+
throw new Error(u.invalidLeaf);
|
|
260
|
+
}
|
|
261
|
+
const t = h.payments.p2tr({
|
|
262
|
+
internalPubkey: this.internalPubkey,
|
|
263
|
+
network: this.network,
|
|
264
|
+
scriptTree: this.leaves(),
|
|
265
|
+
redeem: {
|
|
266
|
+
output: r,
|
|
267
|
+
redeemVersion: m
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
if (!t.witness)
|
|
271
|
+
throw new Error(u.controlBlockGenerationFailed);
|
|
272
|
+
return t.witness[t.witness.length - 1];
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Generates the hash of the leaf script
|
|
276
|
+
* @param leaf Use leaf enum or pass 0 for refund, 1 for redeem, 2 for instant refund
|
|
277
|
+
* @returns hash of the leaf script
|
|
278
|
+
*/
|
|
279
|
+
leafHash(e) {
|
|
280
|
+
let r = this.redeemLeaf();
|
|
281
|
+
return e === 0 && (r = this.refundLeaf()), e === 2 && (r = this.instantRefundLeaf()), h.crypto.taggedHash("TapLeaf", P(r));
|
|
282
|
+
}
|
|
283
|
+
refundLeaf() {
|
|
284
|
+
return h.script.fromASM(
|
|
285
|
+
`
|
|
286
|
+
${h.script.number.encode(this.expiry).toString("hex")}
|
|
287
|
+
OP_CHECKSEQUENCEVERIFY
|
|
288
|
+
OP_DROP
|
|
289
|
+
${this.initiatorPubkey}
|
|
290
|
+
OP_CHECKSIG
|
|
291
|
+
`.trim().replace(/\s+/g, " ")
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
redeemLeaf() {
|
|
295
|
+
return h.script.fromASM(
|
|
296
|
+
`
|
|
297
|
+
OP_SHA256
|
|
298
|
+
${this.secretHash}
|
|
299
|
+
OP_EQUALVERIFY
|
|
300
|
+
${this.redeemerPubkey}
|
|
301
|
+
OP_CHECKSIG
|
|
302
|
+
`.trim().replace(/\s+/g, " ")
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
instantRefundLeaf() {
|
|
306
|
+
return h.script.fromASM(
|
|
307
|
+
`
|
|
308
|
+
${this.initiatorPubkey}
|
|
309
|
+
OP_CHECKSIG
|
|
310
|
+
${this.redeemerPubkey}
|
|
311
|
+
OP_CHECKSIGADD
|
|
312
|
+
OP_2
|
|
313
|
+
OP_NUMEQUAL
|
|
314
|
+
`.trim().replace(/\s+/g, " ")
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
leaves() {
|
|
318
|
+
return [
|
|
319
|
+
// most probable leaf (redeem)
|
|
320
|
+
{
|
|
321
|
+
version: m,
|
|
322
|
+
output: this.redeemLeaf()
|
|
323
|
+
},
|
|
324
|
+
[
|
|
325
|
+
{
|
|
326
|
+
version: m,
|
|
327
|
+
output: this.refundLeaf()
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
version: m,
|
|
331
|
+
output: this.instantRefundLeaf()
|
|
332
|
+
}
|
|
333
|
+
]
|
|
334
|
+
];
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Generates the merkle proof for the leaf script
|
|
338
|
+
*/
|
|
339
|
+
generateMerkleProofFor(e) {
|
|
340
|
+
const r = this.leafHash(
|
|
341
|
+
1
|
|
342
|
+
/* REDEEM */
|
|
343
|
+
), t = this.leafHash(
|
|
344
|
+
2
|
|
345
|
+
/* INSTANT_REFUND */
|
|
346
|
+
), s = this.leafHash(
|
|
347
|
+
0
|
|
348
|
+
/* REFUND */
|
|
349
|
+
);
|
|
350
|
+
switch (e) {
|
|
351
|
+
case 1: {
|
|
352
|
+
const i = O(
|
|
353
|
+
s,
|
|
354
|
+
t
|
|
355
|
+
);
|
|
356
|
+
return [
|
|
357
|
+
h.crypto.taggedHash(
|
|
358
|
+
"TapBranch",
|
|
359
|
+
Buffer.concat(i)
|
|
360
|
+
)
|
|
361
|
+
];
|
|
362
|
+
}
|
|
363
|
+
case 0:
|
|
364
|
+
return [t, r];
|
|
365
|
+
case 2:
|
|
366
|
+
return [s, r];
|
|
367
|
+
default:
|
|
368
|
+
throw new Error(u.invalidLeaf);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function x(S, e) {
|
|
373
|
+
const r = [];
|
|
374
|
+
for (let t = 0; t < e; t++)
|
|
375
|
+
r.push(S);
|
|
376
|
+
return r;
|
|
377
|
+
}
|
|
378
|
+
export {
|
|
379
|
+
H as GardenHTLC
|
|
380
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index128.cjs");/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const u=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),i=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),y=(t,e)=>t<<32-e|t>>>e,b=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,o=t=>t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;function p(t){for(let e=0;e<t.length;e++)t[e]=o(t[e])}function f(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function r(t){return typeof t=="string"&&(t=f(t)),s.bytes(t),t}class w{clone(){return this._cloneInto()}}function l(t){const e=c=>t().update(r(c)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}exports.Hash=w;exports.byteSwap=o;exports.byteSwap32=p;exports.createView=i;exports.isLE=b;exports.rotr=y;exports.toBytes=r;exports.u32=u;exports.utf8ToBytes=f;exports.wrapConstructor=l;
|
package/dist/index110.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { bytes as f } from "./index128.js";
|
|
2
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
+
const s = (t) => new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4)), y = (t) => new DataView(t.buffer, t.byteOffset, t.byteLength), p = (t, e) => t << 32 - e | t >>> e, b = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68, c = (t) => t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255;
|
|
4
|
+
function w(t) {
|
|
5
|
+
for (let e = 0; e < t.length; e++)
|
|
6
|
+
t[e] = c(t[e]);
|
|
7
|
+
}
|
|
8
|
+
function r(t) {
|
|
9
|
+
if (typeof t != "string")
|
|
10
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof t}`);
|
|
11
|
+
return new Uint8Array(new TextEncoder().encode(t));
|
|
12
|
+
}
|
|
13
|
+
function u(t) {
|
|
14
|
+
return typeof t == "string" && (t = r(t)), f(t), t;
|
|
15
|
+
}
|
|
16
|
+
class x {
|
|
17
|
+
// Safe version that clones internal state
|
|
18
|
+
clone() {
|
|
19
|
+
return this._cloneInto();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function g(t) {
|
|
23
|
+
const e = (o) => t().update(u(o)).digest(), n = t();
|
|
24
|
+
return e.outputLen = n.outputLen, e.blockLen = n.blockLen, e.create = () => t(), e;
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
x as Hash,
|
|
28
|
+
c as byteSwap,
|
|
29
|
+
w as byteSwap32,
|
|
30
|
+
y as createView,
|
|
31
|
+
b as isLE,
|
|
32
|
+
p as rotr,
|
|
33
|
+
u as toBytes,
|
|
34
|
+
s as u32,
|
|
35
|
+
r as utf8ToBytes,
|
|
36
|
+
g as wrapConstructor
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={exports:{}};exports.__module=e;
|
package/dist/index111.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./index55.cjs"),a=require("./index126.cjs"),_=require("./index99.cjs");var h=u.safeBufferExports.Buffer,l=a.readableBrowserExports.Transform,c=_.inherits_browserExports;function p(t,e){if(!h.isBuffer(t)&&typeof t!="string")throw new TypeError(e+" must be a string or a buffer")}function i(t){l.call(this),this._block=h.allocUnsafe(t),this._blockSize=t,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}c(i,l);i.prototype._transform=function(t,e,r){var s=null;try{this.update(t,e)}catch(f){s=f}r(s)};i.prototype._flush=function(t){var e=null;try{this.push(this.digest())}catch(r){e=r}t(e)};i.prototype.update=function(t,e){if(p(t,"Data"),this._finalized)throw new Error("Digest already called");h.isBuffer(t)||(t=h.from(t,e));for(var r=this._block,s=0;this._blockOffset+t.length-s>=this._blockSize;){for(var f=this._blockOffset;f<this._blockSize;)r[f++]=t[s++];this._update(),this._blockOffset=0}for(;s<t.length;)r[this._blockOffset++]=t[s++];for(var n=0,o=t.length*8;o>0;++n)this._length[n]+=o,o=this._length[n]/4294967296|0,o>0&&(this._length[n]-=4294967296*o);return this};i.prototype._update=function(){throw new Error("_update is not implemented")};i.prototype.digest=function(t){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var e=this._digest();t!==void 0&&(e=e.toString(t)),this._block.fill(0),this._blockOffset=0;for(var r=0;r<4;++r)this._length[r]=0;return e};i.prototype._digest=function(){throw new Error("_digest is not implemented")};var g=i;exports.hashBase=g;
|
package/dist/index112.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { s as a } from "./index55.js";
|
|
2
|
+
import { r as _ } from "./index126.js";
|
|
3
|
+
import { i as p } from "./index99.js";
|
|
4
|
+
var n = a.Buffer, l = _.Transform, u = p;
|
|
5
|
+
function c(t, r) {
|
|
6
|
+
if (!n.isBuffer(t) && typeof t != "string")
|
|
7
|
+
throw new TypeError(r + " must be a string or a buffer");
|
|
8
|
+
}
|
|
9
|
+
function i(t) {
|
|
10
|
+
l.call(this), this._block = n.allocUnsafe(t), this._blockSize = t, this._blockOffset = 0, this._length = [0, 0, 0, 0], this._finalized = !1;
|
|
11
|
+
}
|
|
12
|
+
u(i, l);
|
|
13
|
+
i.prototype._transform = function(t, r, e) {
|
|
14
|
+
var s = null;
|
|
15
|
+
try {
|
|
16
|
+
this.update(t, r);
|
|
17
|
+
} catch (f) {
|
|
18
|
+
s = f;
|
|
19
|
+
}
|
|
20
|
+
e(s);
|
|
21
|
+
};
|
|
22
|
+
i.prototype._flush = function(t) {
|
|
23
|
+
var r = null;
|
|
24
|
+
try {
|
|
25
|
+
this.push(this.digest());
|
|
26
|
+
} catch (e) {
|
|
27
|
+
r = e;
|
|
28
|
+
}
|
|
29
|
+
t(r);
|
|
30
|
+
};
|
|
31
|
+
i.prototype.update = function(t, r) {
|
|
32
|
+
if (c(t, "Data"), this._finalized) throw new Error("Digest already called");
|
|
33
|
+
n.isBuffer(t) || (t = n.from(t, r));
|
|
34
|
+
for (var e = this._block, s = 0; this._blockOffset + t.length - s >= this._blockSize; ) {
|
|
35
|
+
for (var f = this._blockOffset; f < this._blockSize; ) e[f++] = t[s++];
|
|
36
|
+
this._update(), this._blockOffset = 0;
|
|
37
|
+
}
|
|
38
|
+
for (; s < t.length; ) e[this._blockOffset++] = t[s++];
|
|
39
|
+
for (var h = 0, o = t.length * 8; o > 0; ++h)
|
|
40
|
+
this._length[h] += o, o = this._length[h] / 4294967296 | 0, o > 0 && (this._length[h] -= 4294967296 * o);
|
|
41
|
+
return this;
|
|
42
|
+
};
|
|
43
|
+
i.prototype._update = function() {
|
|
44
|
+
throw new Error("_update is not implemented");
|
|
45
|
+
};
|
|
46
|
+
i.prototype.digest = function(t) {
|
|
47
|
+
if (this._finalized) throw new Error("Digest already called");
|
|
48
|
+
this._finalized = !0;
|
|
49
|
+
var r = this._digest();
|
|
50
|
+
t !== void 0 && (r = r.toString(t)), this._block.fill(0), this._blockOffset = 0;
|
|
51
|
+
for (var e = 0; e < 4; ++e) this._length[e] = 0;
|
|
52
|
+
return r;
|
|
53
|
+
};
|
|
54
|
+
i.prototype._digest = function() {
|
|
55
|
+
throw new Error("_digest is not implemented");
|
|
56
|
+
};
|
|
57
|
+
var m = i;
|
|
58
|
+
export {
|
|
59
|
+
m as h
|
|
60
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={exports:{}};exports.__module=e;
|
package/dist/index113.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("./index99.cjs"),d=require("./index127.cjs"),x=require("./index55.cjs");var b=v.inherits_browserExports,c=d.hash,p=x.safeBufferExports.Buffer,w=[1518500249,1859775393,-1894007588,-899497514],l=new Array(80);function a(){this.init(),this._w=l,c.call(this,64,56)}b(a,c);a.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function B(t){return t<<5|t>>>27}function E(t){return t<<30|t>>>2}function y(t,r,i,s){return t===0?r&i|~r&s:t===2?r&i|r&s|i&s:r^i^s}a.prototype._update=function(t){for(var r=this._w,i=this._a|0,s=this._b|0,h=this._c|0,n=this._d|0,o=this._e|0,e=0;e<16;++e)r[e]=t.readInt32BE(e*4);for(;e<80;++e)r[e]=r[e-3]^r[e-8]^r[e-14]^r[e-16];for(var _=0;_<80;++_){var f=~~(_/20),u=B(i)+y(f,s,h,n)+o+r[_]+w[f]|0;o=n,n=h,h=E(s),s=i,i=u}this._a=i+this._a|0,this._b=s+this._b|0,this._c=h+this._c|0,this._d=n+this._d|0,this._e=o+this._e|0};a.prototype._hash=function(){var t=p.allocUnsafe(20);return t.writeInt32BE(this._a|0,0),t.writeInt32BE(this._b|0,4),t.writeInt32BE(this._c|0,8),t.writeInt32BE(this._d|0,12),t.writeInt32BE(this._e|0,16),t};var I=a;exports.sha=I;
|