@gardenfi/utils 2.0.5 → 2.0.6-alpha.1

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.
Files changed (234) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +22 -20
  3. package/dist/index10.cjs +1 -1
  4. package/dist/index10.js +37 -19
  5. package/dist/index100.cjs +1 -1
  6. package/dist/index100.js +40 -6
  7. package/dist/index101.cjs +1 -2
  8. package/dist/index101.js +644 -3
  9. package/dist/index102.cjs +1 -1
  10. package/dist/index102.js +227 -108
  11. package/dist/index103.cjs +1 -1
  12. package/dist/index103.js +167 -73
  13. package/dist/index104.cjs +1 -1
  14. package/dist/index104.js +13 -2
  15. package/dist/index105.cjs +1 -1
  16. package/dist/index105.js +126 -16
  17. package/dist/index106.cjs +2 -1
  18. package/dist/index106.js +3 -19
  19. package/dist/index107.cjs +1 -1
  20. package/dist/index107.js +17 -15
  21. package/dist/index108.cjs +1 -1
  22. package/dist/index108.js +36 -221
  23. package/dist/index109.cjs +1 -1
  24. package/dist/index109.js +2 -35
  25. package/dist/index11.cjs +1 -1
  26. package/dist/index11.js +19 -134
  27. package/dist/index110.cjs +1 -1
  28. package/dist/index110.js +2 -19
  29. package/dist/index111.cjs +1 -1
  30. package/dist/index111.js +32 -64
  31. package/dist/index112.cjs +1 -1
  32. package/dist/index112.js +10 -66
  33. package/dist/index113.cjs +1 -1
  34. package/dist/index113.js +20 -2
  35. package/dist/index114.cjs +1 -1
  36. package/dist/index114.js +5 -41
  37. package/dist/index115.cjs +1 -1
  38. package/dist/index115.js +10 -643
  39. package/dist/index116.cjs +1 -1
  40. package/dist/index116.js +16 -227
  41. package/dist/index117.cjs +1 -1
  42. package/dist/index117.js +6 -172
  43. package/dist/index118.cjs +1 -0
  44. package/dist/index118.js +7 -0
  45. package/dist/index12.cjs +1 -1
  46. package/dist/index12.js +136 -10
  47. package/dist/index13.cjs +1 -1
  48. package/dist/index13.js +15 -2
  49. package/dist/index14.cjs +1 -1
  50. package/dist/index14.js +2 -34
  51. package/dist/index15.cjs +1 -1
  52. package/dist/index15.js +32 -17
  53. package/dist/index16.cjs +1 -1
  54. package/dist/index16.js +14 -183
  55. package/dist/index17.cjs +1 -1
  56. package/dist/index17.js +187 -92
  57. package/dist/index18.cjs +1 -1
  58. package/dist/index18.js +92 -34
  59. package/dist/index19.cjs +1 -1
  60. package/dist/index19.js +36 -32
  61. package/dist/index20.cjs +1 -16
  62. package/dist/index20.js +30 -112
  63. package/dist/index21.cjs +16 -1
  64. package/dist/index21.js +113 -30
  65. package/dist/index22.cjs +1 -1
  66. package/dist/index22.js +31 -18
  67. package/dist/index23.cjs +1 -1
  68. package/dist/index23.js +41 -7
  69. package/dist/index24.cjs +1 -1
  70. package/dist/index24.js +3 -3
  71. package/dist/index25.cjs +1 -1
  72. package/dist/index25.js +23 -19
  73. package/dist/index26.cjs +1 -1
  74. package/dist/index26.js +6 -8
  75. package/dist/index27.cjs +1 -1
  76. package/dist/index27.js +12 -30
  77. package/dist/index28.cjs +1 -1
  78. package/dist/index28.js +15 -26
  79. package/dist/index29.cjs +1 -2
  80. package/dist/index29.js +5 -65
  81. package/dist/index30.cjs +1 -1
  82. package/dist/index30.js +13 -51
  83. package/dist/index31.cjs +1 -1
  84. package/dist/index31.js +10 -12
  85. package/dist/index32.cjs +1 -1
  86. package/dist/index32.js +12 -24
  87. package/dist/index33.cjs +1 -1
  88. package/dist/index33.js +11 -75
  89. package/dist/index34.cjs +1 -1
  90. package/dist/index34.js +13 -23
  91. package/dist/index35.cjs +1 -1
  92. package/dist/index35.js +23 -7
  93. package/dist/index36.cjs +1 -1
  94. package/dist/index36.js +55 -32
  95. package/dist/index37.cjs +1 -1
  96. package/dist/index37.js +16 -15
  97. package/dist/index38.cjs +1 -1
  98. package/dist/index38.js +6 -2
  99. package/dist/index39.cjs +1 -1
  100. package/dist/index39.js +8 -8
  101. package/dist/index4.cjs +1 -1
  102. package/dist/index4.js +2 -2
  103. package/dist/index40.cjs +1 -1
  104. package/dist/index40.js +171 -20
  105. package/dist/index41.cjs +1 -1
  106. package/dist/index41.js +100 -9
  107. package/dist/index42.cjs +1 -1
  108. package/dist/index42.js +20 -33
  109. package/dist/index43.cjs +1 -2
  110. package/dist/index43.js +17 -59
  111. package/dist/index44.cjs +1 -1
  112. package/dist/index44.js +8 -2
  113. package/dist/index45.cjs +1 -1
  114. package/dist/index45.js +21 -6
  115. package/dist/index46.cjs +1 -1
  116. package/dist/index46.js +8 -6
  117. package/dist/index47.cjs +1 -1
  118. package/dist/index47.js +31 -4
  119. package/dist/index48.cjs +1 -1
  120. package/dist/index48.js +26 -11
  121. package/dist/index49.cjs +2 -5
  122. package/dist/index49.js +53 -44
  123. package/dist/index50.cjs +1 -1
  124. package/dist/index50.js +51 -3
  125. package/dist/index51.cjs +1 -2
  126. package/dist/index51.js +12 -34
  127. package/dist/index52.cjs +1 -1
  128. package/dist/index52.js +24 -5
  129. package/dist/index53.cjs +1 -1
  130. package/dist/index53.js +75 -21
  131. package/dist/index54.cjs +1 -1
  132. package/dist/index54.js +7 -12
  133. package/dist/index55.cjs +1 -1
  134. package/dist/index55.js +32 -55
  135. package/dist/index56.cjs +1 -1
  136. package/dist/index56.js +15 -8
  137. package/dist/index57.cjs +1 -1
  138. package/dist/index57.js +2 -22
  139. package/dist/index58.cjs +1 -1
  140. package/dist/index58.js +8 -11
  141. package/dist/index59.cjs +1 -1
  142. package/dist/index59.js +20 -8
  143. package/dist/index6.cjs +1 -1
  144. package/dist/index6.js +40 -22
  145. package/dist/index60.cjs +1 -1
  146. package/dist/index60.js +112 -10
  147. package/dist/index61.cjs +1 -1
  148. package/dist/index61.js +16 -11
  149. package/dist/index62.cjs +1 -1
  150. package/dist/index62.js +223 -6
  151. package/dist/index63.cjs +1 -1
  152. package/dist/index63.js +12 -13
  153. package/dist/index64.cjs +1 -1
  154. package/dist/index64.js +32 -30
  155. package/dist/index65.cjs +2 -1
  156. package/dist/index65.js +59 -14
  157. package/dist/index66.cjs +1 -1
  158. package/dist/index66.js +19 -62
  159. package/dist/index67.cjs +1 -1
  160. package/dist/index67.js +4 -27
  161. package/dist/index68.cjs +1 -1
  162. package/dist/index68.js +4 -3
  163. package/dist/index69.cjs +1 -1
  164. package/dist/index69.js +18 -5
  165. package/dist/index7.cjs +1 -1
  166. package/dist/index7.js +24 -2
  167. package/dist/index70.cjs +1 -1
  168. package/dist/index70.js +42 -8
  169. package/dist/index71.cjs +1 -1
  170. package/dist/index71.js +8 -3
  171. package/dist/index72.cjs +1 -1
  172. package/dist/index72.js +104 -13
  173. package/dist/index73.cjs +1 -1
  174. package/dist/index73.js +8 -41
  175. package/dist/index74.cjs +1 -1
  176. package/dist/index74.js +9 -102
  177. package/dist/index75.cjs +1 -1
  178. package/dist/index75.js +10 -190
  179. package/dist/index76.cjs +1 -1
  180. package/dist/index76.js +13 -18
  181. package/dist/index77.cjs +1 -1
  182. package/dist/index77.js +6 -11
  183. package/dist/index78.cjs +1 -1
  184. package/dist/index78.js +17 -19
  185. package/dist/index79.cjs +1 -1
  186. package/dist/index79.js +77 -24
  187. package/dist/index8.cjs +1 -1
  188. package/dist/index8.js +2 -100
  189. package/dist/index80.cjs +1 -1
  190. package/dist/index80.js +14 -6
  191. package/dist/index81.cjs +1 -1
  192. package/dist/index81.js +18 -13
  193. package/dist/index82.cjs +1 -1
  194. package/dist/index82.js +190 -14
  195. package/dist/index83.cjs +1 -1
  196. package/dist/index83.js +64 -5
  197. package/dist/index84.cjs +1 -1
  198. package/dist/index84.js +2 -14
  199. package/dist/index85.cjs +1 -1
  200. package/dist/index85.js +6 -10
  201. package/dist/index86.cjs +1 -1
  202. package/dist/index86.js +11 -16
  203. package/dist/index87.cjs +5 -1
  204. package/dist/index87.js +50 -165
  205. package/dist/index88.cjs +2 -1
  206. package/dist/index88.js +34 -8
  207. package/dist/index89.cjs +1 -1
  208. package/dist/index89.js +5 -12
  209. package/dist/index9.cjs +1 -1
  210. package/dist/index9.js +90 -34
  211. package/dist/index90.cjs +1 -1
  212. package/dist/index90.js +3 -104
  213. package/dist/index91.cjs +1 -1
  214. package/dist/index91.js +6 -38
  215. package/dist/index92.cjs +1 -1
  216. package/dist/index92.js +33 -2
  217. package/dist/index93.cjs +1 -1
  218. package/dist/index93.js +28 -5
  219. package/dist/index94.cjs +1 -1
  220. package/dist/index94.js +3 -11
  221. package/dist/index95.cjs +1 -1
  222. package/dist/index95.js +6 -40
  223. package/dist/index96.cjs +1 -1
  224. package/dist/index96.js +64 -17
  225. package/dist/index97.cjs +1 -1
  226. package/dist/index97.js +70 -5
  227. package/dist/index98.cjs +1 -1
  228. package/dist/index98.js +2 -38
  229. package/dist/index99.cjs +1 -1
  230. package/dist/index99.js +34 -127
  231. package/dist/src/index.d.ts +1 -0
  232. package/dist/src/lib/auth/siwe/siwe.d.ts +2 -1
  233. package/dist/src/lib/digestKey/digestKey.d.ts +12 -0
  234. package/package.json +2 -1
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index2.cjs"),e=require("./index3.cjs"),s=require("./index4.cjs"),r=require("./index5.cjs"),i=require("./index6.cjs"),n=require("./index7.cjs"),u=require("./index8.cjs"),c=require("./index9.cjs"),a=require("./index10.cjs"),p=require("./index11.cjs"),k=require("./index12.cjs"),l=require("./index13.cjs"),t=require("./index14.cjs"),y=require("./index15.cjs");exports.ApiStatus=o.ApiStatus;exports.Authorization=e.Authorization;exports.Environment=e.Environment;exports.Network=e.Network;exports.add0x=e.add0x;exports.hexToU32Array=e.hexToU32Array;exports.parseJwt=e.parseJwt;exports.sleep=e.sleep;exports.with0x=e.with0x;exports.checkAllowanceAndApprove=s.checkAllowanceAndApprove;exports.Err=r.Err;exports.Ok=r.Ok;exports.Result=r.Result;exports.Void=r.Void;exports.Url=i.Url;exports.AuthHeaderEnum=n.AuthHeaderEnum;exports.Siwe=u.Siwe;exports.ApiKey=c.ApiKey;exports.Passkey=a.Passkey;exports.PasskeyLogin=p.PasskeyLogin;exports.MemoryStorage=k.MemoryStorage;exports.StoreKeys=l.StoreKeys;exports.fetchBitcoinBlockNumber=t.fetchBitcoinBlockNumber;exports.fetchEVMBlockNumber=t.fetchEVMBlockNumber;exports.EventBroker=y.EventBroker;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index2.cjs"),e=require("./index3.cjs"),s=require("./index4.cjs"),r=require("./index5.cjs"),i=require("./index6.cjs"),n=require("./index7.cjs"),u=require("./index8.cjs"),c=require("./index9.cjs"),a=require("./index10.cjs"),y=require("./index11.cjs"),p=require("./index12.cjs"),k=require("./index13.cjs"),l=require("./index14.cjs"),t=require("./index15.cjs"),A=require("./index16.cjs");exports.ApiStatus=o.ApiStatus;exports.Authorization=e.Authorization;exports.Environment=e.Environment;exports.Network=e.Network;exports.add0x=e.add0x;exports.hexToU32Array=e.hexToU32Array;exports.parseJwt=e.parseJwt;exports.sleep=e.sleep;exports.with0x=e.with0x;exports.checkAllowanceAndApprove=s.checkAllowanceAndApprove;exports.Err=r.Err;exports.Ok=r.Ok;exports.Result=r.Result;exports.Void=r.Void;exports.DigestKey=i.DigestKey;exports.Url=n.Url;exports.AuthHeaderEnum=u.AuthHeaderEnum;exports.Siwe=c.Siwe;exports.ApiKey=a.ApiKey;exports.Passkey=y.Passkey;exports.PasskeyLogin=p.PasskeyLogin;exports.MemoryStorage=k.MemoryStorage;exports.StoreKeys=l.StoreKeys;exports.fetchBitcoinBlockNumber=t.fetchBitcoinBlockNumber;exports.fetchEVMBlockNumber=t.fetchEVMBlockNumber;exports.EventBroker=A.EventBroker;
package/dist/index.js CHANGED
@@ -2,38 +2,40 @@ import { ApiStatus as e } from "./index2.js";
2
2
  import { Authorization as p, Environment as m, Network as x, add0x as f, hexToU32Array as i, parseJwt as a, sleep as n, with0x as s } from "./index3.js";
