@gardenfi/utils 2.0.4 → 2.0.5
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 +33 -24
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +24 -32
- package/dist/index100.cjs +1 -0
- package/dist/index100.js +9 -0
- package/dist/index101.cjs +2 -0
- package/dist/index101.js +5 -0
- package/dist/index102.cjs +1 -0
- package/dist/index102.js +115 -0
- package/dist/index103.cjs +1 -0
- package/dist/index103.js +81 -0
- package/dist/index104.cjs +1 -0
- package/dist/index104.js +4 -0
- package/dist/index105.cjs +1 -0
- package/dist/index105.js +20 -0
- package/dist/index106.cjs +1 -0
- package/dist/index106.js +21 -0
- package/dist/index107.cjs +1 -0
- package/dist/index107.js +19 -0
- package/dist/index108.cjs +1 -0
- package/dist/index108.js +226 -0
- package/dist/index109.cjs +1 -0
- package/dist/index109.js +37 -0
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +136 -14
- package/dist/index110.cjs +1 -0
- package/dist/index110.js +21 -0
- package/dist/index111.cjs +1 -0
- package/dist/index111.js +72 -0
- package/dist/index112.cjs +1 -0
- package/dist/index112.js +70 -0
- package/dist/index113.cjs +1 -0
- package/dist/index113.js +4 -0
- package/dist/index114.cjs +1 -0
- package/dist/index114.js +43 -0
- package/dist/index115.cjs +1 -0
- package/dist/index115.js +646 -0
- package/dist/index116.cjs +1 -0
- package/dist/index116.js +234 -0
- package/dist/index117.cjs +1 -0
- package/dist/index117.js +175 -0
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +9 -182
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +2 -94
- package/dist/index14.cjs +1 -16
- package/dist/index14.js +32 -112
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +18 -31
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +188 -31
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +93 -17
- package/dist/index18.cjs +1 -1
- package/dist/index18.js +35 -7
- package/dist/index19.cjs +1 -1
- package/dist/index19.js +31 -20
- package/dist/index20.cjs +16 -1
- package/dist/index20.js +113 -21
- package/dist/index21.cjs +1 -1
- package/dist/index21.js +31 -9
- package/dist/index22.cjs +1 -1
- package/dist/index22.js +17 -31
- package/dist/index23.cjs +1 -1
- package/dist/index23.js +7 -26
- package/dist/index24.cjs +1 -1
- package/dist/index24.js +41 -19
- package/dist/index25.cjs +1 -1
- package/dist/index25.js +19 -49
- package/dist/index26.cjs +1 -1
- package/dist/index26.js +8 -12
- package/dist/index27.cjs +1 -1
- package/dist/index27.js +30 -23
- package/dist/index28.cjs +1 -1
- package/dist/index28.js +25 -74
- package/dist/index29.cjs +2 -1
- package/dist/index29.js +62 -20
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +30 -7
- package/dist/index30.cjs +1 -1
- package/dist/index30.js +51 -7
- package/dist/index31.cjs +1 -1
- package/dist/index31.js +12 -32
- package/dist/index32.cjs +1 -1
- package/dist/index32.js +24 -15
- package/dist/index33.cjs +1 -1
- package/dist/index33.js +76 -2
- package/dist/index34.cjs +1 -1
- package/dist/index34.js +23 -8
- package/dist/index35.cjs +1 -1
- package/dist/index35.js +7 -20
- package/dist/index36.cjs +1 -1
- package/dist/index36.js +32 -12
- package/dist/index37.cjs +1 -1
- package/dist/index37.js +15 -34
- package/dist/index38.cjs +1 -2
- package/dist/index38.js +2 -60
- package/dist/index39.cjs +1 -1
- package/dist/index39.js +9 -2
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +2 -2
- package/dist/index40.cjs +1 -1
- package/dist/index40.js +20 -4
- package/dist/index41.cjs +1 -1
- package/dist/index41.js +12 -11
- package/dist/index42.cjs +1 -1
- package/dist/index42.js +34 -3
- package/dist/index43.cjs +2 -1
- package/dist/index43.js +58 -20
- package/dist/index44.cjs +1 -1
- package/dist/index44.js +2 -13
- package/dist/index45.cjs +1 -1
- package/dist/index45.js +5 -54
- package/dist/index46.cjs +1 -1
- package/dist/index46.js +6 -6
- package/dist/index47.cjs +1 -1
- package/dist/index47.js +4 -21
- package/dist/index48.cjs +1 -1
- package/dist/index48.js +11 -11
- package/dist/index49.cjs +5 -1
- package/dist/index49.js +56 -3
- package/dist/index50.cjs +1 -1
- package/dist/index50.js +3 -11
- package/dist/index51.cjs +2 -1
- package/dist/index51.js +33 -18
- package/dist/index52.cjs +1 -1
- package/dist/index52.js +5 -6
- package/dist/index53.cjs +1 -1
- package/dist/index53.js +21 -8
- package/dist/index54.cjs +1 -1
- package/dist/index54.js +11 -103
- package/dist/index55.cjs +1 -1
- package/dist/index55.js +51 -24
- package/dist/index56.cjs +1 -1
- package/dist/index56.js +8 -18
- package/dist/index57.cjs +1 -1
- package/dist/index57.js +20 -37
- package/dist/index58.cjs +1 -0
- package/dist/index58.js +14 -0
- package/dist/index59.cjs +1 -0
- package/dist/index59.js +11 -0
- package/dist/index60.cjs +1 -0
- package/dist/index60.js +13 -0
- package/dist/index61.cjs +1 -0
- package/dist/index61.js +14 -0
- package/dist/index62.cjs +1 -0
- package/dist/index62.js +9 -0
- package/dist/index63.cjs +1 -0
- package/dist/index63.js +16 -0
- package/dist/index64.cjs +1 -0
- package/dist/index64.js +35 -0
- package/dist/index65.cjs +1 -0
- package/dist/index65.js +17 -0
- package/dist/index66.cjs +1 -0
- package/dist/index66.js +67 -0
- package/dist/index67.cjs +1 -0
- package/dist/index67.js +30 -0
- package/dist/index68.cjs +1 -0
- package/dist/index68.js +5 -0
- package/dist/index69.cjs +1 -0
- package/dist/index69.js +8 -0
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +2 -109
- package/dist/index70.cjs +1 -0
- package/dist/index70.js +11 -0
- package/dist/index71.cjs +1 -0
- package/dist/index71.js +6 -0
- package/dist/index72.cjs +1 -0
- package/dist/index72.js +16 -0
- package/dist/index73.cjs +1 -0
- package/dist/index73.js +44 -0
- package/dist/index74.cjs +1 -0
- package/dist/index74.js +106 -0
- package/dist/index75.cjs +1 -0
- package/dist/index75.js +194 -0
- package/dist/index76.cjs +1 -0
- package/dist/index76.js +21 -0
- package/dist/index77.cjs +1 -0
- package/dist/index77.js +14 -0
- package/dist/index78.cjs +1 -0
- package/dist/index78.js +22 -0
- package/dist/index79.cjs +1 -0
- package/dist/index79.js +28 -0
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +95 -10
- package/dist/index80.cjs +1 -0
- package/dist/index80.js +9 -0
- package/dist/index81.cjs +1 -0
- package/dist/index81.js +16 -0
- package/dist/index82.cjs +1 -0
- package/dist/index82.js +18 -0
- package/dist/index83.cjs +1 -0
- package/dist/index83.js +8 -0
- package/dist/index84.cjs +1 -0
- package/dist/index84.js +16 -0
- package/dist/index85.cjs +1 -0
- package/dist/index85.js +13 -0
- package/dist/index86.cjs +1 -0
- package/dist/index86.js +19 -0
- package/dist/index87.cjs +1 -0
- package/dist/index87.js +174 -0
- package/dist/index88.cjs +1 -0
- package/dist/index88.js +11 -0
- package/dist/index89.cjs +1 -0
- package/dist/index89.js +15 -0
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +44 -2
- package/dist/index90.cjs +1 -0
- package/dist/index90.js +107 -0
- package/dist/index91.cjs +1 -0
- package/dist/index91.js +41 -0
- package/dist/index92.cjs +1 -0
- package/dist/index92.js +4 -0
- package/dist/index93.cjs +1 -0
- package/dist/index93.js +7 -0
- package/dist/index94.cjs +1 -0
- package/dist/index94.js +13 -0
- package/dist/index95.cjs +1 -0
- package/dist/index95.js +45 -0
- package/dist/index96.cjs +1 -0
- package/dist/index96.js +23 -0
- package/dist/index97.cjs +1 -0
- package/dist/index97.js +7 -0
- package/dist/index98.cjs +1 -0
- package/dist/index98.js +40 -0
- package/dist/index99.cjs +1 -0
- package/dist/index99.js +130 -0
- package/dist/src/lib/auth/apikey/apikey.d.ts +12 -0
- package/dist/src/lib/auth/auth.types.d.ts +21 -8
- package/dist/src/lib/auth/index.d.ts +5 -1
- package/dist/src/lib/auth/passkey/passkey.d.ts +10 -0
- package/dist/src/lib/auth/passkey/passkey.types.d.ts +17 -0
- package/dist/src/lib/auth/passkey/passkeyLogin.d.ts +37 -0
- package/dist/src/lib/auth/{siwe.d.ts → siwe/siwe.d.ts} +4 -15
- package/dist/src/lib/utils.d.ts +3 -0
- package/package.json +2 -1
package/dist/index96.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseError as o } from "./index43.js";
|
|
2
|
+
class i extends o {
|
|
3
|
+
constructor({ offset: e }) {
|
|
4
|
+
super(`Offset \`${e}\` cannot be negative.`, {
|
|
5
|
+
name: "NegativeOffsetError"
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class n extends o {
|
|
10
|
+
constructor({ length: e, position: r }) {
|
|
11
|
+
super(`Position \`${r}\` is out of bounds (\`0 < position < ${e}\`).`, { name: "PositionOutOfBoundsError" });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
class c extends o {
|
|
15
|
+
constructor({ count: e, limit: r }) {
|
|
16
|
+
super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${e}\`).`, { name: "RecursiveReadLimitExceededError" });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
i as NegativeOffsetError,
|
|
21
|
+
n as PositionOutOfBoundsError,
|
|
22
|
+
c as RecursiveReadLimitExceededError
|
|
23
|
+
};
|
package/dist/index97.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=6,s=32,e=4096,n=s*e,o=n*t-1-1*e*t;exports.bytesPerBlob=n;exports.bytesPerFieldElement=s;exports.fieldElementsPerBlob=e;exports.maxBytesPerTransaction=o;
|
package/dist/index97.js
ADDED
package/dist/index98.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index104.cjs"),s=require("./index43.cjs");class i extends s.BaseError{constructor({maxSize:e,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${e} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class n extends s.BaseError{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class t extends s.BaseError{constructor({hash:e,size:r}){super(`Versioned hash "${e}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class d extends s.BaseError{constructor({hash:e,version:r}){super(`Versioned hash "${e}" version is invalid.`,{metaMessages:[`Expected: ${a.versionedHashVersionKzg}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}exports.BlobSizeTooLargeError=i;exports.EmptyBlobError=n;exports.InvalidVersionedHashSizeError=t;exports.InvalidVersionedHashVersionError=d;
|
package/dist/index98.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { versionedHashVersionKzg as a } from "./index104.js";
|
|
2
|
+
import { BaseError as s } from "./index43.js";
|
|
3
|
+
class t extends s {
|
|
4
|
+
constructor({ maxSize: e, size: r }) {
|
|
5
|
+
super("Blob size is too large.", {
|
|
6
|
+
metaMessages: [`Max: ${e} bytes`, `Given: ${r} bytes`],
|
|
7
|
+
name: "BlobSizeTooLargeError"
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class d extends s {
|
|
12
|
+
constructor() {
|
|
13
|
+
super("Blob data must not be empty.", { name: "EmptyBlobError" });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
class l extends s {
|
|
17
|
+
constructor({ hash: e, size: r }) {
|
|
18
|
+
super(`Versioned hash "${e}" size is invalid.`, {
|
|
19
|
+
metaMessages: ["Expected: 32", `Received: ${r}`],
|
|
20
|
+
name: "InvalidVersionedHashSizeError"
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class c extends s {
|
|
25
|
+
constructor({ hash: e, version: r }) {
|
|
26
|
+
super(`Versioned hash "${e}" version is invalid.`, {
|
|
27
|
+
metaMessages: [
|
|
28
|
+
`Expected: ${a}`,
|
|
29
|
+
`Received: ${r}`
|
|
30
|
+
],
|
|
31
|
+
name: "InvalidVersionedHashVersionError"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
t as BlobSizeTooLargeError,
|
|
37
|
+
d as EmptyBlobError,
|
|
38
|
+
l as InvalidVersionedHashSizeError,
|
|
39
|
+
c as InvalidVersionedHashVersionError
|
|
40
|
+
};
|
package/dist/index99.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index96.cjs"),e={bytes:new Uint8Array,dataView:new DataView(new ArrayBuffer(0)),position:0,positionReadCount:new Map,recursiveReadCount:0,recursiveReadLimit:Number.POSITIVE_INFINITY,assertReadLimit(){if(this.recursiveReadCount>=this.recursiveReadLimit)throw new o.RecursiveReadLimitExceededError({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(t){if(t<0||t>this.bytes.length-1)throw new o.PositionOutOfBoundsError({length:this.bytes.length,position:t})},decrementPosition(t){if(t<0)throw new o.NegativeOffsetError({offset:t});const i=this.position-t;this.assertPosition(i),this.position=i},getReadCount(t){return this.positionReadCount.get(t||this.position)||0},incrementPosition(t){if(t<0)throw new o.NegativeOffsetError({offset:t});const i=this.position+t;this.assertPosition(i),this.position=i},inspectByte(t){const i=t??this.position;return this.assertPosition(i),this.bytes[i]},inspectBytes(t,i){const s=i??this.position;return this.assertPosition(s+t-1),this.bytes.subarray(s,s+t)},inspectUint8(t){const i=t??this.position;return this.assertPosition(i),this.bytes[i]},inspectUint16(t){const i=t??this.position;return this.assertPosition(i+1),this.dataView.getUint16(i)},inspectUint24(t){const i=t??this.position;return this.assertPosition(i+2),(this.dataView.getUint16(i)<<8)+this.dataView.getUint8(i+2)},inspectUint32(t){const i=t??this.position;return this.assertPosition(i+3),this.dataView.getUint32(i)},pushByte(t){this.assertPosition(this.position),this.bytes[this.position]=t,this.position++},pushBytes(t){this.assertPosition(this.position+t.length-1),this.bytes.set(t,this.position),this.position+=t.length},pushUint8(t){this.assertPosition(this.position),this.bytes[this.position]=t,this.position++},pushUint16(t){this.assertPosition(this.position+1),this.dataView.setUint16(this.position,t),this.position+=2},pushUint24(t){this.assertPosition(this.position+2),this.dataView.setUint16(this.position,t>>8),this.dataView.setUint8(this.position+2,t&255),this.position+=3},pushUint32(t){this.assertPosition(this.position+3),this.dataView.setUint32(this.position,t),this.position+=4},readByte(){this.assertReadLimit(),this._touch();const t=this.inspectByte();return this.position++,t},readBytes(t,i){this.assertReadLimit(),this._touch();const s=this.inspectBytes(t);return this.position+=i??t,s},readUint8(){this.assertReadLimit(),this._touch();const t=this.inspectUint8();return this.position+=1,t},readUint16(){this.assertReadLimit(),this._touch();const t=this.inspectUint16();return this.position+=2,t},readUint24(){this.assertReadLimit(),this._touch();const t=this.inspectUint24();return this.position+=3,t},readUint32(){this.assertReadLimit(),this._touch();const t=this.inspectUint32();return this.position+=4,t},get remaining(){return this.bytes.length-this.position},setPosition(t){const i=this.position;return this.assertPosition(t),this.position=t,()=>this.position=i},_touch(){if(this.recursiveReadLimit===Number.POSITIVE_INFINITY)return;const t=this.getReadCount();this.positionReadCount.set(this.position,t+1),t>0&&this.recursiveReadCount++}};function n(t,{recursiveReadLimit:i=8192}={}){const s=Object.create(e);return s.bytes=t,s.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength),s.positionReadCount=new Map,s.recursiveReadLimit=i,s}exports.createCursor=n;
|
package/dist/index99.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { RecursiveReadLimitExceededError as e, PositionOutOfBoundsError as n, NegativeOffsetError as o } from "./index96.js";
|
|
2
|
+
const h = {
|
|
3
|
+
bytes: new Uint8Array(),
|
|
4
|
+
dataView: new DataView(new ArrayBuffer(0)),
|
|
5
|
+
position: 0,
|
|
6
|
+
positionReadCount: /* @__PURE__ */ new Map(),
|
|
7
|
+
recursiveReadCount: 0,
|
|
8
|
+
recursiveReadLimit: Number.POSITIVE_INFINITY,
|
|
9
|
+
assertReadLimit() {
|
|
10
|
+
if (this.recursiveReadCount >= this.recursiveReadLimit)
|
|
11
|
+
throw new e({
|
|
12
|
+
count: this.recursiveReadCount + 1,
|
|
13
|
+
limit: this.recursiveReadLimit
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
assertPosition(t) {
|
|
17
|
+
if (t < 0 || t > this.bytes.length - 1)
|
|
18
|
+
throw new n({
|
|
19
|
+
length: this.bytes.length,
|
|
20
|
+
position: t
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
decrementPosition(t) {
|
|
24
|
+
if (t < 0)
|
|
25
|
+
throw new o({ offset: t });
|
|
26
|
+
const i = this.position - t;
|
|
27
|
+
this.assertPosition(i), this.position = i;
|
|
28
|
+
},
|
|
29
|
+
getReadCount(t) {
|
|
30
|
+
return this.positionReadCount.get(t || this.position) || 0;
|
|
31
|
+
},
|
|
32
|
+
incrementPosition(t) {
|
|
33
|
+
if (t < 0)
|
|
34
|
+
throw new o({ offset: t });
|
|
35
|
+
const i = this.position + t;
|
|
36
|
+
this.assertPosition(i), this.position = i;
|
|
37
|
+
},
|
|
38
|
+
inspectByte(t) {
|
|
39
|
+
const i = t ?? this.position;
|
|
40
|
+
return this.assertPosition(i), this.bytes[i];
|
|
41
|
+
},
|
|
42
|
+
inspectBytes(t, i) {
|
|
43
|
+
const s = i ?? this.position;
|
|
44
|
+
return this.assertPosition(s + t - 1), this.bytes.subarray(s, s + t);
|
|
45
|
+
},
|
|
46
|
+
inspectUint8(t) {
|
|
47
|
+
const i = t ?? this.position;
|
|
48
|
+
return this.assertPosition(i), this.bytes[i];
|
|
49
|
+
},
|
|
50
|
+
inspectUint16(t) {
|
|
51
|
+
const i = t ?? this.position;
|
|
52
|
+
return this.assertPosition(i + 1), this.dataView.getUint16(i);
|
|
53
|
+
},
|
|
54
|
+
inspectUint24(t) {
|
|
55
|
+
const i = t ?? this.position;
|
|
56
|
+
return this.assertPosition(i + 2), (this.dataView.getUint16(i) << 8) + this.dataView.getUint8(i + 2);
|
|
57
|
+
},
|
|
58
|
+
inspectUint32(t) {
|
|
59
|
+
const i = t ?? this.position;
|
|
60
|
+
return this.assertPosition(i + 3), this.dataView.getUint32(i);
|
|
61
|
+
},
|
|
62
|
+
pushByte(t) {
|
|
63
|
+
this.assertPosition(this.position), this.bytes[this.position] = t, this.position++;
|
|
64
|
+
},
|
|
65
|
+
pushBytes(t) {
|
|
66
|
+
this.assertPosition(this.position + t.length - 1), this.bytes.set(t, this.position), this.position += t.length;
|
|
67
|
+
},
|
|
68
|
+
pushUint8(t) {
|
|
69
|
+
this.assertPosition(this.position), this.bytes[this.position] = t, this.position++;
|
|
70
|
+
},
|
|
71
|
+
pushUint16(t) {
|
|
72
|
+
this.assertPosition(this.position + 1), this.dataView.setUint16(this.position, t), this.position += 2;
|
|
73
|
+
},
|
|
74
|
+
pushUint24(t) {
|
|
75
|
+
this.assertPosition(this.position + 2), this.dataView.setUint16(this.position, t >> 8), this.dataView.setUint8(this.position + 2, t & 255), this.position += 3;
|
|
76
|
+
},
|
|
77
|
+
pushUint32(t) {
|
|
78
|
+
this.assertPosition(this.position + 3), this.dataView.setUint32(this.position, t), this.position += 4;
|
|
79
|
+
},
|
|
80
|
+
readByte() {
|
|
81
|
+
this.assertReadLimit(), this._touch();
|
|
82
|
+
const t = this.inspectByte();
|
|
83
|
+
return this.position++, t;
|
|
84
|
+
},
|
|
85
|
+
readBytes(t, i) {
|
|
86
|
+
this.assertReadLimit(), this._touch();
|
|
87
|
+
const s = this.inspectBytes(t);
|
|
88
|
+
return this.position += i ?? t, s;
|
|
89
|
+
},
|
|
90
|
+
readUint8() {
|
|
91
|
+
this.assertReadLimit(), this._touch();
|
|
92
|
+
const t = this.inspectUint8();
|
|
93
|
+
return this.position += 1, t;
|
|
94
|
+
},
|
|
95
|
+
readUint16() {
|
|
96
|
+
this.assertReadLimit(), this._touch();
|
|
97
|
+
const t = this.inspectUint16();
|
|
98
|
+
return this.position += 2, t;
|
|
99
|
+
},
|
|
100
|
+
readUint24() {
|
|
101
|
+
this.assertReadLimit(), this._touch();
|
|
102
|
+
const t = this.inspectUint24();
|
|
103
|
+
return this.position += 3, t;
|
|
104
|
+
},
|
|
105
|
+
readUint32() {
|
|
106
|
+
this.assertReadLimit(), this._touch();
|
|
107
|
+
const t = this.inspectUint32();
|
|
108
|
+
return this.position += 4, t;
|
|
109
|
+
},
|
|
110
|
+
get remaining() {
|
|
111
|
+
return this.bytes.length - this.position;
|
|
112
|
+
},
|
|
113
|
+
setPosition(t) {
|
|
114
|
+
const i = this.position;
|
|
115
|
+
return this.assertPosition(t), this.position = t, () => this.position = i;
|
|
116
|
+
},
|
|
117
|
+
_touch() {
|
|
118
|
+
if (this.recursiveReadLimit === Number.POSITIVE_INFINITY)
|
|
119
|
+
return;
|
|
120
|
+
const t = this.getReadCount();
|
|
121
|
+
this.positionReadCount.set(this.position, t + 1), t > 0 && this.recursiveReadCount++;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
function a(t, { recursiveReadLimit: i = 8192 } = {}) {
|
|
125
|
+
const s = Object.create(h);
|
|
126
|
+
return s.bytes = t, s.dataView = new DataView(t.buffer, t.byteOffset, t.byteLength), s.positionReadCount = /* @__PURE__ */ new Map(), s.recursiveReadLimit = i, s;
|
|
127
|
+
}
|
|
128
|
+
export {
|
|
129
|
+
a as createCursor
|
|
130
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Result, AsyncResult } from '@catalogfi/utils';
|
|
2
|
+
import { AuthHeader, IAuth } from '../auth.types';
|
|
3
|
+
|
|
4
|
+
export declare class ApiKey implements IAuth {
|
|
5
|
+
private readonly apiKey;
|
|
6
|
+
constructor(apiKey: string);
|
|
7
|
+
getToken(): AsyncResult<string, string>;
|
|
8
|
+
verifyToken(): Result<boolean, string>;
|
|
9
|
+
private decodeBase64UrlSafe;
|
|
10
|
+
private extractData;
|
|
11
|
+
getAuthHeaders(): AsyncResult<AuthHeader, string>;
|
|
12
|
+
}
|
|
@@ -6,15 +6,28 @@ export type SiweOpts = {
|
|
|
6
6
|
store?: IStore;
|
|
7
7
|
signingStatement?: string;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export interface ISiwe {
|
|
13
|
-
getToken(): AsyncResult<string, string>;
|
|
14
|
-
verifyToken(token: string, account: string): Result<boolean, string>;
|
|
9
|
+
export declare enum AuthHeaderEnum {
|
|
10
|
+
Authorization = "Authorization",
|
|
11
|
+
ApiKey = "api-key"
|
|
15
12
|
}
|
|
13
|
+
export type AuthHeader = Record<AuthHeaderEnum.ApiKey, string> | Record<AuthHeaderEnum.Authorization, string>;
|
|
16
14
|
export interface IAuth {
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Get a token from store if available or fetch from the wallet
|
|
17
|
+
* @returns verified token
|
|
18
|
+
*/
|
|
19
|
+
getToken(): AsyncResult<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Verify the token expiry and account
|
|
22
|
+
* @param token The token to verify
|
|
23
|
+
* @param account The account to verify the token against
|
|
24
|
+
*/
|
|
25
|
+
verifyToken(token: string, account: string): Result<boolean, string>;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves the authentication token and formats it into the appropriate header object.
|
|
28
|
+
* Example: For API keys, returns { 'api-key': apiKey }
|
|
29
|
+
* Example: For SIWE, returns { Authorization: 'Bearer token' }
|
|
30
|
+
* @returns An AsyncResult containing the formatted auth header object or an error message
|
|
31
|
+
*/
|
|
19
32
|
getAuthHeaders(): AsyncResult<AuthHeader, string>;
|
|
20
33
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Result, AsyncResult } from '@catalogfi/utils';
|
|
2
|
+
import { AuthHeader, IAuth } from '../auth.types';
|
|
3
|
+
|
|
4
|
+
export declare class Passkey implements IAuth {
|
|
5
|
+
private token;
|
|
6
|
+
constructor(token: string);
|
|
7
|
+
getToken(): AsyncResult<string, string>;
|
|
8
|
+
verifyToken(token: string): Result<boolean, string>;
|
|
9
|
+
getAuthHeaders(): AsyncResult<AuthHeader, string>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PublicKeyCredentialCreationOptionsJSON } from '@simplewebauthn/browser';
|
|
2
|
+
|
|
3
|
+
export type PasskeyToken = {
|
|
4
|
+
token: string;
|
|
5
|
+
gardenUserName: string;
|
|
6
|
+
};
|
|
7
|
+
export type RegisterChallenge = {
|
|
8
|
+
challenge: {
|
|
9
|
+
publicKey: PublicKeyCredentialCreationOptionsJSON;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export type ConditionalLoginChallenge = {
|
|
13
|
+
challenge: {
|
|
14
|
+
publicKey: PublicKeyCredentialCreationOptionsJSON;
|
|
15
|
+
};
|
|
16
|
+
login_id: string;
|
|
17
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AsyncResult, Result } from '@catalogfi/utils';
|
|
2
|
+
import { Url } from 'src/lib/url';
|
|
3
|
+
import { PasskeyToken } from './passkey.types';
|
|
4
|
+
import { IStore } from 'src/lib/store';
|
|
5
|
+
|
|
6
|
+
export declare class PasskeyLogin {
|
|
7
|
+
private url;
|
|
8
|
+
private store;
|
|
9
|
+
private storeKey;
|
|
10
|
+
private token;
|
|
11
|
+
private userName;
|
|
12
|
+
constructor(url: Url, store: IStore);
|
|
13
|
+
getPasskeyFromStore(): Result<PasskeyToken, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Validates the username according to predefined rules.
|
|
16
|
+
* @param username The username to validate.
|
|
17
|
+
* @returns Result<string, string> - Ok if valid, Err with message if invalid.
|
|
18
|
+
*/
|
|
19
|
+
private validateUsername;
|
|
20
|
+
/**
|
|
21
|
+
* Handles user registration using WebAuthn passkeys.
|
|
22
|
+
* @param username The username to register.
|
|
23
|
+
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
24
|
+
*/
|
|
25
|
+
register(username: string): AsyncResult<PasskeyToken, string>;
|
|
26
|
+
/**
|
|
27
|
+
* Handles user login using WebAuthn passkeys.
|
|
28
|
+
* @param username The username to log in.
|
|
29
|
+
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
30
|
+
*/
|
|
31
|
+
login(username: string): AsyncResult<PasskeyToken, string>;
|
|
32
|
+
/**
|
|
33
|
+
* Handles conditional login (without username) for existing users.
|
|
34
|
+
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
35
|
+
*/
|
|
36
|
+
conditionalLogin(): AsyncResult<PasskeyToken, string>;
|
|
37
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AuthHeader, IAuth,
|
|
1
|
+
import { AuthHeader, IAuth, SiweOpts } from '../auth.types';
|
|
2
2
|
import { AsyncResult, Result } from '@catalogfi/utils';
|
|
3
|
-
import { Url } from '
|
|
3
|
+
import { Url } from '../../url';
|
|
4
4
|
import { WalletClient } from 'viem';
|
|
5
5
|
|
|
6
|
-
export declare class Siwe implements
|
|
6
|
+
export declare class Siwe implements IAuth {
|
|
7
7
|
private readonly API;
|
|
8
8
|
private readonly url;
|
|
9
9
|
private store;
|
|
@@ -11,20 +11,9 @@ export declare class Siwe implements ISiwe {
|
|
|
11
11
|
private readonly signingStatement;
|
|
12
12
|
private readonly domain;
|
|
13
13
|
constructor(url: Url, walletClient: WalletClient, opts?: SiweOpts);
|
|
14
|
+
static fromDigestKey(url: Url, digestKey: string): Siwe;
|
|
14
15
|
verifyToken(token: string, account: string): Result<boolean, string>;
|
|
15
16
|
getToken(): AsyncResult<string, string>;
|
|
16
17
|
private signStatement;
|
|
17
|
-
}
|
|
18
|
-
export declare const parseJwt: (token: string) => {
|
|
19
|
-
user_id: string;
|
|
20
|
-
exp: number;
|
|
21
|
-
} | undefined;
|
|
22
|
-
export declare class Auth implements IAuth {
|
|
23
|
-
siwe?: ISiwe;
|
|
24
|
-
apiKey?: string;
|
|
25
|
-
constructor(opts: {
|
|
26
|
-
siwe?: ISiwe;
|
|
27
|
-
apiKey?: string;
|
|
28
|
-
});
|
|
29
18
|
getAuthHeaders(): AsyncResult<AuthHeader, string>;
|
|
30
19
|
}
|
package/dist/src/lib/utils.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare const with0x: (str: string) => `0x${string}`;
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const Authorization: (authToken: string) => string;
|
|
8
8
|
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
9
|
+
export declare const parseJwt: <T>(token: string) => T | undefined;
|
|
9
10
|
export declare enum Network {
|
|
10
11
|
MAINNET = "mainnet",
|
|
11
12
|
TESTNET = "testnet"
|
|
@@ -15,3 +16,5 @@ export declare enum Environment {
|
|
|
15
16
|
TESTNET = "testnet",
|
|
16
17
|
LOCALNET = "localnet"
|
|
17
18
|
}
|
|
19
|
+
export declare const add0x: (str: string) => `0x${string}`;
|
|
20
|
+
export declare function hexToU32Array(hexString: string, endian?: 'big' | 'little'): number[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vite build",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"sideEffects": false,
|
|
37
37
|
"dependencies": {
|
|
38
|
+
"@simplewebauthn/browser": "^13.1.0",
|
|
38
39
|
"jwt-decode": "^4.0.0",
|
|
39
40
|
"viem": "^2.21.23"
|
|
40
41
|
}
|