@nucypher/taco-auth 0.3.0-alpha.2 → 0.3.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-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 +47 -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 +24 -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/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 +47 -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 +24 -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/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
|
@@ -1,28 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SingleSignOnEIP4361AuthProvider =
|
|
3
|
+
exports.SingleSignOnEIP4361AuthProvider = void 0;
|
|
4
4
|
const siwe_1 = require("siwe");
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const auth_1 = require("./auth");
|
|
6
|
+
const eip4361_1 = require("./eip4361");
|
|
7
|
+
async function generateAndVerifySiweMessage(message, signature) {
|
|
8
|
+
const siweMessage = new siwe_1.SiweMessage(message);
|
|
9
|
+
// this will trigger validation for the signature and all parameters (`expirationTime`, `notBefore`...).
|
|
10
|
+
await siweMessage.verify({ signature });
|
|
11
|
+
const twoHoursBeforeNow = new Date(Date.now() - eip4361_1.FRESHNESS_IN_MILLISECONDS);
|
|
12
|
+
if (!siweMessage.issuedAt) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
// this should never happen
|
|
15
|
+
`The SIWE message is missing an \`issuedAt\` field and would be rejected by TACo nodes.`);
|
|
16
|
+
}
|
|
17
|
+
if (new Date(siweMessage.issuedAt) < twoHoursBeforeNow) {
|
|
18
|
+
throw new Error(`The SIWE message was issued more than 2 hours ago and would be rejected by TACo nodes.`);
|
|
19
|
+
}
|
|
20
|
+
const now = new Date();
|
|
21
|
+
if (new Date(siweMessage.issuedAt) > now) {
|
|
22
|
+
throw new Error(`The SIWE message was issued at a future datetime: ${siweMessage.issuedAt} and would be rejected by TACo nodes.`);
|
|
23
|
+
}
|
|
24
|
+
return siweMessage;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* SingleSignOnEIP4361AuthProvider handles Sign-In with Ethereum (EIP-4361/SIWE) authentication
|
|
28
|
+
* using an existing SIWE message and signature.
|
|
29
|
+
*
|
|
30
|
+
* This provider validates and reuses an existing SIWE message and signature rather than generating new ones.
|
|
31
|
+
* It's useful for implementing single sign-on flows where the SIWE authentication was performed elsewhere.
|
|
32
|
+
*/
|
|
7
33
|
class SingleSignOnEIP4361AuthProvider {
|
|
8
34
|
existingSiweMessage;
|
|
9
35
|
address;
|
|
10
36
|
signature;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new SingleSignOnEIP4361AuthProvider from an existing SIWE message and signature.
|
|
39
|
+
*
|
|
40
|
+
* @param existingSiweMessage - The existing SIWE message string to validate and reuse
|
|
41
|
+
* @param signature - The signature corresponding to the SIWE message
|
|
42
|
+
* @returns A new SingleSignOnEIP4361AuthProvider instance
|
|
43
|
+
* @throws {Error} If signature verification fails or message parameters are invalid
|
|
44
|
+
*/
|
|
11
45
|
static async fromExistingSiweInfo(existingSiweMessage, signature) {
|
|
12
|
-
|
|
13
|
-
const siweMessage = new siwe_1.SiweMessage(existingSiweMessage);
|
|
14
|
-
await siweMessage.verify({ signature });
|
|
46
|
+
const siweMessage = await generateAndVerifySiweMessage(existingSiweMessage, signature);
|
|
15
47
|
// create provider
|
|
16
48
|
const authProvider = new SingleSignOnEIP4361AuthProvider(siweMessage.prepareMessage(), siweMessage.address, signature);
|
|
17
49
|
return authProvider;
|
|
18
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Private constructor - use fromExistingSiweInfo() to create instances.
|
|
53
|
+
*
|
|
54
|
+
* @param existingSiweMessage - The validated SIWE message string
|
|
55
|
+
* @param address - The Ethereum address that signed the message
|
|
56
|
+
* @param signature - The validated signature
|
|
57
|
+
*/
|
|
19
58
|
constructor(existingSiweMessage, address, signature) {
|
|
20
59
|
this.existingSiweMessage = existingSiweMessage;
|
|
21
60
|
this.address = address;
|
|
22
61
|
this.signature = signature;
|
|
23
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns the existing auth signature after re-validating it.
|
|
65
|
+
*
|
|
66
|
+
* This method verifies that the stored signature and message are still valid
|
|
67
|
+
* before returning them as an EIP4361AuthSignature object.
|
|
68
|
+
*
|
|
69
|
+
* @returns {Promise<EIP4361AuthSignature>} The validated authentication signature
|
|
70
|
+
* @throws {Error} If signature verification fails
|
|
71
|
+
*/
|
|
24
72
|
async getOrCreateAuthSignature() {
|
|
25
|
-
|
|
73
|
+
await generateAndVerifySiweMessage(this.existingSiweMessage, this.signature);
|
|
74
|
+
const scheme = auth_1.EIP4361_AUTH_METHOD;
|
|
26
75
|
return {
|
|
27
76
|
signature: this.signature,
|
|
28
77
|
address: this.address,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-eip4361.js","sourceRoot":"","sources":["../../../../src/providers/eip4361/external-eip4361.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AAInC,
|
|
1
|
+
{"version":3,"file":"external-eip4361.js","sourceRoot":"","sources":["../../../../src/providers/eip4361/external-eip4361.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AAInC,iCAAmE;AACnE,uCAAsD;AAEtD,KAAK,UAAU,4BAA4B,CACzC,OAAe,EACf,SAAiB;IAEjB,MAAM,WAAW,GAAG,IAAI,kBAAW,CAAC,OAAO,CAAC,CAAC;IAC7C,wGAAwG;IACxG,MAAM,WAAW,CAAC,MAAM,CAAC,EAAE,SAAS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wBAAwB;QACnC,MAAM,4BAA4B,CAChC,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,SAAS,CACf,CAAC;QAEF,MAAM,MAAM,GAAG,0BAAmB,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;AA/DD,0EA+DC"}
|
|
@@ -14,6 +14,10 @@ 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
|
+
exports.USER_ADDRESS_PARAM_DEFAULT = void 0;
|
|
18
|
+
__exportStar(require("./eip1271/eip1271"), exports);
|
|
19
|
+
var auth_1 = require("./eip4361/auth");
|
|
20
|
+
Object.defineProperty(exports, "USER_ADDRESS_PARAM_DEFAULT", { enumerable: true, get: function () { return auth_1.USER_ADDRESS_PARAM_DEFAULT; } });
|
|
17
21
|
__exportStar(require("./eip4361/eip4361"), exports);
|
|
18
22
|
__exportStar(require("./eip4361/external-eip4361"), exports);
|
|
19
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,oDAAkC;AAClC,uCAGwB;AADtB,kHAAA,0BAA0B,OAAA;AAE5B,oDAAkC;AAClC,6DAA2C"}
|
package/dist/cjs/storage.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { AuthSignature } from './index';
|
|
2
|
-
export declare class LocalStorage {
|
|
3
|
+
export declare class LocalStorage<T extends AuthSignature> {
|
|
3
4
|
private storage;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
private signatureSchema;
|
|
6
|
+
constructor(signatureSchema: z.ZodSchema);
|
|
7
|
+
getAuthSignature(key: string): T | null;
|
|
8
|
+
setAuthSignature(key: string, authSignature: T): void;
|
|
7
9
|
clear(key: string): void;
|
|
8
10
|
}
|
package/dist/cjs/storage.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LocalStorage = void 0;
|
|
4
|
-
const index_1 = require("./index");
|
|
5
4
|
class BrowserStorage {
|
|
6
5
|
getItem(key) {
|
|
7
6
|
return localStorage.getItem(key);
|
|
@@ -27,18 +26,20 @@ class NodeStorage {
|
|
|
27
26
|
}
|
|
28
27
|
class LocalStorage {
|
|
29
28
|
storage;
|
|
30
|
-
|
|
29
|
+
signatureSchema;
|
|
30
|
+
constructor(signatureSchema) {
|
|
31
31
|
this.storage =
|
|
32
32
|
typeof localStorage === 'undefined'
|
|
33
33
|
? new NodeStorage()
|
|
34
34
|
: new BrowserStorage();
|
|
35
|
+
this.signatureSchema = signatureSchema;
|
|
35
36
|
}
|
|
36
37
|
getAuthSignature(key) {
|
|
37
38
|
const asJson = this.storage.getItem(key);
|
|
38
39
|
if (!asJson) {
|
|
39
40
|
return null;
|
|
40
41
|
}
|
|
41
|
-
return
|
|
42
|
+
return this.signatureSchema.parse(JSON.parse(asJson));
|
|
42
43
|
}
|
|
43
44
|
setAuthSignature(key, authSignature) {
|
|
44
45
|
const asJson = JSON.stringify(authSignature);
|
package/dist/cjs/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file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AC,CAAC,CAAC;IACxD,CAAC;IAEM,gBAAgB,CAAC,GAAW,EAAE,aAAgB;QACnD,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;AA5BD,oCA4BC"}
|
package/dist/es/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/es/auth-sig.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { EthAddressSchema } from '@nucypher/shared';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
export const authSignatureSchema = z.object({
|
|
3
|
+
export const baseAuthSignatureSchema = z.object({
|
|
5
4
|
signature: z.string(),
|
|
6
5
|
address: EthAddressSchema,
|
|
7
|
-
scheme: z.
|
|
8
|
-
typedData:
|
|
6
|
+
scheme: z.string(),
|
|
7
|
+
typedData: z.unknown(),
|
|
9
8
|
});
|
|
10
9
|
//# sourceMappingURL=auth-sig.js.map
|
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;
|
|
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;AAKxB,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,OAAO,EAAE,gBAAgB;IACzB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE;CACvB,CAAC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
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<z.objectUtil.extendShape<{
|
|
14
|
+
signature: z.ZodString;
|
|
15
|
+
address: z.ZodEffects<z.ZodString, string, string>;
|
|
16
|
+
scheme: z.ZodString;
|
|
17
|
+
typedData: z.ZodUnknown;
|
|
18
|
+
}, {
|
|
19
|
+
scheme: z.ZodLiteral<"EIP1271">;
|
|
20
|
+
typedData: z.ZodObject<{
|
|
21
|
+
chain: z.ZodNumber;
|
|
22
|
+
dataHash: z.ZodString;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
chain: number;
|
|
25
|
+
dataHash: string;
|
|
26
|
+
}, {
|
|
27
|
+
chain: number;
|
|
28
|
+
dataHash: string;
|
|
29
|
+
}>;
|
|
30
|
+
}>, "strip", z.ZodTypeAny, {
|
|
31
|
+
signature: string;
|
|
32
|
+
address: string;
|
|
33
|
+
scheme: "EIP1271";
|
|
34
|
+
typedData: {
|
|
35
|
+
chain: number;
|
|
36
|
+
dataHash: string;
|
|
37
|
+
};
|
|
38
|
+
}, {
|
|
39
|
+
signature: string;
|
|
40
|
+
address: string;
|
|
41
|
+
scheme: "EIP1271";
|
|
42
|
+
typedData: {
|
|
43
|
+
chain: number;
|
|
44
|
+
dataHash: string;
|
|
45
|
+
};
|
|
46
|
+
}>;
|
|
47
|
+
export type EIP1271AuthSignature = z.infer<typeof eip1271AuthSignatureSchema>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { baseAuthSignatureSchema } from '../../auth-sig';
|
|
3
|
+
export const EIP1271_AUTH_METHOD = 'EIP1271';
|
|
4
|
+
export const EIP1271TypedDataSchema = z.object({
|
|
5
|
+
chain: z.number().int().nonnegative(),
|
|
6
|
+
dataHash: z.string().startsWith('0x'), // hex string
|
|
7
|
+
});
|
|
8
|
+
export const eip1271AuthSignatureSchema = baseAuthSignatureSchema.extend({
|
|
9
|
+
scheme: z.literal(EIP1271_AUTH_METHOD),
|
|
10
|
+
typedData: EIP1271TypedDataSchema,
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../../src/providers/eip1271/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAE7C,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;IACrC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,aAAa;CACrD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAAG,uBAAuB,CAAC,MAAM,CAAC;IACvE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC;IACtC,SAAS,EAAE,sBAAsB;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,49 @@
|
|
|
1
|
+
import { EIP1271_AUTH_METHOD } from './auth';
|
|
2
|
+
/**
|
|
3
|
+
* EIP1271AuthProvider handles EIP-1271 contract-based authentication.
|
|
4
|
+
* This provider manages authentication signatures from smart contracts that implement EIP-1271's `isValidSignature` solidity function.
|
|
5
|
+
*/
|
|
6
|
+
export class EIP1271AuthProvider {
|
|
7
|
+
contractAddress;
|
|
8
|
+
chain;
|
|
9
|
+
dataHash;
|
|
10
|
+
signature;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new EIP1271AuthProvider for contract-based authentication.
|
|
13
|
+
*
|
|
14
|
+
* @param contractAddress - The Ethereum address of the contract implementing EIP-1271
|
|
15
|
+
* @param chain - The chain ID where the contract is deployed
|
|
16
|
+
* @param dataHash - The hash of the data that was signed
|
|
17
|
+
* @param signature - The signature produced by the contract's signing method
|
|
18
|
+
*/
|
|
19
|
+
constructor(contractAddress, chain, dataHash, signature) {
|
|
20
|
+
this.contractAddress = contractAddress;
|
|
21
|
+
this.chain = chain;
|
|
22
|
+
this.dataHash = dataHash;
|
|
23
|
+
this.signature = signature;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns the authentication signature for the contract.
|
|
27
|
+
*
|
|
28
|
+
* Since contract signatures are created externally, this method simply returns
|
|
29
|
+
* the existing signature and metadata rather than creating a new one.
|
|
30
|
+
*
|
|
31
|
+
* @returns {Promise<EIP1271AuthSignature>} The authentication signature containing:
|
|
32
|
+
* - signature: The contract-generated signature
|
|
33
|
+
* - address: The contract's address
|
|
34
|
+
* - scheme: The authentication scheme (EIP1271)
|
|
35
|
+
* - typedData: Object containing the chain ID and data hash
|
|
36
|
+
*/
|
|
37
|
+
async getOrCreateAuthSignature() {
|
|
38
|
+
return {
|
|
39
|
+
signature: this.signature,
|
|
40
|
+
address: this.contractAddress,
|
|
41
|
+
scheme: EIP1271_AUTH_METHOD,
|
|
42
|
+
typedData: {
|
|
43
|
+
chain: this.chain,
|
|
44
|
+
dataHash: this.dataHash,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=eip1271.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip1271.js","sourceRoot":"","sources":["../../../../src/providers/eip1271/eip1271.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAwB,MAAM,QAAQ,CAAC;AAEnE;;;GAGG;AACH,MAAM,OAAO,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,mBAAmB;YAC3B,SAAS,EAAE;gBACT,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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<z.objectUtil.extendShape<{
|
|
6
|
+
signature: z.ZodString;
|
|
7
|
+
address: z.ZodEffects<z.ZodString, string, string>;
|
|
8
|
+
scheme: z.ZodString;
|
|
9
|
+
typedData: z.ZodUnknown;
|
|
10
|
+
}, {
|
|
11
|
+
scheme: z.ZodLiteral<"EIP4361">;
|
|
12
|
+
typedData: z.ZodEffects<z.ZodString, string, string>;
|
|
13
|
+
}>, "strip", z.ZodTypeAny, {
|
|
14
|
+
signature: string;
|
|
15
|
+
address: string;
|
|
16
|
+
scheme: "EIP4361";
|
|
17
|
+
typedData: string;
|
|
18
|
+
}, {
|
|
19
|
+
signature: string;
|
|
20
|
+
address: string;
|
|
21
|
+
scheme: "EIP4361";
|
|
22
|
+
typedData: string;
|
|
23
|
+
}>;
|
|
24
|
+
export type EIP4361AuthSignature = z.infer<typeof eip4361AuthSignatureSchema>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SiweMessage } from 'siwe';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { baseAuthSignatureSchema } from '../../auth-sig';
|
|
4
|
+
export const EIP4361_AUTH_METHOD = 'EIP4361';
|
|
5
|
+
export const USER_ADDRESS_PARAM_DEFAULT = ':userAddress';
|
|
6
|
+
const isSiweMessage = (message) => {
|
|
7
|
+
try {
|
|
8
|
+
new SiweMessage(message);
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export const EIP4361TypedDataSchema = z
|
|
16
|
+
.string()
|
|
17
|
+
.refine(isSiweMessage, { message: 'Invalid SIWE message' });
|
|
18
|
+
export const eip4361AuthSignatureSchema = baseAuthSignatureSchema.extend({
|
|
19
|
+
scheme: z.literal(EIP4361_AUTH_METHOD),
|
|
20
|
+
typedData: EIP4361TypedDataSchema,
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../../src/providers/eip4361/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAE7C,MAAM,CAAC,MAAM,0BAA0B,GAAG,cAAc,CAAC;AAEzD,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;AAE9D,MAAM,CAAC,MAAM,0BAA0B,GAAG,uBAAuB,CAAC,MAAM,CAAC;IACvE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC;IACtC,SAAS,EAAE,sBAAsB;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
|
}
|