3
3
  import { checkAllowanceAndApprove as k } from "./index4.js";
4
4
  import { Err as h, Ok as l, Result as u, Void as y } from "./index5.js";
5
- import { Url as w } from "./index6.js";
6
- import { AuthHeaderEnum as B } from "./index7.js";
7
- import { Siwe as v } from "./index8.js";
8
- import { ApiKey as b } from "./index9.js";
9
- import { Passkey as K } from "./index10.js";
10
- import { PasskeyLogin as P } from "./index11.js";
11
- import { MemoryStorage as V } from "./index12.js";
12
- import { StoreKeys as H } from "./index13.js";
13
- import { fetchBitcoinBlockNumber as L, fetchEVMBlockNumber as O } from "./index14.js";
14
- import { EventBroker as T } from "./index15.js";
5
+ import { DigestKey as w } from "./index6.js";
6
+ import { Url as B } from "./index7.js";
7
+ import { AuthHeaderEnum as g } from "./index8.js";
8
+ import { Siwe as K } from "./index9.js";
9
+ import { ApiKey as b } from "./index10.js";
10
+ import { Passkey as P } from "./index11.js";
11
+ import { PasskeyLogin as V } from "./index12.js";
12
+ import { MemoryStorage as D } from "./index13.js";
13
+ import { StoreKeys as J } from "./index14.js";
14
+ import { fetchBitcoinBlockNumber as O, fetchEVMBlockNumber as R } from "./index15.js";
15
+ import { EventBroker as j } from "./index16.js";
15
16
  export {
16
17
  b as ApiKey,
17
18
  e as ApiStatus,
18
- B as AuthHeaderEnum,
19
+ g as AuthHeaderEnum,
19
20
  p as Authorization,
21
+ w as DigestKey,
20
22
  m as Environment,
21
23
  h as Err,
22
- T as EventBroker,
23
- V as MemoryStorage,
24
+ j as EventBroker,
25
+ D as MemoryStorage,
24
26
  x as Network,
25
27
  l as Ok,
26
- K as Passkey,
27
- P as PasskeyLogin,
28
+ P as Passkey,
29
+ V as PasskeyLogin,
28
30
  u as Result,
29
- v as Siwe,
30
- H as StoreKeys,
31
- w as Url,
31
+ K as Siwe,
32
+ J as StoreKeys,
33
+ B as Url,
32
34
  y as Void,
33
35
  f as add0x,
34
36
  k as checkAllowanceAndApprove,
35
- L as fetchBitcoinBlockNumber,
36
- O as fetchEVMBlockNumber,
37
+ O as fetchBitcoinBlockNumber,
38
+ R as fetchEVMBlockNumber,
37
39
  i as hexToU32Array,
38
40
  a as parseJwt,
39
41
  n as sleep,
package/dist/index10.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index16.cjs"),o=require("./index7.cjs"),s=require("./index3.cjs");class i{constructor(e){this.token=e}async getToken(){return this.token?this.verifyToken(this.token).ok?t.Ok(this.token):t.Err("Token is invalid"):t.Err("Token is not set")}verifyToken(e){try{const r=s.parseJwt(e);if(!r)return t.Ok(!1);const n=Math.floor(Date.now()/1e3)+120;return t.Ok(r.exp>n)}catch{return t.Ok(!1)}}async getAuthHeaders(){const e=await this.getToken();return e.ok?t.Ok({[o.AuthHeaderEnum.Authorization]:e.val}):t.Err(e.error??"Failed to get auth token")}}exports.Passkey=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index17.cjs"),l=require("./index8.cjs");class f{constructor(e){this.apiKey=e}async getToken(){const e=this.verifyToken();return e.error?t.Err(e.error):e.val?t.Ok(this.apiKey):t.Err("Token verification failed")}verifyToken(){const e=this.decodeBase64UrlSafe(this.apiKey),r=this.extractData(e);if(r.error)return t.Err(r.error);const{expiryTimestamp:i}=r.val;return i<new Date?t.Err("Token expired"):t.Ok(!0)}decodeBase64UrlSafe(e){let r=e.replace(/_/g,"/").replace(/-/g,"+");for(;r.length%4!==0;)r+="=";return Uint8Array.from(atob(r),i=>i.charCodeAt(0))}extractData(e){const r=new TextEncoder().encode("::"),i=e.findIndex((n,a)=>e.slice(a,a+r.length).every((u,d)=>u===r[d]));if(i===-1)return t.Err("Invalid format: delimiter not found");const o=e.slice(0,8),s=new DataView(o.buffer).getBigUint64(0,!1),c=e.slice(i+r.length);return t.Ok({expiryTimestamp:new Date(Number(s)*1e3),signature:Array.from(c).map(n=>n.toString(16).padStart(2,"0")).join("")})}async getAuthHeaders(){const e=await this.getToken();return e.ok?t.Ok({[l.AuthHeaderEnum.ApiKey]:e.val}):t.Err(e.error??"Failed to get auth token")}}exports.ApiKey=f;
package/dist/index10.js CHANGED
@@ -1,28 +1,46 @@
1
- import { Err as r, Ok as e } from "./index16.js";
2
- import { AuthHeaderEnum as s } from "./index7.js";
3
- import { parseJwt as i } from "./index3.js";
4
- class c {
5
- constructor(t) {
6
- this.token = t;
1
+ import { Err as i, Ok as n } from "./index17.js";
2
+ import { AuthHeaderEnum as u } from "./index8.js";
3
+ class h {
4
+ constructor(e) {
5
+ this.apiKey = e;
7
6
  }
8
7
  async getToken() {
9
- return this.token ? this.verifyToken(this.token).ok ? e(this.token) : r("Token is invalid") : r("Token is not set");
8
+ const e = this.verifyToken();
9
+ return e.error ? i(e.error) : e.val ? n(this.apiKey) : i("Token verification failed");
10
10
  }
11
- verifyToken(t) {
12
- try {
13
- const o = i(t);
14
- if (!o) return e(!1);
15
- const n = Math.floor(Date.now() / 1e3) + 120;
16
- return e(o.exp > n);
17
- } catch {
18
- return e(!1);
19
- }
11
+ verifyToken() {
12
+ const e = this.decodeBase64UrlSafe(this.apiKey), r = this.extractData(e);
13
+ if (r.error)
14
+ return i(r.error);
15
+ const { expiryTimestamp: t } = r.val;
16
+ return t < /* @__PURE__ */ new Date() ? i("Token expired") : n(!0);
17
+ }
18
+ decodeBase64UrlSafe(e) {
19
+ let r = e.replace(/_/g, "/").replace(/-/g, "+");
20
+ for (; r.length % 4 !== 0; )
21
+ r += "=";
22
+ return Uint8Array.from(atob(r), (t) => t.charCodeAt(0));
23
+ }
24
+ extractData(e) {
25
+ const r = new TextEncoder().encode("::"), t = e.findIndex(
26
+ (a, o) => e.slice(o, o + r.length).every((f, l) => f === r[l])
27
+ );
28
+ if (t === -1)
29
+ return i("Invalid format: delimiter not found");
30
+ const s = e.slice(0, 8), c = new DataView(s.buffer).getBigUint64(
31
+ 0,
32
+ !1
33
+ ), d = e.slice(t + r.length);
34
+ return n({
35
+ expiryTimestamp: new Date(Number(c) * 1e3),
36
+ signature: Array.from(d).map((a) => a.toString(16).padStart(2, "0")).join("")
37
+ });
20
38
  }
21
39
  async getAuthHeaders() {
22
- const t = await this.getToken();
23
- return t.ok ? e({ [s.Authorization]: t.val }) : r(t.error ?? "Failed to get auth token");
40
+ const e = await this.getToken();
41
+ return e.ok ? n({ [u.ApiKey]: e.val }) : i(e.error ?? "Failed to get auth token");
24
42
  }
25
43
  }
26
44
  export {
27
- c as Passkey
45
+ h as ApiKey
28
46
  };
package/dist/index100.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index102.cjs"),s=require("./index71.cjs"),r=require("./index55.cjs");function o(t,i){return e.sha256(s.isHex(t,{strict:!1})?r.toBytes(t):t)}exports.sha256=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index99.cjs"),c=require("./index97.cjs");class r extends c.Hash{constructor(t,i){super(),this.finished=!1,this.destroyed=!1,o.ahash(t);const h=c.toBytes(i);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const a=this.blockLen,e=new Uint8Array(a);e.set(h.length>a?t.create().update(h).digest():h);for(let s=0;s<e.length;s++)e[s]^=54;this.iHash.update(e),this.oHash=t.create();for(let s=0;s<e.length;s++)e[s]^=106;this.oHash.update(e),e.fill(0)}update(t){return o.aexists(this),this.iHash.update(t),this}digestInto(t){o.aexists(this),o.abytes(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:i,iHash:h,finished:a,destroyed:e,blockLen:s,outputLen:u}=this;return t=t,t.finished=a,t.destroyed=e,t.blockLen=s,t.outputLen=u,t.oHash=i._cloneInto(t.oHash),t.iHash=h._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const d=(n,t,i)=>new r(n,t).update(i).digest();d.create=(n,t)=>new r(n,t);exports.HMAC=r;exports.hmac=d;
package/dist/index100.js CHANGED
@@ -1,9 +1,43 @@
1
- import { sha256 as o } from "./index102.js";
2
- import { isHex as s } from "./index71.js";
3
- import { toBytes as r } from "./index55.js";
4
- function p(t, i) {
5
- return o(s(t, { strict: !1 }) ? r(t) : t);
1
+ import { ahash as c, aexists as a, abytes as u } from "./index99.js";
2
+ import { Hash as H, toBytes as p } from "./index97.js";
3
+ class r extends H {
4
+ constructor(t, i) {
5
+ super(), this.finished = !1, this.destroyed = !1, c(t);
6
+ const h = p(i);
7
+ if (this.iHash = t.create(), typeof this.iHash.update != "function")
8
+ throw new Error("Expected instance of class which extends utils.Hash");
9
+ this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
10
+ const o = this.blockLen, e = new Uint8Array(o);
11
+ e.set(h.length > o ? t.create().update(h).digest() : h);
12
+ for (let s = 0; s < e.length; s++)
13
+ e[s] ^= 54;
14
+ this.iHash.update(e), this.oHash = t.create();
15
+ for (let s = 0; s < e.length; s++)
16
+ e[s] ^= 106;
17
+ this.oHash.update(e), e.fill(0);
18
+ }
19
+ update(t) {
20
+ return a(this), this.iHash.update(t), this;
21
+ }
22
+ digestInto(t) {
23
+ a(this), u(t, this.outputLen), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
24
+ }
25
+ digest() {
26
+ const t = new Uint8Array(this.oHash.outputLen);
27
+ return this.digestInto(t), t;
28
+ }
29
+ _cloneInto(t) {
30
+ t || (t = Object.create(Object.getPrototypeOf(this), {}));
31
+ const { oHash: i, iHash: h, finished: o, destroyed: e, blockLen: s, outputLen: d } = this;
32
+ return t = t, t.finished = o, t.destroyed = e, t.blockLen = s, t.outputLen = d, t.oHash = i._cloneInto(t.oHash), t.iHash = h._cloneInto(t.iHash), t;
33
+ }
34
+ destroy() {
35
+ this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
36
+ }
6
37
  }
38
+ const l = (n, t, i) => new r(n, t).update(i).digest();
39
+ l.create = (n, t) => new r(n, t);
7
40
  export {
8
- p as sha256
41
+ r as HMAC,
42
+ l as hmac
9
43
  };
package/dist/index101.cjs CHANGED
@@ -1,2 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`Ethereum Signed Message:
2
- `;exports.presignMessagePrefix=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const tt=require("./index103.cjs"),Q=require("./index62.cjs"),a=require("./index102.cjs");/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ot(h){h.lowS!==void 0&&a.abool("lowS",h.lowS),h.prehash!==void 0&&a.abool("prehash",h.prehash)}function ct(h){const n=tt.validateBasic(h);a.validateObject(n,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:t,Fp:b,a:O}=n;if(t){if(!b.eql(O,b.ZERO))throw new Error("invalid 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("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...n})}const{bytesToNumberBE:lt,hexToBytes:ut}=a;class it extends Error{constructor(n=""){super(n)}}const Y={Err:it,_tlv:{encode:(h,n)=>{const{Err:t}=Y;if(h<0||h>256)throw new t("tlv.encode: wrong tag");if(n.length&1)throw new t("tlv.encode: unpadded data");const b=n.length/2,O=a.numberToHexUnpadded(b);if(O.length/2&128)throw new t("tlv.encode: long form length too big");const Z=b>127?a.numberToHexUnpadded(O.length/2|128):"";return a.numberToHexUnpadded(h)+Z+O+n},decode(h,n){const{Err:t}=Y;let b=0;if(h<0||h>256)throw new t("tlv.encode: wrong tag");if(n.length<2||n[b++]!==h)throw new t("tlv.decode: wrong tlv");const O=n[b++],Z=!!(O&128);let x=0;if(!Z)x=O;else{const R=O&127;if(!R)throw new t("tlv.decode(long): indefinite length not supported");if(R>4)throw new t("tlv.decode(long): byte length is too big");const L=n.subarray(b,b+R);if(L.length!==R)throw new t("tlv.decode: length bytes not complete");if(L[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(const P of L)x=x<<8|P;if(b+=R,x<128)throw new t("tlv.decode(long): not minimal encoding")}const V=n.subarray(b,b+x);if(V.length!==x)throw new t("tlv.decode: wrong value length");return{v:V,l:n.subarray(b+x)}}},_int:{encode(h){const{Err:n}=Y;if(h<C)throw new n("integer: negative integers are not allowed");let t=a.numberToHexUnpadded(h);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new n("unexpected DER parsing assertion: unpadded hex");return t},decode(h){const{Err:n}=Y;if(h[0]&128)throw new n("invalid signature integer: negative");if(h[0]===0&&!(h[1]&128))throw new n("invalid signature integer: unnecessary leading zero");return lt(h)}},toSig(h){const{Err:n,_int:t,_tlv:b}=Y,O=typeof h=="string"?ut(h):h;a.abytes(O);const{v:Z,l:x}=b.decode(48,O);if(x.length)throw new n("invalid signature: left bytes after parsing");const{v:V,l:R}=b.decode(2,Z),{v:L,l:P}=b.decode(2,R);if(P.length)throw new n("invalid signature: left bytes after parsing");return{r:t.decode(V),s:t.decode(L)}},hexFromSig(h){const{_tlv:n,_int:t}=Y,b=n.encode(2,t.encode(h.r)),O=n.encode(2,t.encode(h.s)),Z=b+O;return n.encode(48,Z)}},C=BigInt(0),T=BigInt(1);BigInt(2);const st=BigInt(3);BigInt(4);function at(h){const n=ct(h),{Fp:t}=n,b=Q.Field(n.n,n.nBitLength),O=n.toBytes||((m,e,s)=>{const c=e.toAffine();return a.concatBytes(Uint8Array.from([4]),t.toBytes(c.x),t.toBytes(c.y))}),Z=n.fromBytes||(m=>{const e=m.subarray(1),s=t.fromBytes(e.subarray(0,t.BYTES)),c=t.fromBytes(e.subarray(t.BYTES,2*t.BYTES));return{x:s,y:c}});function x(m){const{a:e,b:s}=n,c=t.sqr(m),d=t.mul(c,m);return t.add(t.add(d,t.mul(m,e)),s)}if(!t.eql(t.sqr(n.Gy),x(n.Gx)))throw new Error("bad generator point: equation left != right");function V(m){return a.inRange(m,T,n.n)}function R(m){const{allowedPrivateKeyLengths:e,nByteLength:s,wrapPrivateKey:c,n:d}=n;if(e&&typeof m!="bigint"){if(a.isBytes(m)&&(m=a.bytesToHex(m)),typeof m!="string"||!e.includes(m.length))throw new Error("invalid private key");m=m.padStart(s*2,"0")}let p;try{p=typeof m=="bigint"?m:a.bytesToNumberBE(a.ensureBytes("private key",m,s))}catch{throw new Error("invalid private key, expected hex or "+s+" bytes, got "+typeof m)}return c&&(p=Q.mod(p,d)),a.aInRange("private key",p,T,d),p}function L(m){if(!(m instanceof w))throw new Error("ProjectivePoint expected")}const P=a.memoized((m,e)=>{const{px:s,py:c,pz:d}=m;if(t.eql(d,t.ONE))return{x:s,y:c};const p=m.is0();e==null&&(e=p?t.ONE:t.inv(d));const v=t.mul(s,e),g=t.mul(c,e),l=t.mul(d,e);if(p)return{x:t.ZERO,y:t.ZERO};if(!t.eql(l,t.ONE))throw new Error("invZ was invalid");return{x:v,y:g}}),et=a.memoized(m=>{if(m.is0()){if(n.allowInfinityPoint&&!t.is0(m.py))return;throw new Error("bad point: ZERO")}const{x:e,y:s}=m.toAffine();if(!t.isValid(e)||!t.isValid(s))throw new Error("bad point: x or y not FE");const c=t.sqr(s),d=x(e);if(!t.eql(c,d))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class w{constructor(e,s,c){if(this.px=e,this.py=s,this.pz=c,e==null||!t.isValid(e))throw new Error("x required");if(s==null||!t.isValid(s))throw new Error("y required");if(c==null||!t.isValid(c))throw new Error("z required");Object.freeze(this)}static fromAffine(e){const{x:s,y:c}=e||{};if(!e||!t.isValid(s)||!t.isValid(c))throw new Error("invalid affine point");if(e instanceof w)throw new Error("projective point not allowed");const d=p=>t.eql(p,t.ZERO);return d(s)&&d(c)?w.ZERO:new w(s,c,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){const s=t.invertBatch(e.map(c=>c.pz));return e.map((c,d)=>c.toAffine(s[d])).map(w.fromAffine)}static fromHex(e){const s=w.fromAffine(Z(a.ensureBytes("pointHex",e)));return s.assertValidity(),s}static fromPrivateKey(e){return w.BASE.multiply(R(e))}static msm(e,s){return tt.pippenger(w,b,e,s)}_setWindowSize(e){j.setWindowSize(this,e)}assertValidity(){et(this)}hasEvenY(){const{y:e}=this.toAffine();if(t.isOdd)return!t.isOdd(e);throw new Error("Field doesn't support isOdd")}equals(e){L(e);const{px:s,py:c,pz:d}=this,{px:p,py:v,pz:g}=e,l=t.eql(t.mul(s,g),t.mul(p,d)),y=t.eql(t.mul(c,g),t.mul(v,d));return l&&y}negate(){return new w(this.px,t.neg(this.py),this.pz)}double(){const{a:e,b:s}=n,c=t.mul(s,st),{px:d,py:p,pz:v}=this;let g=t.ZERO,l=t.ZERO,y=t.ZERO,u=t.mul(d,d),N=t.mul(p,p),S=t.mul(v,v),B=t.mul(d,p);return B=t.add(B,B),y=t.mul(d,v),y=t.add(y,y),g=t.mul(e,y),l=t.mul(c,S),l=t.add(g,l),g=t.sub(N,l),l=t.add(N,l),l=t.mul(g,l),g=t.mul(B,g),y=t.mul(c,y),S=t.mul(e,S),B=t.sub(u,S),B=t.mul(e,B),B=t.add(B,y),y=t.add(u,u),u=t.add(y,u),u=t.add(u,S),u=t.mul(u,B),l=t.add(l,u),S=t.mul(p,v),S=t.add(S,S),u=t.mul(S,B),g=t.sub(g,u),y=t.mul(S,N),y=t.add(y,y),y=t.add(y,y),new w(g,l,y)}add(e){L(e);const{px:s,py:c,pz:d}=this,{px:p,py:v,pz:g}=e;let l=t.ZERO,y=t.ZERO,u=t.ZERO;const N=n.a,S=t.mul(n.b,st);let B=t.mul(s,p),F=t.mul(c,v),r=t.mul(d,g),o=t.add(s,c),i=t.add(p,v);o=t.mul(o,i),i=t.add(B,F),o=t.sub(o,i),i=t.add(s,d);let f=t.add(p,g);return i=t.mul(i,f),f=t.add(B,r),i=t.sub(i,f),f=t.add(c,d),l=t.add(v,g),f=t.mul(f,l),l=t.add(F,r),f=t.sub(f,l),u=t.mul(N,i),l=t.mul(S,r),u=t.add(l,u),l=t.sub(F,u),u=t.add(F,u),y=t.mul(l,u),F=t.add(B,B),F=t.add(F,B),r=t.mul(N,r),i=t.mul(S,i),F=t.add(F,r),r=t.sub(B,r),r=t.mul(N,r),i=t.add(i,r),B=t.mul(F,i),y=t.add(y,B),B=t.mul(f,i),l=t.mul(o,l),l=t.sub(l,B),B=t.mul(o,F),u=t.mul(f,u),u=t.add(u,B),new w(l,y,u)}subtract(e){return this.add(e.negate())}is0(){return this.equals(w.ZERO)}wNAF(e){return j.wNAFCached(this,e,w.normalizeZ)}multiplyUnsafe(e){const{endo:s,n:c}=n;a.aInRange("scalar",e,C,c);const d=w.ZERO;if(e===C)return d;if(this.is0()||e===T)return this;if(!s||j.hasPrecomputes(this))return j.wNAFCachedUnsafe(this,e,w.normalizeZ);let{k1neg:p,k1:v,k2neg:g,k2:l}=s.splitScalar(e),y=d,u=d,N=this;for(;v>C||l>C;)v&T&&(y=y.add(N)),l&T&&(u=u.add(N)),N=N.double(),v>>=T,l>>=T;return p&&(y=y.negate()),g&&(u=u.negate()),u=new w(t.mul(u.px,s.beta),u.py,u.pz),y.add(u)}multiply(e){const{endo:s,n:c}=n;a.aInRange("scalar",e,T,c);let d,p;if(s){const{k1neg:v,k1:g,k2neg:l,k2:y}=s.splitScalar(e);let{p:u,f:N}=this.wNAF(g),{p:S,f:B}=this.wNAF(y);u=j.constTimeNegate(v,u),S=j.constTimeNegate(l,S),S=new w(t.mul(S.px,s.beta),S.py,S.pz),d=u.add(S),p=N.add(B)}else{const{p:v,f:g}=this.wNAF(e);d=v,p=g}return w.normalizeZ([d,p])[0]}multiplyAndAddUnsafe(e,s,c){const d=w.BASE,p=(g,l)=>l===C||l===T||!g.equals(d)?g.multiplyUnsafe(l):g.multiply(l),v=p(this,s).add(p(e,c));return v.is0()?void 0:v}toAffine(e){return P(this,e)}isTorsionFree(){const{h:e,isTorsionFree:s}=n;if(e===T)return!0;if(s)return s(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:e,clearCofactor:s}=n;return e===T?this:s?s(w,this):this.multiplyUnsafe(n.h)}toRawBytes(e=!0){return a.abool("isCompressed",e),this.assertValidity(),O(w,this,e)}toHex(e=!0){return a.abool("isCompressed",e),a.bytesToHex(this.toRawBytes(e))}}w.BASE=new w(n.Gx,n.Gy,t.ONE),w.ZERO=new w(t.ZERO,t.ONE,t.ZERO);const M=n.nBitLength,j=tt.wNAF(w,n.endo?Math.ceil(M/2):M);return{CURVE:n,ProjectivePoint:w,normPrivateKeyToScalar:R,weierstrassEquation:x,isWithinCurveOrder:V}}function dt(h){const n=tt.validateBasic(h);return a.validateObject(n,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...n})}function ft(h){const n=dt(h),{Fp:t,n:b}=n,O=t.BYTES+1,Z=2*t.BYTES+1;function x(r){return Q.mod(r,b)}function V(r){return Q.invert(r,b)}const{ProjectivePoint:R,normPrivateKeyToScalar:L,weierstrassEquation:P,isWithinCurveOrder:et}=at({...n,toBytes(r,o,i){const f=o.toAffine(),E=t.toBytes(f.x),A=a.concatBytes;return a.abool("isCompressed",i),i?A(Uint8Array.from([o.hasEvenY()?2:3]),E):A(Uint8Array.from([4]),E,t.toBytes(f.y))},fromBytes(r){const o=r.length,i=r[0],f=r.subarray(1);if(o===O&&(i===2||i===3)){const E=a.bytesToNumberBE(f);if(!a.inRange(E,T,t.ORDER))throw new Error("Point is not on curve");const A=P(E);let z;try{z=t.sqrt(A)}catch(U){const H=U instanceof Error?": "+U.message:"";throw new Error("Point is not on curve"+H)}const q=(z&T)===T;return(i&1)===1!==q&&(z=t.neg(z)),{x:E,y:z}}else if(o===Z&&i===4){const E=t.fromBytes(f.subarray(0,t.BYTES)),A=t.fromBytes(f.subarray(t.BYTES,2*t.BYTES));return{x:E,y:A}}else{const E=O,A=Z;throw new Error("invalid Point, expected length of "+E+", or uncompressed "+A+", got "+o)}}}),w=r=>a.bytesToHex(a.numberToBytesBE(r,n.nByteLength));function M(r){const o=b>>T;return r>o}function j(r){return M(r)?x(-r):r}const m=(r,o,i)=>a.bytesToNumberBE(r.slice(o,i));class e{constructor(o,i,f){this.r=o,this.s=i,this.recovery=f,this.assertValidity()}static fromCompact(o){const i=n.nByteLength;return o=a.ensureBytes("compactSignature",o,i*2),new e(m(o,0,i),m(o,i,2*i))}static fromDER(o){const{r:i,s:f}=Y.toSig(a.ensureBytes("DER",o));return new e(i,f)}assertValidity(){a.aInRange("r",this.r,T,b),a.aInRange("s",this.s,T,b)}addRecoveryBit(o){return new e(this.r,this.s,o)}recoverPublicKey(o){const{r:i,s:f,recovery:E}=this,A=g(a.ensureBytes("msgHash",o));if(E==null||![0,1,2,3].includes(E))throw new Error("recovery id invalid");const z=E===2||E===3?i+n.n:i;if(z>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");const q=E&1?"03":"02",I=R.fromHex(q+w(z)),U=V(z),H=x(-A*U),X=x(f*U),D=R.BASE.multiplyAndAddUnsafe(I,H,X);if(!D)throw new Error("point at infinify");return D.assertValidity(),D}hasHighS(){return M(this.s)}normalizeS(){return this.hasHighS()?new e(this.r,x(-this.s),this.recovery):this}toDERRawBytes(){return a.hexToBytes(this.toDERHex())}toDERHex(){return Y.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return a.hexToBytes(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}const s={isValidPrivateKey(r){try{return L(r),!0}catch{return!1}},normPrivateKeyToScalar:L,randomPrivateKey:()=>{const r=Q.getMinHashLength(n.n);return Q.mapHashToField(n.randomBytes(r),n.n)},precompute(r=8,o=R.BASE){return o._setWindowSize(r),o.multiply(BigInt(3)),o}};function c(r,o=!0){return R.fromPrivateKey(r).toRawBytes(o)}function d(r){const o=a.isBytes(r),i=typeof r=="string",f=(o||i)&&r.length;return o?f===O||f===Z:i?f===2*O||f===2*Z:r instanceof R}function p(r,o,i=!0){if(d(r))throw new Error("first arg must be private key");if(!d(o))throw new Error("second arg must be public key");return R.fromHex(o).multiply(L(r)).toRawBytes(i)}const v=n.bits2int||function(r){if(r.length>8192)throw new Error("input is too large");const o=a.bytesToNumberBE(r),i=r.length*8-n.nBitLength;return i>0?o>>BigInt(i):o},g=n.bits2int_modN||function(r){return x(v(r))},l=a.bitMask(n.nBitLength);function y(r){return a.aInRange("num < 2^"+n.nBitLength,r,C,l),a.numberToBytesBE(r,n.nByteLength)}function u(r,o,i=N){if(["recovered","canonical"].some(K=>K in i))throw new Error("sign() legacy options not supported");const{hash:f,randomBytes:E}=n;let{lowS:A,prehash:z,extraEntropy:q}=i;A==null&&(A=!0),r=a.ensureBytes("msgHash",r),ot(i),z&&(r=a.ensureBytes("prehashed msgHash",f(r)));const I=g(r),U=L(o),H=[y(U),y(I)];if(q!=null&&q!==!1){const K=q===!0?E(t.BYTES):q;H.push(a.ensureBytes("extraEntropy",K))}const X=a.concatBytes(...H),D=I;function nt(K){const W=v(K);if(!et(W))return;const rt=V(W),$=R.BASE.multiply(W).toAffine(),k=x($.x);if(k===C)return;const J=x(rt*x(D+k*U));if(J===C)return;let _=($.x===k?0:2)|Number($.y&T),G=J;return A&&M(J)&&(G=j(J),_^=1),new e(k,G,_)}return{seed:X,k2sig:nt}}const N={lowS:n.lowS,prehash:!1},S={lowS:n.lowS,prehash:!1};function B(r,o,i=N){const{seed:f,k2sig:E}=u(r,o,i),A=n;return a.createHmacDrbg(A.hash.outputLen,A.nByteLength,A.hmac)(f,E)}R.BASE._setWindowSize(8);function F(r,o,i,f=S){var _;const E=r;o=a.ensureBytes("msgHash",o),i=a.ensureBytes("publicKey",i);const{lowS:A,prehash:z,format:q}=f;if(ot(f),"strict"in f)throw new Error("options.strict was renamed to lowS");if(q!==void 0&&q!=="compact"&&q!=="der")throw new Error("format must be compact or der");const I=typeof E=="string"||a.isBytes(E),U=!I&&!q&&typeof E=="object"&&E!==null&&typeof E.r=="bigint"&&typeof E.s=="bigint";if(!I&&!U)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let H,X;try{if(U&&(H=new e(E.r,E.s)),I){try{q!=="compact"&&(H=e.fromDER(E))}catch(G){if(!(G instanceof Y.Err))throw G}!H&&q!=="der"&&(H=e.fromCompact(E))}X=R.fromHex(i)}catch{return!1}if(!H||A&&H.hasHighS())return!1;z&&(o=n.hash(o));const{r:D,s:nt}=H,K=g(o),W=V(nt),rt=x(K*W),$=x(D*W),k=(_=R.BASE.multiplyAndAddUnsafe(X,rt,$))==null?void 0:_.toAffine();return k?x(k.x)===D:!1}return{CURVE:n,getPublicKey:c,getSharedSecret:p,sign:B,verify:F,ProjectivePoint:R,Signature:e,utils:s}}exports.DER=Y;exports.DERErr=it;exports.weierstrass=ft;exports.weierstrassPoints=at;