@gardenfi/utils 2.0.3 → 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 +35 -21
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +21 -14
- 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 +126 -173
- 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 +14 -93
- package/dist/index13.cjs +1 -16
- package/dist/index13.js +2 -114
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +33 -31
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +19 -31
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +187 -17
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +93 -7
- package/dist/index18.cjs +1 -1
- package/dist/index18.js +35 -20
- package/dist/index19.cjs +1 -1
- package/dist/index19.js +32 -22
- package/dist/index20.cjs +16 -1
- package/dist/index20.js +113 -8
- package/dist/index21.cjs +1 -1
- package/dist/index21.js +30 -31
- package/dist/index22.cjs +1 -1
- package/dist/index22.js +17 -26
- package/dist/index23.cjs +1 -1
- package/dist/index23.js +6 -22
- package/dist/index24.cjs +1 -1
- package/dist/index24.js +44 -50
- package/dist/index25.cjs +1 -1
- package/dist/index25.js +21 -12
- package/dist/index26.cjs +1 -1
- package/dist/index26.js +8 -24
- package/dist/index27.cjs +1 -1
- package/dist/index27.js +31 -75
- package/dist/index28.cjs +1 -1
- package/dist/index28.js +25 -22
- package/dist/index29.cjs +2 -1
- package/dist/index29.js +65 -7
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +30 -7
- package/dist/index30.cjs +1 -1
- package/dist/index30.js +51 -32
- package/dist/index31.cjs +1 -1
- package/dist/index31.js +12 -15
- package/dist/index32.cjs +1 -1
- package/dist/index32.js +25 -2
- package/dist/index33.cjs +1 -1
- package/dist/index33.js +75 -8
- package/dist/index34.cjs +1 -1
- package/dist/index34.js +23 -20
- package/dist/index35.cjs +1 -1
- package/dist/index35.js +7 -12
- package/dist/index36.cjs +1 -1
- package/dist/index36.js +32 -34
- package/dist/index37.cjs +1 -2
- package/dist/index37.js +15 -59
- package/dist/index38.cjs +1 -1
- package/dist/index38.js +2 -2
- package/dist/index39.cjs +1 -1
- package/dist/index39.js +8 -4
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +2 -2
- package/dist/index40.cjs +1 -1
- package/dist/index40.js +20 -11
- package/dist/index41.cjs +1 -1
- package/dist/index41.js +12 -3
- package/dist/index42.cjs +1 -1
- package/dist/index42.js +33 -20
- package/dist/index43.cjs +2 -1
- package/dist/index43.js +58 -11
- package/dist/index44.cjs +1 -1
- package/dist/index44.js +2 -56
- package/dist/index45.cjs +1 -1
- package/dist/index45.js +6 -6
- package/dist/index46.cjs +1 -1
- package/dist/index46.js +6 -21
- package/dist/index47.cjs +1 -1
- package/dist/index47.js +4 -11
- package/dist/index48.cjs +1 -1
- package/dist/index48.js +11 -3
- package/dist/index49.cjs +5 -1
- package/dist/index49.js +53 -8
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +43 -19
- package/dist/index50.cjs +1 -1
- package/dist/index50.js +3 -19
- package/dist/index51.cjs +2 -1
- package/dist/index51.js +33 -5
- package/dist/index52.cjs +1 -1
- package/dist/index52.js +5 -8
- package/dist/index53.cjs +1 -1
- package/dist/index53.js +20 -103
- package/dist/index54.cjs +1 -1
- package/dist/index54.js +12 -28
- package/dist/index55.cjs +1 -1
- package/dist/index55.js +53 -16
- package/dist/index56.cjs +1 -1
- package/dist/index56.js +8 -38
- package/dist/index57.cjs +1 -0
- package/dist/index57.js +24 -0
- 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/index6.cjs +1 -1
- package/dist/index6.js +19 -104
- 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 -15
- 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 +100 -2
- 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 +42 -32
- 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/index.d.ts +1 -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/result.d.ts +16 -0
- package/dist/src/lib/utils.d.ts +3 -0
- package/package.json +2 -1
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
|
+
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -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
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class Result<T, E> {
|
|
2
|
+
#private;
|
|
3
|
+
constructor(ok: boolean, val: T, error?: E | undefined);
|
|
4
|
+
get ok(): boolean;
|
|
5
|
+
get error(): E | undefined;
|
|
6
|
+
get val(): T;
|
|
7
|
+
}
|
|
8
|
+
export type AsyncResult<T, E> = Promise<Result<T, E>>;
|
|
9
|
+
export declare const Ok: <T>(val: T) => Result<T, never>;
|
|
10
|
+
export declare const Void: undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Constructs an error result with the given error value.
|
|
13
|
+
*
|
|
14
|
+
* If the error value is a string, it can be followed by any number of optional messages which will be concatenated
|
|
15
|
+
*/
|
|
16
|
+
export declare const Err: <E>(error: E, ...optionalMsg: (E extends string ? any : never)[]) => Result<never, E>;
|
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
|
}
|