@nucypher/taco-auth 0.3.0-alpha.1 → 0.3.0-alpha.3
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-sig.d.ts +10 -8
- package/dist/cjs/auth-sig.js +4 -5
- package/dist/cjs/auth-sig.js.map +1 -1
- package/dist/cjs/providers/eip1271/auth.d.ts +44 -0
- package/dist/cjs/providers/eip1271/auth.js +15 -0
- package/dist/cjs/providers/eip1271/auth.js.map +1 -0
- package/dist/cjs/providers/eip1271/eip1271.d.ts +34 -0
- package/dist/cjs/providers/eip1271/eip1271.js +53 -0
- package/dist/cjs/providers/eip1271/eip1271.js.map +1 -0
- package/dist/cjs/providers/eip4361/auth.d.ts +21 -0
- package/dist/cjs/providers/eip4361/auth.js +25 -0
- package/dist/cjs/providers/eip4361/auth.js.map +1 -0
- package/dist/cjs/providers/eip4361/eip4361.d.ts +71 -5
- package/dist/cjs/providers/eip4361/eip4361.js +89 -30
- package/dist/cjs/providers/eip4361/eip4361.js.map +1 -1
- package/dist/cjs/providers/eip4361/external-eip4361.d.ts +35 -4
- package/dist/cjs/providers/eip4361/external-eip4361.js +56 -7
- package/dist/cjs/providers/eip4361/external-eip4361.js.map +1 -1
- package/dist/cjs/providers/eip4361.d.ts +18 -0
- package/dist/cjs/providers/eip4361.js +85 -0
- package/dist/cjs/providers/eip4361.js.map +1 -0
- package/dist/cjs/providers/external-eip4361.d.ts +9 -0
- package/dist/cjs/providers/external-eip4361.js +34 -0
- package/dist/cjs/providers/external-eip4361.js.map +1 -0
- package/dist/cjs/providers/index.d.ts +3 -0
- package/dist/cjs/providers/index.js +4 -0
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/storage.d.ts +6 -4
- package/dist/cjs/storage.js +4 -3
- package/dist/cjs/storage.js.map +1 -1
- package/dist/es/auth-sig.d.ts +10 -8
- package/dist/es/auth-sig.js +3 -4
- package/dist/es/auth-sig.js.map +1 -1
- package/dist/es/providers/eip1271/auth.d.ts +44 -0
- package/dist/es/providers/eip1271/auth.js +12 -0
- package/dist/es/providers/eip1271/auth.js.map +1 -0
- package/dist/es/providers/eip1271/eip1271.d.ts +34 -0
- package/dist/es/providers/eip1271/eip1271.js +49 -0
- package/dist/es/providers/eip1271/eip1271.js.map +1 -0
- package/dist/es/providers/eip4361/auth.d.ts +21 -0
- package/dist/es/providers/eip4361/auth.js +22 -0
- package/dist/es/providers/eip4361/auth.js.map +1 -0
- package/dist/es/providers/eip4361/eip4361.d.ts +71 -5
- package/dist/es/providers/eip4361/eip4361.js +87 -28
- package/dist/es/providers/eip4361/eip4361.js.map +1 -1
- package/dist/es/providers/eip4361/external-eip4361.d.ts +35 -4
- package/dist/es/providers/eip4361/external-eip4361.js +54 -5
- package/dist/es/providers/eip4361/external-eip4361.js.map +1 -1
- package/dist/es/providers/eip4361.d.ts +18 -0
- package/dist/es/providers/eip4361.js +81 -0
- package/dist/es/providers/eip4361.js.map +1 -0
- package/dist/es/providers/external-eip4361.d.ts +9 -0
- package/dist/es/providers/external-eip4361.js +30 -0
- package/dist/es/providers/external-eip4361.js.map +1 -0
- package/dist/es/providers/index.d.ts +3 -0
- package/dist/es/providers/index.js +2 -0
- package/dist/es/providers/index.js.map +1 -1
- package/dist/es/storage.d.ts +6 -4
- package/dist/es/storage.js +4 -3
- 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 +5 -5
package/dist/cjs/auth-sig.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
2
|
+
import { EIP1271AuthSignature } from './providers/eip1271/auth';
|
|
3
|
+
import { EIP4361AuthSignature } from './providers/eip4361/auth';
|
|
4
|
+
export declare const baseAuthSignatureSchema: z.ZodObject<{
|
|
3
5
|
signature: z.ZodString;
|
|
4
6
|
address: z.ZodEffects<z.ZodString, string, string>;
|
|
5
|
-
scheme: z.
|
|
6
|
-
typedData: z.
|
|
7
|
+
scheme: z.ZodString;
|
|
8
|
+
typedData: z.ZodUnknown;
|
|
7
9
|
}, "strip", z.ZodTypeAny, {
|
|
8
10
|
signature: string;
|
|
9
11
|
address: string;
|
|
10
|
-
scheme:
|
|
11
|
-
typedData
|
|
12
|
+
scheme: string;
|
|
13
|
+
typedData?: unknown;
|
|
12
14
|
}, {
|
|
13
15
|
signature: string;
|
|
14
16
|
address: string;
|
|
15
|
-
scheme:
|
|
16
|
-
typedData
|
|
17
|
+
scheme: string;
|
|
18
|
+
typedData?: unknown;
|
|
17
19
|
}>;
|
|
18
|
-
export type AuthSignature =
|
|
20
|
+
export type AuthSignature = EIP4361AuthSignature | EIP1271AuthSignature;
|
package/dist/cjs/auth-sig.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.baseAuthSignatureSchema = void 0;
|
|
4
4
|
const shared_1 = require("@nucypher/shared");
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
|
-
|
|
7
|
-
exports.authSignatureSchema = zod_1.z.object({
|
|
6
|
+
exports.baseAuthSignatureSchema = zod_1.z.object({
|
|
8
7
|
signature: zod_1.z.string(),
|
|
9
8
|
address: shared_1.EthAddressSchema,
|
|
10
|
-
scheme: zod_1.z.
|
|
11
|
-
typedData:
|
|
9
|
+
scheme: zod_1.z.string(),
|
|
10
|
+
typedData: zod_1.z.unknown(),
|
|
12
11
|
});
|
|
13
12
|
//# 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;
|
|
1
|
+
{"version":3,"file":"auth-sig.js","sourceRoot":"","sources":["../../src/auth-sig.ts"],"names":[],"mappings":";;;AAAA,6CAAoD;AACpD,6BAAwB;AAKX,QAAA,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9C,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;IACrB,OAAO,EAAE,yBAAgB;IACzB,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;IAClB,SAAS,EAAE,OAAC,CAAC,OAAO,EAAE;CACvB,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const EIP1271_AUTH_METHOD = "EIP1271";
|
|
3
|
+
export declare const EIP1271TypedDataSchema: z.ZodObject<{
|
|
4
|
+
chain: z.ZodNumber;
|
|
5
|
+
dataHash: z.ZodString;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
chain: number;
|
|
8
|
+
dataHash: string;
|
|
9
|
+
}, {
|
|
10
|
+
chain: number;
|
|
11
|
+
dataHash: string;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const eip1271AuthSignatureSchema: z.ZodObject<{
|
|
14
|
+
signature: z.ZodString;
|
|
15
|
+
address: z.ZodEffects<z.ZodString, string, string>;
|
|
16
|
+
scheme: z.ZodLiteral<"EIP1271">;
|
|
17
|
+
typedData: z.ZodObject<{
|
|
18
|
+
chain: z.ZodNumber;
|
|
19
|
+
dataHash: z.ZodString;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
chain: number;
|
|
22
|
+
dataHash: string;
|
|
23
|
+
}, {
|
|
24
|
+
chain: number;
|
|
25
|
+
dataHash: string;
|
|
26
|
+
}>;
|
|
27
|
+
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
signature: string;
|
|
29
|
+
address: string;
|
|
30
|
+
scheme: "EIP1271";
|
|
31
|
+
typedData: {
|
|
32
|
+
chain: number;
|
|
33
|
+
dataHash: string;
|
|
34
|
+
};
|
|
35
|
+
}, {
|
|
36
|
+
signature: string;
|
|
37
|
+
address: string;
|
|
38
|
+
scheme: "EIP1271";
|
|
39
|
+
typedData: {
|
|
40
|
+
chain: number;
|
|
41
|
+
dataHash: string;
|
|
42
|
+
};
|
|
43
|
+
}>;
|
|
44
|
+
export type EIP1271AuthSignature = z.infer<typeof eip1271AuthSignatureSchema>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eip1271AuthSignatureSchema = exports.EIP1271TypedDataSchema = exports.EIP1271_AUTH_METHOD = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const auth_sig_1 = require("../../auth-sig");
|
|
6
|
+
exports.EIP1271_AUTH_METHOD = 'EIP1271';
|
|
7
|
+
exports.EIP1271TypedDataSchema = zod_1.z.object({
|
|
8
|
+
chain: zod_1.z.number().int().nonnegative(),
|
|
9
|
+
dataHash: zod_1.z.string().startsWith('0x'), // hex string
|
|
10
|
+
});
|
|
11
|
+
exports.eip1271AuthSignatureSchema = auth_sig_1.baseAuthSignatureSchema.extend({
|
|
12
|
+
scheme: zod_1.z.literal(exports.EIP1271_AUTH_METHOD),
|
|
13
|
+
typedData: exports.EIP1271TypedDataSchema,
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../../src/providers/eip1271/auth.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,6CAAyD;AAE5C,QAAA,mBAAmB,GAAG,SAAS,CAAC;AAEhC,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC7C,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;IACrC,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,aAAa;CACrD,CAAC,CAAC;AAEU,QAAA,0BAA0B,GAAG,kCAAuB,CAAC,MAAM,CAAC;IACvE,MAAM,EAAE,OAAC,CAAC,OAAO,CAAC,2BAAmB,CAAC;IACtC,SAAS,EAAE,8BAAsB;CAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AuthProvider } from '../../auth-provider';
|
|
2
|
+
import { EIP1271AuthSignature } from './auth';
|
|
3
|
+
/**
|
|
4
|
+
* EIP1271AuthProvider handles EIP-1271 contract-based authentication.
|
|
5
|
+
* This provider manages authentication signatures from smart contracts that implement EIP-1271's `isValidSignature` solidity function.
|
|
6
|
+
*/
|
|
7
|
+
export declare class EIP1271AuthProvider implements AuthProvider {
|
|
8
|
+
readonly contractAddress: string;
|
|
9
|
+
readonly chain: number;
|
|
10
|
+
readonly dataHash: string;
|
|
11
|
+
readonly signature: string;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new EIP1271AuthProvider for contract-based authentication.
|
|
14
|
+
*
|
|
15
|
+
* @param contractAddress - The Ethereum address of the contract implementing EIP-1271
|
|
16
|
+
* @param chain - The chain ID where the contract is deployed
|
|
17
|
+
* @param dataHash - The hash of the data that was signed
|
|
18
|
+
* @param signature - The signature produced by the contract's signing method
|
|
19
|
+
*/
|
|
20
|
+
constructor(contractAddress: string, chain: number, dataHash: string, signature: string);
|
|
21
|
+
/**
|
|
22
|
+
* Returns the authentication signature for the contract.
|
|
23
|
+
*
|
|
24
|
+
* Since contract signatures are created externally, this method simply returns
|
|
25
|
+
* the existing signature and metadata rather than creating a new one.
|
|
26
|
+
*
|
|
27
|
+
* @returns {Promise<EIP1271AuthSignature>} The authentication signature containing:
|
|
28
|
+
* - signature: The contract-generated signature
|
|
29
|
+
* - address: The contract's address
|
|
30
|
+
* - scheme: The authentication scheme (EIP1271)
|
|
31
|
+
* - typedData: Object containing the chain ID and data hash
|
|
32
|
+
*/
|
|
33
|
+
getOrCreateAuthSignature(): Promise<EIP1271AuthSignature>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EIP1271AuthProvider = void 0;
|
|
4
|
+
const auth_1 = require("./auth");
|
|
5
|
+
/**
|
|
6
|
+
* EIP1271AuthProvider handles EIP-1271 contract-based authentication.
|
|
7
|
+
* This provider manages authentication signatures from smart contracts that implement EIP-1271's `isValidSignature` solidity function.
|
|
8
|
+
*/
|
|
9
|
+
class EIP1271AuthProvider {
|
|
10
|
+
contractAddress;
|
|
11
|
+
chain;
|
|
12
|
+
dataHash;
|
|
13
|
+
signature;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new EIP1271AuthProvider for contract-based authentication.
|
|
16
|
+
*
|
|
17
|
+
* @param contractAddress - The Ethereum address of the contract implementing EIP-1271
|
|
18
|
+
* @param chain - The chain ID where the contract is deployed
|
|
19
|
+
* @param dataHash - The hash of the data that was signed
|
|
20
|
+
* @param signature - The signature produced by the contract's signing method
|
|
21
|
+
*/
|
|
22
|
+
constructor(contractAddress, chain, dataHash, signature) {
|
|
23
|
+
this.contractAddress = contractAddress;
|
|
24
|
+
this.chain = chain;
|
|
25
|
+
this.dataHash = dataHash;
|
|
26
|
+
this.signature = signature;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the authentication signature for the contract.
|
|
30
|
+
*
|
|
31
|
+
* Since contract signatures are created externally, this method simply returns
|
|
32
|
+
* the existing signature and metadata rather than creating a new one.
|
|
33
|
+
*
|
|
34
|
+
* @returns {Promise<EIP1271AuthSignature>} The authentication signature containing:
|
|
35
|
+
* - signature: The contract-generated signature
|
|
36
|
+
* - address: The contract's address
|
|
37
|
+
* - scheme: The authentication scheme (EIP1271)
|
|
38
|
+
* - typedData: Object containing the chain ID and data hash
|
|
39
|
+
*/
|
|
40
|
+
async getOrCreateAuthSignature() {
|
|
41
|
+
return {
|
|
42
|
+
signature: this.signature,
|
|
43
|
+
address: this.contractAddress,
|
|
44
|
+
scheme: auth_1.EIP1271_AUTH_METHOD,
|
|
45
|
+
typedData: {
|
|
46
|
+
chain: this.chain,
|
|
47
|
+
dataHash: this.dataHash,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.EIP1271AuthProvider = EIP1271AuthProvider;
|
|
53
|
+
//# sourceMappingURL=eip1271.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip1271.js","sourceRoot":"","sources":["../../../../src/providers/eip1271/eip1271.ts"],"names":[],"mappings":";;;AAEA,iCAAmE;AAEnE;;;GAGG;AACH,MAAa,mBAAmB;IAUZ;IACA;IACA;IACA;IAZlB;;;;;;;OAOG;IACH,YACkB,eAAuB,EACvB,KAAa,EACb,QAAgB,EAChB,SAAiB;QAHjB,oBAAe,GAAf,eAAe,CAAQ;QACvB,UAAK,GAAL,KAAK,CAAQ;QACb,aAAQ,GAAR,QAAQ,CAAQ;QAChB,cAAS,GAAT,SAAS,CAAQ;IAChC,CAAC;IAEJ;;;;;;;;;;;OAWG;IACI,KAAK,CAAC,wBAAwB;QACnC,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,eAAe;YAC7B,MAAM,EAAE,0BAAmB;YAC3B,SAAS,EAAE;gBACT,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB;SACF,CAAC;IACJ,CAAC;CACF;AAvCD,kDAuCC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const EIP4361_AUTH_METHOD = "EIP4361";
|
|
3
|
+
export declare const USER_ADDRESS_PARAM_DEFAULT = ":userAddress";
|
|
4
|
+
export declare const EIP4361TypedDataSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
5
|
+
export declare const eip4361AuthSignatureSchema: z.ZodObject<{
|
|
6
|
+
signature: z.ZodString;
|
|
7
|
+
address: z.ZodEffects<z.ZodString, string, string>;
|
|
8
|
+
scheme: z.ZodLiteral<"EIP4361">;
|
|
9
|
+
typedData: z.ZodEffects<z.ZodString, string, string>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
signature: string;
|
|
12
|
+
address: string;
|
|
13
|
+
scheme: "EIP4361";
|
|
14
|
+
typedData: string;
|
|
15
|
+
}, {
|
|
16
|
+
signature: string;
|
|
17
|
+
address: string;
|
|
18
|
+
scheme: "EIP4361";
|
|
19
|
+
typedData: string;
|
|
20
|
+
}>;
|
|
21
|
+
export type EIP4361AuthSignature = z.infer<typeof eip4361AuthSignatureSchema>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eip4361AuthSignatureSchema = exports.EIP4361TypedDataSchema = exports.USER_ADDRESS_PARAM_DEFAULT = exports.EIP4361_AUTH_METHOD = void 0;
|
|
4
|
+
const siwe_1 = require("siwe");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const auth_sig_1 = require("../../auth-sig");
|
|
7
|
+
exports.EIP4361_AUTH_METHOD = 'EIP4361';
|
|
8
|
+
exports.USER_ADDRESS_PARAM_DEFAULT = ':userAddress';
|
|
9
|
+
const isSiweMessage = (message) => {
|
|
10
|
+
try {
|
|
11
|
+
new siwe_1.SiweMessage(message);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.EIP4361TypedDataSchema = zod_1.z
|
|
19
|
+
.string()
|
|
20
|
+
.refine(isSiweMessage, { message: 'Invalid SIWE message' });
|
|
21
|
+
exports.eip4361AuthSignatureSchema = auth_sig_1.baseAuthSignatureSchema.extend({
|
|
22
|
+
scheme: zod_1.z.literal(exports.EIP4361_AUTH_METHOD),
|
|
23
|
+
typedData: exports.EIP4361TypedDataSchema,
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../../src/providers/eip4361/auth.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AACnC,6BAAwB;AAExB,6CAAyD;AAE5C,QAAA,mBAAmB,GAAG,SAAS,CAAC;AAEhC,QAAA,0BAA0B,GAAG,cAAc,CAAC;AAEzD,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;AAEjD,QAAA,0BAA0B,GAAG,kCAAuB,CAAC,MAAM,CAAC;IACvE,MAAM,EAAE,OAAC,CAAC,OAAO,CAAC,2BAAmB,CAAC;IACtC,SAAS,EAAE,8BAAsB;CAClC,CAAC,CAAC"}
|
|
@@ -1,18 +1,84 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { AuthProvider } from '../../auth-provider';
|
|
3
|
+
import { EIP4361AuthSignature } from './auth';
|
|
4
4
|
export type EIP4361AuthProviderParams = {
|
|
5
5
|
domain: string;
|
|
6
6
|
uri: string;
|
|
7
7
|
};
|
|
8
|
-
export declare
|
|
8
|
+
export declare const FRESHNESS_IN_MILLISECONDS: number;
|
|
9
|
+
/**
|
|
10
|
+
* Implements Sign-In with Ethereum (EIP-4361/SIWE) authentication by managing SIWE message lifecycle.
|
|
11
|
+
*
|
|
12
|
+
* This provider handles:
|
|
13
|
+
* - Creating and signing new SIWE messages
|
|
14
|
+
* - Storing signed messages in local storage
|
|
15
|
+
* - Retrieving and validating stored messages
|
|
16
|
+
* - Automatically refreshing expired messages
|
|
17
|
+
*
|
|
18
|
+
* Messages are valid for 2 hours from creation and stored locally keyed by the signer's address.
|
|
19
|
+
*
|
|
20
|
+
* @implements {AuthProvider}
|
|
21
|
+
*/
|
|
22
|
+
export declare class EIP4361AuthProvider implements AuthProvider {
|
|
9
23
|
private readonly provider;
|
|
10
24
|
private readonly signer;
|
|
11
25
|
private readonly storage;
|
|
12
26
|
private readonly providerParams;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new EIP4361AuthProvider instance.
|
|
29
|
+
*
|
|
30
|
+
* @param provider - Ethers provider used to fetch the current chainId
|
|
31
|
+
* @param signer - Ethers signer used to sign SIWE messages
|
|
32
|
+
* @param providerParams - Optional SIWE message configuration
|
|
33
|
+
* @param providerParams.domain - Domain name for the signing request (e.g. 'app.example.com').
|
|
34
|
+
* Defaults to current website domain or 'taco.build'
|
|
35
|
+
* @param providerParams.uri - Full URI of signing request origin (e.g. 'https://app.example.com').
|
|
36
|
+
* Defaults to current website URL or 'https://taco.build'
|
|
37
|
+
*
|
|
38
|
+
* The SIWE message will include:
|
|
39
|
+
* - A human-readable statement: "{domain} wants you to sign in with your Ethereum account: {address}"
|
|
40
|
+
* - Version: "1"
|
|
41
|
+
* - 2 hour expiration from creation time
|
|
42
|
+
* - Chain ID from the provided provider
|
|
43
|
+
* - Nonce: Auto-generated
|
|
44
|
+
*/
|
|
13
45
|
constructor(provider: ethers.providers.Provider, signer: ethers.Signer, providerParams?: EIP4361AuthProviderParams);
|
|
46
|
+
/**
|
|
47
|
+
* Gets default domain and URI parameters based on runtime environment.
|
|
48
|
+
*
|
|
49
|
+
* @returns Default parameters object with domain and uri
|
|
50
|
+
* @returns.domain - Host domain from window.location or 'taco.build'
|
|
51
|
+
* @returns.uri - Origin URL from window.location or 'https://taco.build'
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
14
54
|
private getDefaultParameters;
|
|
15
|
-
|
|
16
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Gets a valid auth signature, either from storage or by creating a new one.
|
|
57
|
+
*
|
|
58
|
+
* Process:
|
|
59
|
+
* 1. Check local storage for existing signature for the signer's address
|
|
60
|
+
* 2. If found, verify the signature and expiration time
|
|
61
|
+
* 3. If verification fails or no signature exists, create and store a new one
|
|
62
|
+
* 4. Return the valid signature
|
|
63
|
+
*
|
|
64
|
+
* @returns Promise resolving to a valid EIP-4361 auth signature containing:
|
|
65
|
+
* @returns.signature - The signed SIWE message
|
|
66
|
+
* @returns.address - The signer's Ethereum address
|
|
67
|
+
* @returns.scheme - Authentication scheme ('eip4361')
|
|
68
|
+
* @returns.typedData - Original SIWE message string
|
|
69
|
+
*/
|
|
70
|
+
getOrCreateAuthSignature(): Promise<EIP4361AuthSignature>;
|
|
71
|
+
/**
|
|
72
|
+
* Creates and signs a new SIWE authentication message.
|
|
73
|
+
*
|
|
74
|
+
* Process:
|
|
75
|
+
* 1. Get signer's address and current chain ID
|
|
76
|
+
* 2. Create SIWE message with 2 hour expiration
|
|
77
|
+
* 3. Sign message with signer
|
|
78
|
+
* 4. Return signed auth signature object
|
|
79
|
+
*
|
|
80
|
+
* @returns Promise resolving to newly created and signed auth signature
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
17
83
|
private createSIWEAuthMessage;
|
|
18
84
|
}
|
|
@@ -1,22 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EIP4361AuthProvider = exports.
|
|
3
|
+
exports.EIP4361AuthProvider = exports.FRESHNESS_IN_MILLISECONDS = void 0;
|
|
4
4
|
const siwe_1 = require("siwe");
|
|
5
5
|
const storage_1 = require("../../storage");
|
|
6
|
-
const
|
|
7
|
-
exports.
|
|
8
|
-
const
|
|
6
|
+
const auth_1 = require("./auth");
|
|
7
|
+
exports.FRESHNESS_IN_MILLISECONDS = 2 * 60 * 60 * 1000;
|
|
8
|
+
const TACO_DEFAULT_DOMAIN = 'taco.build';
|
|
9
|
+
const TACO_DEFAULT_URI = 'https://taco.build';
|
|
10
|
+
/**
|
|
11
|
+
* Implements Sign-In with Ethereum (EIP-4361/SIWE) authentication by managing SIWE message lifecycle.
|
|
12
|
+
*
|
|
13
|
+
* This provider handles:
|
|
14
|
+
* - Creating and signing new SIWE messages
|
|
15
|
+
* - Storing signed messages in local storage
|
|
16
|
+
* - Retrieving and validating stored messages
|
|
17
|
+
* - Automatically refreshing expired messages
|
|
18
|
+
*
|
|
19
|
+
* Messages are valid for 2 hours from creation and stored locally keyed by the signer's address.
|
|
20
|
+
*
|
|
21
|
+
* @implements {AuthProvider}
|
|
22
|
+
*/
|
|
9
23
|
class EIP4361AuthProvider {
|
|
10
24
|
provider;
|
|
11
25
|
signer;
|
|
12
26
|
storage;
|
|
13
27
|
providerParams;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new EIP4361AuthProvider instance.
|
|
30
|
+
*
|
|
31
|
+
* @param provider - Ethers provider used to fetch the current chainId
|
|
32
|
+
* @param signer - Ethers signer used to sign SIWE messages
|
|
33
|
+
* @param providerParams - Optional SIWE message configuration
|
|
34
|
+
* @param providerParams.domain - Domain name for the signing request (e.g. 'app.example.com').
|
|
35
|
+
* Defaults to current website domain or 'taco.build'
|
|
36
|
+
* @param providerParams.uri - Full URI of signing request origin (e.g. 'https://app.example.com').
|
|
37
|
+
* Defaults to current website URL or 'https://taco.build'
|
|
38
|
+
*
|
|
39
|
+
* The SIWE message will include:
|
|
40
|
+
* - A human-readable statement: "{domain} wants you to sign in with your Ethereum account: {address}"
|
|
41
|
+
* - Version: "1"
|
|
42
|
+
* - 2 hour expiration from creation time
|
|
43
|
+
* - Chain ID from the provided provider
|
|
44
|
+
* - Nonce: Auto-generated
|
|
45
|
+
*/
|
|
46
|
+
constructor(provider, signer, providerParams) {
|
|
17
47
|
this.provider = provider;
|
|
18
48
|
this.signer = signer;
|
|
19
|
-
this.storage = new storage_1.LocalStorage();
|
|
49
|
+
this.storage = new storage_1.LocalStorage(auth_1.eip4361AuthSignatureSchema);
|
|
20
50
|
if (providerParams) {
|
|
21
51
|
this.providerParams = providerParams;
|
|
22
52
|
}
|
|
@@ -24,6 +54,14 @@ class EIP4361AuthProvider {
|
|
|
24
54
|
this.providerParams = this.getDefaultParameters();
|
|
25
55
|
}
|
|
26
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Gets default domain and URI parameters based on runtime environment.
|
|
59
|
+
*
|
|
60
|
+
* @returns Default parameters object with domain and uri
|
|
61
|
+
* @returns.domain - Host domain from window.location or 'taco.build'
|
|
62
|
+
* @returns.uri - Origin URL from window.location or 'https://taco.build'
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
27
65
|
getDefaultParameters() {
|
|
28
66
|
if (typeof window !== 'undefined') {
|
|
29
67
|
// If we are in a browser environment, we can get the domain and uri from the window object
|
|
@@ -32,45 +70,65 @@ class EIP4361AuthProvider {
|
|
|
32
70
|
uri: window.location?.origin,
|
|
33
71
|
};
|
|
34
72
|
}
|
|
35
|
-
//
|
|
36
|
-
|
|
73
|
+
// not in a browser environment, use hardcoded defaults
|
|
74
|
+
return {
|
|
75
|
+
domain: TACO_DEFAULT_DOMAIN,
|
|
76
|
+
uri: TACO_DEFAULT_URI,
|
|
77
|
+
};
|
|
37
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Gets a valid auth signature, either from storage or by creating a new one.
|
|
81
|
+
*
|
|
82
|
+
* Process:
|
|
83
|
+
* 1. Check local storage for existing signature for the signer's address
|
|
84
|
+
* 2. If found, verify the signature and expiration time
|
|
85
|
+
* 3. If verification fails or no signature exists, create and store a new one
|
|
86
|
+
* 4. Return the valid signature
|
|
87
|
+
*
|
|
88
|
+
* @returns Promise resolving to a valid EIP-4361 auth signature containing:
|
|
89
|
+
* @returns.signature - The signed SIWE message
|
|
90
|
+
* @returns.address - The signer's Ethereum address
|
|
91
|
+
* @returns.scheme - Authentication scheme ('eip4361')
|
|
92
|
+
* @returns.typedData - Original SIWE message string
|
|
93
|
+
*/
|
|
38
94
|
async getOrCreateAuthSignature() {
|
|
39
95
|
const address = await this.signer.getAddress();
|
|
40
|
-
const storageKey = `eth-${
|
|
96
|
+
const storageKey = `eth-${auth_1.EIP4361_AUTH_METHOD}-message-${address}`;
|
|
41
97
|
// If we have a signature in localStorage, return it
|
|
42
98
|
const maybeSignature = this.storage.getAuthSignature(storageKey);
|
|
43
99
|
if (maybeSignature) {
|
|
44
|
-
|
|
45
|
-
|
|
100
|
+
const siweMessage = new siwe_1.SiweMessage(maybeSignature.typedData);
|
|
101
|
+
try {
|
|
102
|
+
// check message validity specifically here for the `expirationTime`.
|
|
103
|
+
await siweMessage.verify({ signature: maybeSignature.signature });
|
|
104
|
+
return maybeSignature;
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
46
107
|
// clear signature so that it will be recreated and stored
|
|
47
108
|
this.storage.clear(storageKey);
|
|
48
109
|
}
|
|
49
|
-
else {
|
|
50
|
-
return maybeSignature;
|
|
51
|
-
}
|
|
52
110
|
}
|
|
53
111
|
// If at this point we didn't return, we need to create a new message
|
|
54
112
|
const authMessage = await this.createSIWEAuthMessage();
|
|
55
113
|
this.storage.setAuthSignature(storageKey, authMessage);
|
|
56
114
|
return authMessage;
|
|
57
115
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Creates and signs a new SIWE authentication message.
|
|
118
|
+
*
|
|
119
|
+
* Process:
|
|
120
|
+
* 1. Get signer's address and current chain ID
|
|
121
|
+
* 2. Create SIWE message with 2 hour expiration
|
|
122
|
+
* 3. Sign message with signer
|
|
123
|
+
* 4. Return signed auth signature object
|
|
124
|
+
*
|
|
125
|
+
* @returns Promise resolving to newly created and signed auth signature
|
|
126
|
+
* @private
|
|
127
|
+
*/
|
|
69
128
|
async createSIWEAuthMessage() {
|
|
70
129
|
const address = await this.signer.getAddress();
|
|
71
130
|
const { domain, uri } = this.providerParams;
|
|
72
131
|
const version = '1';
|
|
73
|
-
const nonce = (0, siwe_1.generateNonce)();
|
|
74
132
|
const chainId = (await this.provider.getNetwork()).chainId;
|
|
75
133
|
const siweMessage = new siwe_1.SiweMessage({
|
|
76
134
|
domain,
|
|
@@ -78,10 +136,11 @@ class EIP4361AuthProvider {
|
|
|
78
136
|
statement: `${domain} wants you to sign in with your Ethereum account: ${address}`,
|
|
79
137
|
uri,
|
|
80
138
|
version,
|
|
81
|
-
nonce,
|
|
82
139
|
chainId,
|
|
140
|
+
// set the expirationTime to 2 hours from now
|
|
141
|
+
expirationTime: new Date(Date.now() + exports.FRESHNESS_IN_MILLISECONDS).toISOString(),
|
|
83
142
|
});
|
|
84
|
-
const scheme =
|
|
143
|
+
const scheme = auth_1.EIP4361_AUTH_METHOD;
|
|
85
144
|
const message = siweMessage.prepareMessage();
|
|
86
145
|
const signature = await this.signer.signMessage(message);
|
|
87
146
|
return { signature, address, scheme, typedData: message };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eip4361.js","sourceRoot":"","sources":["../../../../src/providers/eip4361/eip4361.ts"],"names":[],"mappings":";;;AACA,+
|
|
1
|
+
{"version":3,"file":"eip4361.js","sourceRoot":"","sources":["../../../../src/providers/eip4361/eip4361.ts"],"names":[],"mappings":";;;AACA,+BAAmC;AAGnC,2CAA6C;AAE7C,iCAIgB;AAOH,QAAA,yBAAyB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE5D,MAAM,mBAAmB,GAAG,YAAY,CAAC;AACzC,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAE9C;;;;;;;;;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AC;QACzD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;IAC5D,CAAC;CACF;AApID,kDAoIC"}
|
|
@@ -1,10 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { AuthProvider } from '../../auth-provider';
|
|
2
|
+
import { EIP4361AuthSignature } from './auth';
|
|
3
|
+
/**
|
|
4
|
+
* SingleSignOnEIP4361AuthProvider handles Sign-In with Ethereum (EIP-4361/SIWE) authentication
|
|
5
|
+
* using an existing SIWE message and signature.
|
|
6
|
+
*
|
|
7
|
+
* This provider validates and reuses an existing SIWE message and signature rather than generating new ones.
|
|
8
|
+
* It's useful for implementing single sign-on flows where the SIWE authentication was performed elsewhere.
|
|
9
|
+
*/
|
|
10
|
+
export declare class SingleSignOnEIP4361AuthProvider implements AuthProvider {
|
|
4
11
|
private readonly existingSiweMessage;
|
|
5
12
|
readonly address: string;
|
|
6
13
|
private readonly signature;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new SingleSignOnEIP4361AuthProvider from an existing SIWE message and signature.
|
|
16
|
+
*
|
|
17
|
+
* @param existingSiweMessage - The existing SIWE message string to validate and reuse
|
|
18
|
+
* @param signature - The signature corresponding to the SIWE message
|
|
19
|
+
* @returns A new SingleSignOnEIP4361AuthProvider instance
|
|
20
|
+
* @throws {Error} If signature verification fails or message parameters are invalid
|
|
21
|
+
*/
|
|
7
22
|
static fromExistingSiweInfo(existingSiweMessage: string, signature: string): Promise<SingleSignOnEIP4361AuthProvider>;
|
|
23
|
+
/**
|
|
24
|
+
* Private constructor - use fromExistingSiweInfo() to create instances.
|
|
25
|
+
*
|
|
26
|
+
* @param existingSiweMessage - The validated SIWE message string
|
|
27
|
+
* @param address - The Ethereum address that signed the message
|
|
28
|
+
* @param signature - The validated signature
|
|
29
|
+
*/
|
|
8
30
|
private constructor();
|
|
9
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Returns the existing auth signature after re-validating it.
|
|
33
|
+
*
|
|
34
|
+
* This method verifies that the stored signature and message are still valid
|
|
35
|
+
* before returning them as an EIP4361AuthSignature object.
|
|
36
|
+
*
|
|
37
|
+
* @returns {Promise<EIP4361AuthSignature>} The validated authentication signature
|
|
38
|
+
* @throws {Error} If signature verification fails
|
|
39
|
+
*/
|
|
40
|
+
getOrCreateAuthSignature(): Promise<EIP4361AuthSignature>;
|
|
10
41
|
}
|