@nucypher/taco-auth 0.1.0 → 0.3.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/auth-provider.d.ts +0 -8
- package/dist/cjs/auth-provider.js +0 -6
- package/dist/cjs/auth-provider.js.map +1 -1
- package/dist/cjs/auth-sig.js +3 -4
- package/dist/cjs/auth-sig.js.map +1 -1
- package/dist/cjs/providers/eip4361/common.d.ts +3 -0
- package/dist/cjs/providers/eip4361/common.js +19 -0
- package/dist/cjs/providers/eip4361/common.js.map +1 -0
- package/dist/cjs/providers/eip4361/eip4361.d.ts +18 -0
- package/dist/cjs/providers/eip4361/eip4361.js +91 -0
- package/dist/cjs/providers/eip4361/eip4361.js.map +1 -0
- package/dist/cjs/providers/eip4361/external-eip4361.d.ts +10 -0
- package/dist/cjs/providers/eip4361/external-eip4361.js +35 -0
- package/dist/cjs/providers/eip4361/external-eip4361.js.map +1 -0
- package/dist/cjs/providers/index.d.ts +2 -2
- package/dist/cjs/providers/index.js +2 -2
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/storage.d.ts +1 -0
- package/dist/cjs/storage.js +9 -0
- package/dist/cjs/storage.js.map +1 -1
- package/dist/es/auth-provider.d.ts +0 -8
- package/dist/es/auth-provider.js +1 -5
- package/dist/es/auth-provider.js.map +1 -1
- package/dist/es/auth-sig.js +1 -2
- package/dist/es/auth-sig.js.map +1 -1
- package/dist/es/providers/eip4361/common.d.ts +3 -0
- package/dist/es/providers/eip4361/common.js +16 -0
- package/dist/es/providers/eip4361/common.js.map +1 -0
- package/dist/es/providers/eip4361/eip4361.d.ts +18 -0
- package/dist/es/providers/eip4361/eip4361.js +87 -0
- package/dist/es/providers/eip4361/eip4361.js.map +1 -0
- package/dist/es/providers/eip4361/external-eip4361.d.ts +10 -0
- package/dist/es/providers/eip4361/external-eip4361.js +31 -0
- package/dist/es/providers/eip4361/external-eip4361.js.map +1 -0
- package/dist/es/providers/index.d.ts +2 -2
- package/dist/es/providers/index.js +2 -2
- package/dist/es/providers/index.js.map +1 -1
- package/dist/es/storage.d.ts +1 -0
- package/dist/es/storage.js +9 -0
- package/dist/es/storage.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.es.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import { AuthSignature } from './auth-sig';
|
|
2
|
-
import { EIP4361AuthProvider } from './providers';
|
|
3
|
-
export declare const EIP4361_AUTH_METHOD = "EIP4361";
|
|
4
2
|
export interface AuthProvider {
|
|
5
3
|
getOrCreateAuthSignature(): Promise<AuthSignature>;
|
|
6
4
|
}
|
|
7
|
-
export type AuthProviders = {
|
|
8
|
-
[EIP4361_AUTH_METHOD]?: EIP4361AuthProvider;
|
|
9
|
-
[key: string]: AuthProvider | undefined;
|
|
10
|
-
};
|
|
11
|
-
export declare const USER_ADDRESS_PARAM_DEFAULT = ":userAddress";
|
|
12
|
-
export declare const AUTH_METHOD_FOR_PARAM: Record<string, string>;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AUTH_METHOD_FOR_PARAM = exports.USER_ADDRESS_PARAM_DEFAULT = exports.EIP4361_AUTH_METHOD = void 0;
|
|
4
|
-
exports.EIP4361_AUTH_METHOD = 'EIP4361';
|
|
5
|
-
exports.USER_ADDRESS_PARAM_DEFAULT = ':userAddress';
|
|
6
|
-
exports.AUTH_METHOD_FOR_PARAM = {
|
|
7
|
-
[exports.USER_ADDRESS_PARAM_DEFAULT]: exports.EIP4361_AUTH_METHOD,
|
|
8
|
-
};
|
|
9
3
|
//# sourceMappingURL=auth-provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-provider.js","sourceRoot":"","sources":["../../src/auth-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth-provider.js","sourceRoot":"","sources":["../../src/auth-provider.ts"],"names":[],"mappings":""}
|
package/dist/cjs/auth-sig.js
CHANGED
|
@@ -3,12 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.authSignatureSchema = void 0;
|
|
4
4
|
const shared_1 = require("@nucypher/shared");
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
|
-
const
|
|
7
|
-
const providers_1 = require("./providers");
|
|
6
|
+
const common_1 = require("./providers/eip4361/common");
|
|
8
7
|
exports.authSignatureSchema = zod_1.z.object({
|
|
9
8
|
signature: zod_1.z.string(),
|
|
10
9
|
address: shared_1.EthAddressSchema,
|
|
11
|
-
scheme: zod_1.z.enum([
|
|
12
|
-
typedData:
|
|
10
|
+
scheme: zod_1.z.enum([common_1.EIP4361_AUTH_METHOD]),
|
|
11
|
+
typedData: common_1.EIP4361TypedDataSchema,
|
|
13
12
|
});
|
|
14
13
|
//# sourceMappingURL=auth-sig.js.map
|
package/dist/cjs/auth-sig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-sig.js","sourceRoot":"","sources":["../../src/auth-sig.ts"],"names":[],"mappings":";;;AAAA,6CAAoD;AACpD,6BAAwB;AAExB,
|
|
1
|
+
{"version":3,"file":"auth-sig.js","sourceRoot":"","sources":["../../src/auth-sig.ts"],"names":[],"mappings":";;;AAAA,6CAAoD;AACpD,6BAAwB;AAExB,uDAGoC;AAEvB,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC1C,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;IACrB,OAAO,EAAE,yBAAgB;IACzB,MAAM,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,4BAAmB,CAAC,CAAC;IACrC,SAAS,EAAE,+BAAsB;CAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EIP4361TypedDataSchema = exports.EIP4361_AUTH_METHOD = void 0;
|
|
4
|
+
const siwe_1 = require("siwe");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
exports.EIP4361_AUTH_METHOD = 'EIP4361';
|
|
7
|
+
const isSiweMessage = (message) => {
|
|
8
|
+
try {
|
|
9
|
+
new siwe_1.SiweMessage(message);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
exports.EIP4361TypedDataSchema = zod_1.z
|
|
17
|
+
.string()
|
|
18
|
+
.refine(isSiweMessage, { message: 'Invalid SIWE message' });
|
|
19
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../src/providers/eip4361/common.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AACnC,6BAAwB;AAEX,QAAA,mBAAmB,GAAG,SAAS,CAAC;AAE7C,MAAM,aAAa,GAAG,CAAC,OAAe,EAAW,EAAE;IACjD,IAAI,CAAC;QACH,IAAI,kBAAW,CAAC,OAAO,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AAEW,QAAA,sBAAsB,GAAG,OAAC;KACpC,MAAM,EAAE;KACR,MAAM,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { AuthSignature } from '../../auth-sig';
|
|
3
|
+
export declare const USER_ADDRESS_PARAM_DEFAULT = ":userAddress";
|
|
4
|
+
export type EIP4361AuthProviderParams = {
|
|
5
|
+
domain: string;
|
|
6
|
+
uri: string;
|
|
7
|
+
};
|
|
8
|
+
export declare class EIP4361AuthProvider {
|
|
9
|
+
private readonly provider;
|
|
10
|
+
private readonly signer;
|
|
11
|
+
private readonly storage;
|
|
12
|
+
private readonly providerParams;
|
|
13
|
+
constructor(provider: ethers.providers.Provider, signer: ethers.Signer, providerParams?: EIP4361AuthProviderParams);
|
|
14
|
+
private getDefaultParameters;
|
|
15
|
+
getOrCreateAuthSignature(): Promise<AuthSignature>;
|
|
16
|
+
private isMessageExpired;
|
|
17
|
+
private createSIWEAuthMessage;
|
|
18
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EIP4361AuthProvider = exports.USER_ADDRESS_PARAM_DEFAULT = void 0;
|
|
4
|
+
const siwe_1 = require("siwe");
|
|
5
|
+
const storage_1 = require("../../storage");
|
|
6
|
+
const common_1 = require("./common");
|
|
7
|
+
exports.USER_ADDRESS_PARAM_DEFAULT = ':userAddress';
|
|
8
|
+
const ERR_MISSING_SIWE_PARAMETERS = 'Missing default SIWE parameters';
|
|
9
|
+
class EIP4361AuthProvider {
|
|
10
|
+
provider;
|
|
11
|
+
signer;
|
|
12
|
+
storage;
|
|
13
|
+
providerParams;
|
|
14
|
+
constructor(
|
|
15
|
+
// TODO: We only need the provider to fetch the chainId, consider removing it
|
|
16
|
+
provider, signer, providerParams) {
|
|
17
|
+
this.provider = provider;
|
|
18
|
+
this.signer = signer;
|
|
19
|
+
this.storage = new storage_1.LocalStorage();
|
|
20
|
+
if (providerParams) {
|
|
21
|
+
this.providerParams = providerParams;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.providerParams = this.getDefaultParameters();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
getDefaultParameters() {
|
|
28
|
+
if (typeof window !== 'undefined') {
|
|
29
|
+
// If we are in a browser environment, we can get the domain and uri from the window object
|
|
30
|
+
return {
|
|
31
|
+
domain: window.location?.host,
|
|
32
|
+
uri: window.location?.origin,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// If not, we have no choice but to throw an error
|
|
36
|
+
throw new Error(ERR_MISSING_SIWE_PARAMETERS);
|
|
37
|
+
}
|
|
38
|
+
async getOrCreateAuthSignature() {
|
|
39
|
+
const address = await this.signer.getAddress();
|
|
40
|
+
const storageKey = `eth-${common_1.EIP4361_AUTH_METHOD}-message-${address}`;
|
|
41
|
+
// If we have a signature in localStorage, return it
|
|
42
|
+
const maybeSignature = this.storage.getAuthSignature(storageKey);
|
|
43
|
+
if (maybeSignature) {
|
|
44
|
+
// check whether older than node freshness requirement
|
|
45
|
+
if (this.isMessageExpired(maybeSignature.typedData)) {
|
|
46
|
+
// clear signature so that it will be recreated and stored
|
|
47
|
+
this.storage.clear(storageKey);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return maybeSignature;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// If at this point we didn't return, we need to create a new message
|
|
54
|
+
const authMessage = await this.createSIWEAuthMessage();
|
|
55
|
+
this.storage.setAuthSignature(storageKey, authMessage);
|
|
56
|
+
return authMessage;
|
|
57
|
+
}
|
|
58
|
+
isMessageExpired(message) {
|
|
59
|
+
const siweMessage = new siwe_1.SiweMessage(message);
|
|
60
|
+
if (!siweMessage.issuedAt) {
|
|
61
|
+
// don't expect to ever happen; but just in case
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const twoHourWindow = new Date(siweMessage.issuedAt);
|
|
65
|
+
twoHourWindow.setHours(twoHourWindow.getHours() + 2);
|
|
66
|
+
const now = new Date();
|
|
67
|
+
return twoHourWindow < now;
|
|
68
|
+
}
|
|
69
|
+
async createSIWEAuthMessage() {
|
|
70
|
+
const address = await this.signer.getAddress();
|
|
71
|
+
const { domain, uri } = this.providerParams;
|
|
72
|
+
const version = '1';
|
|
73
|
+
const nonce = (0, siwe_1.generateNonce)();
|
|
74
|
+
const chainId = (await this.provider.getNetwork()).chainId;
|
|
75
|
+
const siweMessage = new siwe_1.SiweMessage({
|
|
76
|
+
domain,
|
|
77
|
+
address,
|
|
78
|
+
statement: `${domain} wants you to sign in with your Ethereum account: ${address}`,
|
|
79
|
+
uri,
|
|
80
|
+
version,
|
|
81
|
+
nonce,
|
|
82
|
+
chainId,
|
|
83
|
+
});
|
|
84
|
+
const scheme = common_1.EIP4361_AUTH_METHOD;
|
|
85
|
+
const message = siweMessage.prepareMessage();
|
|
86
|
+
const signature = await this.signer.signMessage(message);
|
|
87
|
+
return { signature, address, scheme, typedData: message };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.EIP4361AuthProvider = EIP4361AuthProvider;
|
|
91
|
+
//# sourceMappingURL=eip4361.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip4361.js","sourceRoot":"","sources":["../../../../src/providers/eip4361/eip4361.ts"],"names":[],"mappings":";;;AACA,+BAAkD;AAGlD,2CAA6C;AAE7C,qCAA+C;AAElC,QAAA,0BAA0B,GAAG,cAAc,CAAC;AAOzD,MAAM,2BAA2B,GAAG,iCAAiC,CAAC;AAEtE,MAAa,mBAAmB;IAMX;IACA;IANF,OAAO,CAAe;IACtB,cAAc,CAA4B;IAE3D;IACE,6EAA6E;IAC5D,QAAmC,EACnC,MAAqB,EACtC,cAA0C;QAFzB,aAAQ,GAAR,QAAQ,CAA2B;QACnC,WAAM,GAAN,MAAM,CAAe;QAGtC,IAAI,CAAC,OAAO,GAAG,IAAI,sBAAY,EAAE,CAAC;QAClC,IAAI,cAAc,EAAE,CAAC;YACnB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACvC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACpD,CAAC;IACH,CAAC;IAEO,oBAAoB;QAC1B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,2FAA2F;YAC3F,OAAO;gB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,GAAG,CAAC,CAAC,CAAC;QACrD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,OAAO,aAAa,GAAG,GAAG,CAAC;IAC7B,CAAC;IAEO,KAAK,CAAC,qBAAqB;QACjC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QAC/C,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC;QAC5C,MAAM,OAAO,GAAG,GAAG,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,oBAAa,GAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC;QAC3D,MAAM,WAAW,GAAG,IAAI,kBAAW,CAAC;YAClC,MAAM;YACN,OAAO;YACP,SAAS,EAAE,GAAG,MAAM,qDAAqD,OAAO,EAAE;YAClF,GAAG;YACH,OAAO;YACP,KAAK;YACL,OAAO;SACR,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,4BAAmB,CAAC;QACnC,MAAM,OAAO,GAAG,WAAW,CAAC,cAAc,EAAE,CAAC;QAC7C,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACzD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;IAC5D,CAAC;CACF;AArFD,kDAqFC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthSignature } from '../../auth-sig';
|
|
2
|
+
export declare const USER_ADDRESS_PARAM_EXTERNAL_EIP4361 = ":userAddressExternalEIP4361";
|
|
3
|
+
export declare class SingleSignOnEIP4361AuthProvider {
|
|
4
|
+
private readonly existingSiweMessage;
|
|
5
|
+
readonly address: string;
|
|
6
|
+
private readonly signature;
|
|
7
|
+
static fromExistingSiweInfo(existingSiweMessage: string, signature: string): Promise<SingleSignOnEIP4361AuthProvider>;
|
|
8
|
+
private constructor();
|
|
9
|
+
getOrCreateAuthSignature(): Promise<AuthSignature>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SingleSignOnEIP4361AuthProvider = exports.USER_ADDRESS_PARAM_EXTERNAL_EIP4361 = void 0;
|
|
4
|
+
const siwe_1 = require("siwe");
|
|
5
|
+
const common_1 = require("./common");
|
|
6
|
+
exports.USER_ADDRESS_PARAM_EXTERNAL_EIP4361 = ':userAddressExternalEIP4361';
|
|
7
|
+
class SingleSignOnEIP4361AuthProvider {
|
|
8
|
+
existingSiweMessage;
|
|
9
|
+
address;
|
|
10
|
+
signature;
|
|
11
|
+
static async fromExistingSiweInfo(existingSiweMessage, signature) {
|
|
12
|
+
// validation
|
|
13
|
+
const siweMessage = new siwe_1.SiweMessage(existingSiweMessage);
|
|
14
|
+
await siweMessage.verify({ signature });
|
|
15
|
+
// create provider
|
|
16
|
+
const authProvider = new SingleSignOnEIP4361AuthProvider(siweMessage.prepareMessage(), siweMessage.address, signature);
|
|
17
|
+
return authProvider;
|
|
18
|
+
}
|
|
19
|
+
constructor(existingSiweMessage, address, signature) {
|
|
20
|
+
this.existingSiweMessage = existingSiweMessage;
|
|
21
|
+
this.address = address;
|
|
22
|
+
this.signature = signature;
|
|
23
|
+
}
|
|
24
|
+
async getOrCreateAuthSignature() {
|
|
25
|
+
const scheme = common_1.EIP4361_AUTH_METHOD;
|
|
26
|
+
return {
|
|
27
|
+
signature: this.signature,
|
|
28
|
+
address: this.address,
|
|
29
|
+
scheme,
|
|
30
|
+
typedData: this.existingSiweMessage,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.SingleSignOnEIP4361AuthProvider = SingleSignOnEIP4361AuthProvider;
|
|
35
|
+
//# sourceMappingURL=external-eip4361.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-eip4361.js","sourceRoot":"","sources":["../../../../src/providers/eip4361/external-eip4361.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AAInC,qCAA+C;AAElC,QAAA,mCAAmC,GAC9C,6BAA6B,CAAC;AAEhC,MAAa,+BAA+B;IAkBvB;IACD;IACC;IAnBZ,MAAM,CAAC,KAAK,CAAC,oBAAoB,CACtC,mBAA2B,EAC3B,SAAiB;QAEjB,aAAa;QACb,MAAM,WAAW,GAAG,IAAI,kBAAW,CAAC,mBAAmB,CAAC,CAAC;QACzD,MAAM,WAAW,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;QACxC,kBAAkB;QAClB,MAAM,YAAY,GAAG,IAAI,+BAA+B,CACtD,WAAW,CAAC,cAAc,EAAE,EAC5B,WAAW,CAAC,OAAO,EACnB,SAAS,CACV,CAAC;QACF,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,YACmB,mBAA2B,EAC5B,OAAe,EACd,SAAiB;QAFjB,wBAAmB,GAAnB,mBAAmB,CAAQ;QAC5B,YAAO,GAAP,OAAO,CAAQ;QACd,cAAS,GAAT,SAAS,CAAQ;IACjC,CAAC;IAEG,KAAK,CAAC,wBAAwB;QACnC,MAAM,MAAM,GAAG,4BAAmB,CAAC;QACnC,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM;YACN,SAAS,EAAE,IAAI,CAAC,mBAAmB;SACpC,CAAC;IACJ,CAAC;CACF;AAhCD,0EAgCC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './eip4361';
|
|
2
|
-
export * from './external-eip4361';
|
|
1
|
+
export * from './eip4361/eip4361';
|
|
2
|
+
export * from './eip4361/external-eip4361';
|
|
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./eip4361"), exports);
|
|
18
|
-
__exportStar(require("./external-eip4361"), exports);
|
|
17
|
+
__exportStar(require("./eip4361/eip4361"), exports);
|
|
18
|
+
__exportStar(require("./eip4361/external-eip4361"), exports);
|
|
19
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,6DAA2C"}
|
package/dist/cjs/storage.d.ts
CHANGED
package/dist/cjs/storage.js
CHANGED
|
@@ -9,6 +9,9 @@ class BrowserStorage {
|
|
|
9
9
|
setItem(key, value) {
|
|
10
10
|
localStorage.setItem(key, value);
|
|
11
11
|
}
|
|
12
|
+
removeItem(key) {
|
|
13
|
+
localStorage.removeItem(key);
|
|
14
|
+
}
|
|
12
15
|
}
|
|
13
16
|
class NodeStorage {
|
|
14
17
|
storage = {};
|
|
@@ -18,6 +21,9 @@ class NodeStorage {
|
|
|
18
21
|
setItem(key, value) {
|
|
19
22
|
this.storage[key] = value;
|
|
20
23
|
}
|
|
24
|
+
removeItem(key) {
|
|
25
|
+
delete this.storage[key];
|
|
26
|
+
}
|
|
21
27
|
}
|
|
22
28
|
class LocalStorage {
|
|
23
29
|
storage;
|
|
@@ -38,6 +44,9 @@ class LocalStorage {
|
|
|
38
44
|
const asJson = JSON.stringify(authSignature);
|
|
39
45
|
this.storage.setItem(key, asJson);
|
|
40
46
|
}
|
|
47
|
+
clear(key) {
|
|
48
|
+
this.storage.removeItem(key);
|
|
49
|
+
}
|
|
41
50
|
}
|
|
42
51
|
exports.LocalStorage = LocalStorage;
|
|
43
52
|
//# sourceMappingURL=storage.js.map
|
package/dist/cjs/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":";;;AAAA,mCAA6D;
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":";;;AAAA,mCAA6D;AAU7D,MAAM,cAAc;IACX,OAAO,CAAC,GAAW;QACxB,OAAO,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAEM,OAAO,CAAC,GAAW,EAAE,KAAa;QACvC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;IAEM,UAAU,CAAC,GAAW;QAC3B,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,WAAW;IACP,OAAO,GAA2B,EAAE,CAAC;IAEtC,OAAO,CAAC,GAAW;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IACnC,CAAC;IAEM,OAAO,CAAC,GAAW,EAAE,KAAa;QACvC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC5B,CAAC;IAEM,UAAU,CAAC,GAAW;QAC3B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;CACF;AAED,MAAa,YAAY;IACf,OAAO,CAAW;IAE1B;QACE,IAAI,CAAC,OAAO;YACV,OAAO,YAAY,KAAK,WAAW;gBACjC,CAAC,CAAC,IAAI,WAAW,EAAE;gBACnB,CAAC,CAAC,IAAI,cAAc,EAAE,CAAC;IAC7B,CAAC;IAEM,gBAAgB,CAAC,GAAW;QACjC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,2BAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACvD,CAAC;IAEM,gBAAgB,CAAC,GAAW,EAAE,aAA4B;QAC/D,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;IAEM,KAAK,CAAC,GAAW;QACtB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;CACF;AA1BD,oCA0BC"}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import { AuthSignature } from './auth-sig';
|
|
2
|
-
import { EIP4361AuthProvider } from './providers';
|
|
3
|
-
export declare const EIP4361_AUTH_METHOD = "EIP4361";
|
|
4
2
|
export interface AuthProvider {
|
|
5
3
|
getOrCreateAuthSignature(): Promise<AuthSignature>;
|
|
6
4
|
}
|
|
7
|
-
export type AuthProviders = {
|
|
8
|
-
[EIP4361_AUTH_METHOD]?: EIP4361AuthProvider;
|
|
9
|
-
[key: string]: AuthProvider | undefined;
|
|
10
|
-
};
|
|
11
|
-
export declare const USER_ADDRESS_PARAM_DEFAULT = ":userAddress";
|
|
12
|
-
export declare const AUTH_METHOD_FOR_PARAM: Record<string, string>;
|
package/dist/es/auth-provider.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-provider.js","sourceRoot":"","sources":["../../src/auth-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth-provider.js","sourceRoot":"","sources":["../../src/auth-provider.ts"],"names":[],"mappings":""}
|
package/dist/es/auth-sig.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { EthAddressSchema } from '@nucypher/shared';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { EIP4361_AUTH_METHOD } from './
|
|
4
|
-
import { EIP4361TypedDataSchema } from './providers';
|
|
3
|
+
import { EIP4361_AUTH_METHOD, EIP4361TypedDataSchema, } from './providers/eip4361/common';
|
|
5
4
|
export const authSignatureSchema = z.object({
|
|
6
5
|
signature: z.string(),
|
|
7
6
|
address: EthAddressSchema,
|
package/dist/es/auth-sig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-sig.js","sourceRoot":"","sources":["../../src/auth-sig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,
|
|
1
|
+
{"version":3,"file":"auth-sig.js","sourceRoot":"","sources":["../../src/auth-sig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,OAAO,EAAE,gBAAgB;IACzB,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,mBAAmB,CAAC,CAAC;IACrC,SAAS,EAAE,sBAAsB;CAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SiweMessage } from 'siwe';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export const EIP4361_AUTH_METHOD = 'EIP4361';
|
|
4
|
+
const isSiweMessage = (message) => {
|
|
5
|
+
try {
|
|
6
|
+
new SiweMessage(message);
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export const EIP4361TypedDataSchema = z
|
|
14
|
+
.string()
|
|
15
|
+
.refine(isSiweMessage, { message: 'Invalid SIWE message' });
|
|
16
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../src/providers/eip4361/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAE7C,MAAM,aAAa,GAAG,CAAC,OAAe,EAAW,EAAE;IACjD,IAAI,CAAC;QACH,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC;KACpC,MAAM,EAAE;KACR,MAAM,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { AuthSignature } from '../../auth-sig';
|
|
3
|
+
export declare const USER_ADDRESS_PARAM_DEFAULT = ":userAddress";
|
|
4
|
+
export type EIP4361AuthProviderParams = {
|
|
5
|
+
domain: string;
|
|
6
|
+
uri: string;
|
|
7
|
+
};
|
|
8
|
+
export declare class EIP4361AuthProvider {
|
|
9
|
+
private readonly provider;
|
|
10
|
+
private readonly signer;
|
|
11
|
+
private readonly storage;
|
|
12
|
+
private readonly providerParams;
|
|
13
|
+
constructor(provider: ethers.providers.Provider, signer: ethers.Signer, providerParams?: EIP4361AuthProviderParams);
|
|
14
|
+
private getDefaultParameters;
|
|
15
|
+
getOrCreateAuthSignature(): Promise<AuthSignature>;
|
|
16
|
+
private isMessageExpired;
|
|
17
|
+
private createSIWEAuthMessage;
|
|
18
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { generateNonce, SiweMessage } from 'siwe';
|
|
2
|
+
import { LocalStorage } from '../../storage';
|
|
3
|
+
import { EIP4361_AUTH_METHOD } from './common';
|
|
4
|
+
export const USER_ADDRESS_PARAM_DEFAULT = ':userAddress';
|
|
5
|
+
const ERR_MISSING_SIWE_PARAMETERS = 'Missing default SIWE parameters';
|
|
6
|
+
export class EIP4361AuthProvider {
|
|
7
|
+
provider;
|
|
8
|
+
signer;
|
|
9
|
+
storage;
|
|
10
|
+
providerParams;
|
|
11
|
+
constructor(
|
|
12
|
+
// TODO: We only need the provider to fetch the chainId, consider removing it
|
|
13
|
+
provider, signer, providerParams) {
|
|
14
|
+
this.provider = provider;
|
|
15
|
+
this.signer = signer;
|
|
16
|
+
this.storage = new LocalStorage();
|
|
17
|
+
if (providerParams) {
|
|
18
|
+
this.providerParams = providerParams;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
this.providerParams = this.getDefaultParameters();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
getDefaultParameters() {
|
|
25
|
+
if (typeof window !== 'undefined') {
|
|
26
|
+
// If we are in a browser environment, we can get the domain and uri from the window object
|
|
27
|
+
return {
|
|
28
|
+
domain: window.location?.host,
|
|
29
|
+
uri: window.location?.origin,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// If not, we have no choice but to throw an error
|
|
33
|
+
throw new Error(ERR_MISSING_SIWE_PARAMETERS);
|
|
34
|
+
}
|
|
35
|
+
async getOrCreateAuthSignature() {
|
|
36
|
+
const address = await this.signer.getAddress();
|
|
37
|
+
const storageKey = `eth-${EIP4361_AUTH_METHOD}-message-${address}`;
|
|
38
|
+
// If we have a signature in localStorage, return it
|
|
39
|
+
const maybeSignature = this.storage.getAuthSignature(storageKey);
|
|
40
|
+
if (maybeSignature) {
|
|
41
|
+
// check whether older than node freshness requirement
|
|
42
|
+
if (this.isMessageExpired(maybeSignature.typedData)) {
|
|
43
|
+
// clear signature so that it will be recreated and stored
|
|
44
|
+
this.storage.clear(storageKey);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return maybeSignature;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// If at this point we didn't return, we need to create a new message
|
|
51
|
+
const authMessage = await this.createSIWEAuthMessage();
|
|
52
|
+
this.storage.setAuthSignature(storageKey, authMessage);
|
|
53
|
+
return authMessage;
|
|
54
|
+
}
|
|
55
|
+
isMessageExpired(message) {
|
|
56
|
+
const siweMessage = new SiweMessage(message);
|
|
57
|
+
if (!siweMessage.issuedAt) {
|
|
58
|
+
// don't expect to ever happen; but just in case
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const twoHourWindow = new Date(siweMessage.issuedAt);
|
|
62
|
+
twoHourWindow.setHours(twoHourWindow.getHours() + 2);
|
|
63
|
+
const now = new Date();
|
|
64
|
+
return twoHourWindow < now;
|
|
65
|
+
}
|
|
66
|
+
async createSIWEAuthMessage() {
|
|
67
|
+
const address = await this.signer.getAddress();
|
|
68
|
+
const { domain, uri } = this.providerParams;
|
|
69
|
+
const version = '1';
|
|
70
|
+
const nonce = generateNonce();
|
|
71
|
+
const chainId = (await this.provider.getNetwork()).chainId;
|
|
72
|
+
const siweMessage = new SiweMessage({
|
|
73
|
+
domain,
|
|
74
|
+
address,
|
|
75
|
+
statement: `${domain} wants you to sign in with your Ethereum account: ${address}`,
|
|
76
|
+
uri,
|
|
77
|
+
version,
|
|
78
|
+
nonce,
|
|
79
|
+
chainId,
|
|
80
|
+
});
|
|
81
|
+
const scheme = EIP4361_AUTH_METHOD;
|
|
82
|
+
const message = siweMessage.prepareMessage();
|
|
83
|
+
const signature = await this.signer.signMessage(message);
|
|
84
|
+
return { signature, address, scheme, typedData: message };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=eip4361.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip4361.js","sourceRoot":"","sources":["../../../../src/providers/eip4361/eip4361.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,CAAC,MAAM,0BAA0B,GAAG,cAAc,CAAC;AAOzD,MAAM,2BAA2B,GAAG,iCAAiC,CAAC;AAEtE,MAAM,OAAO,mBAAmB;IAMX;IACA;IANF,OAAO,CAAe;IACtB,cAAc,CAA4B;IAE3D;IACE,6EAA6E;IAC5D,QAAmC,EACnC,MAAqB,EACtC,cAA0C;QAFzB,aAAQ,GAAR,QAAQ,CAA2B;QACnC,WAAM,GAAN,MAAM,CAAe;QAGtC,IAAI,CAAC,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;QAClC,IAAI,cAAc,EAAE,CAAC;YACnB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACvC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACpD,CAAC;IACH,CAAC;IAEO,oBAAoB;QAC1B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,2FAA2F;YAC3F,OAAO;gBACL,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI;gBAC7B,GAAG,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM;aAC7B,CAAC;QACJ,CAAC;QACD,kDAAkD;QAClD,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IAEM,KAAK,CAAC,wBAAwB;QACnC,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EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC;QAC5C,MAAM,OAAO,GAAG,GAAG,CAAC;QACpB,MAAM,KAAK,GAAG,aAAa,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC;QAC3D,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC;YAClC,MAAM;YACN,OAAO;YACP,SAAS,EAAE,GAAG,MAAM,qDAAqD,OAAO,EAAE;YAClF,GAAG;YACH,OAAO;YACP,KAAK;YACL,OAAO;SACR,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,mBAAmB,CAAC;QACnC,MAAM,OAAO,GAAG,WAAW,CAAC,cAAc,EAAE,CAAC;QAC7C,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACzD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;IAC5D,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthSignature } from '../../auth-sig';
|
|
2
|
+
export declare const USER_ADDRESS_PARAM_EXTERNAL_EIP4361 = ":userAddressExternalEIP4361";
|
|
3
|
+
export declare class SingleSignOnEIP4361AuthProvider {
|
|
4
|
+
private readonly existingSiweMessage;
|
|
5
|
+
readonly address: string;
|
|
6
|
+
private readonly signature;
|
|
7
|
+
static fromExistingSiweInfo(existingSiweMessage: string, signature: string): Promise<SingleSignOnEIP4361AuthProvider>;
|
|
8
|
+
private constructor();
|
|
9
|
+
getOrCreateAuthSignature(): Promise<AuthSignature>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SiweMessage } from 'siwe';
|
|
2
|
+
import { EIP4361_AUTH_METHOD } from './common';
|
|
3
|
+
export const USER_ADDRESS_PARAM_EXTERNAL_EIP4361 = ':userAddressExternalEIP4361';
|
|
4
|
+
export class SingleSignOnEIP4361AuthProvider {
|
|
5
|
+
existingSiweMessage;
|
|
6
|
+
address;
|
|
7
|
+
signature;
|
|
8
|
+
static async fromExistingSiweInfo(existingSiweMessage, signature) {
|
|
9
|
+
// validation
|
|
10
|
+
const siweMessage = new SiweMessage(existingSiweMessage);
|
|
11
|
+
await siweMessage.verify({ signature });
|
|
12
|
+
// create provider
|
|
13
|
+
const authProvider = new SingleSignOnEIP4361AuthProvider(siweMessage.prepareMessage(), siweMessage.address, signature);
|
|
14
|
+
return authProvider;
|
|
15
|
+
}
|
|
16
|
+
constructor(existingSiweMessage, address, signature) {
|
|
17
|
+
this.existingSiweMessage = existingSiweMessage;
|
|
18
|
+
this.address = address;
|
|
19
|
+
this.signature = signature;
|
|
20
|
+
}
|
|
21
|
+
async getOrCreateAuthSignature() {
|
|
22
|
+
const scheme = EIP4361_AUTH_METHOD;
|
|
23
|
+
return {
|
|
24
|
+
signature: this.signature,
|
|
25
|
+
address: this.address,
|
|
26
|
+
scheme,
|
|
27
|
+
typedData: this.existingSiweMessage,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=external-eip4361.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-eip4361.js","sourceRoot":"","sources":["../../../../src/providers/eip4361/external-eip4361.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAInC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,CAAC,MAAM,mCAAmC,GAC9C,6BAA6B,CAAC;AAEhC,MAAM,OAAO,+BAA+B;IAkBvB;IACD;IACC;IAnBZ,MAAM,CAAC,KAAK,CAAC,oBAAoB,CACtC,mBAA2B,EAC3B,SAAiB;QAEjB,aAAa;QACb,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,mBAAmB,CAAC,CAAC;QACzD,MAAM,WAAW,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;QACxC,kBAAkB;QAClB,MAAM,YAAY,GAAG,IAAI,+BAA+B,CACtD,WAAW,CAAC,cAAc,EAAE,EAC5B,WAAW,CAAC,OAAO,EACnB,SAAS,CACV,CAAC;QACF,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,YACmB,mBAA2B,EAC5B,OAAe,EACd,SAAiB;QAFjB,wBAAmB,GAAnB,mBAAmB,CAAQ;QAC5B,YAAO,GAAP,OAAO,CAAQ;QACd,cAAS,GAAT,SAAS,CAAQ;IACjC,CAAC;IAEG,KAAK,CAAC,wBAAwB;QACnC,MAAM,MAAM,GAAG,mBAAmB,CAAC;QACnC,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM;YACN,SAAS,EAAE,IAAI,CAAC,mBAAmB;SACpC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './eip4361';
|
|
2
|
-
export * from './external-eip4361';
|
|
1
|
+
export * from './eip4361/eip4361';
|
|
2
|
+
export * from './eip4361/external-eip4361';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './eip4361';
|
|
2
|
-
export * from './external-eip4361';
|
|
1
|
+
export * from './eip4361/eip4361';
|
|
2
|
+
export * from './eip4361/external-eip4361';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC"}
|
package/dist/es/storage.d.ts
CHANGED
package/dist/es/storage.js
CHANGED
|
@@ -6,6 +6,9 @@ class BrowserStorage {
|
|
|
6
6
|
setItem(key, value) {
|
|
7
7
|
localStorage.setItem(key, value);
|
|
8
8
|
}
|
|
9
|
+
removeItem(key) {
|
|
10
|
+
localStorage.removeItem(key);
|
|
11
|
+
}
|
|
9
12
|
}
|
|
10
13
|
class NodeStorage {
|
|
11
14
|
storage = {};
|
|
@@ -15,6 +18,9 @@ class NodeStorage {
|
|
|
15
18
|
setItem(key, value) {
|
|
16
19
|
this.storage[key] = value;
|
|
17
20
|
}
|
|
21
|
+
removeItem(key) {
|
|
22
|
+
delete this.storage[key];
|
|
23
|
+
}
|
|
18
24
|
}
|
|
19
25
|
export class LocalStorage {
|
|
20
26
|
storage;
|
|
@@ -35,5 +41,8 @@ export class LocalStorage {
|
|
|
35
41
|
const asJson = JSON.stringify(authSignature);
|
|
36
42
|
this.storage.setItem(key, asJson);
|
|
37
43
|
}
|
|
44
|
+
clear(key) {
|
|
45
|
+
this.storage.removeItem(key);
|
|
46
|
+
}
|
|
38
47
|
}
|
|
39
48
|
//# sourceMappingURL=storage.js.map
|
package/dist/es/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,mBAAmB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAU7D,MAAM,cAAc;IACX,OAAO,CAAC,GAAW;QACxB,OAAO,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAEM,OAAO,CAAC,GAAW,EAAE,KAAa;QACvC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;IAEM,UAAU,CAAC,GAAW;QAC3B,YAAY,CAAC,UAA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