@nucypher/taco-auth 0.4.0-alpha.2 → 0.4.0-alpha.4

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.
@@ -1 +0,0 @@
1
- {"version":3,"file":"external-eip4361.js","sourceRoot":"","sources":["../../../src/providers/external-eip4361.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AAEnC,oDAAuD;AAGvD,MAAa,+BAA+B;IAkBvB;IACA;IACA;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,EAC3B,OAAe,EACf,SAAiB;QAFjB,wBAAmB,GAAnB,mBAAmB,CAAQ;QAC3B,YAAO,GAAP,OAAO,CAAQ;QACf,cAAS,GAAT,SAAS,CAAQ;IACjC,CAAC;IAEG,KAAK,CAAC,wBAAwB;QACnC,MAAM,MAAM,GAAG,mCAAmB,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,3 +0,0 @@
1
- import { z } from 'zod';
2
- export declare const EIP4361_AUTH_METHOD = "EIP4361";
3
- export declare const EIP4361TypedDataSchema: z.ZodEffects<z.ZodString, string, string>;
@@ -1,16 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,18 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import { z } from 'zod';
3
- import { AuthSignature } from '../auth-sig';
4
- export declare const EIP4361TypedDataSchema: z.ZodEffects<z.ZodString, string, string>;
5
- export type EIP4361AuthProviderParams = {
6
- domain: string;
7
- uri: string;
8
- };
9
- export declare class EIP4361AuthProvider {
10
- private readonly provider;
11
- private readonly signer;
12
- private readonly storage;
13
- private readonly providerParams;
14
- constructor(provider: ethers.providers.Provider, signer: ethers.Signer, providerParams?: EIP4361AuthProviderParams);
15
- private getDefaultParameters;
16
- getOrCreateAuthSignature(): Promise<AuthSignature>;
17
- private createSIWEAuthMessage;
18
- }
@@ -1,81 +0,0 @@
1
- import { generateNonce, SiweMessage } from 'siwe';
2
- import { z } from 'zod';
3
- import { EIP4361_AUTH_METHOD } from '../auth-provider';
4
- import { LocalStorage } from '../storage';
5
- const isSiweMessage = (message) => {
6
- try {
7
- new SiweMessage(message);
8
- return true;
9
- }
10
- catch {
11
- return false;
12
- }
13
- };
14
- export const EIP4361TypedDataSchema = z
15
- .string()
16
- .refine(isSiweMessage, { message: 'Invalid SIWE message' });
17
- const ERR_MISSING_SIWE_PARAMETERS = 'Missing default SIWE parameters';
18
- export class EIP4361AuthProvider {
19
- provider;
20
- signer;
21
- storage;
22
- providerParams;
23
- constructor(
24
- // TODO: We only need the provider to fetch the chainId, consider removing it
25
- provider, signer, providerParams) {
26
- this.provider = provider;
27
- this.signer = signer;
28
- this.storage = new LocalStorage();
29
- if (providerParams) {
30
- this.providerParams = providerParams;
31
- }
32
- else {
33
- this.providerParams = this.getDefaultParameters();
34
- }
35
- }
36
- getDefaultParameters() {
37
- if (typeof window !== 'undefined') {
38
- // If we are in a browser environment, we can get the domain and uri from the window object
39
- return {
40
- domain: window.location?.host,
41
- uri: window.location?.origin,
42
- };
43
- }
44
- // If not, we have no choice but to throw an error
45
- throw new Error(ERR_MISSING_SIWE_PARAMETERS);
46
- }
47
- async getOrCreateAuthSignature() {
48
- const address = await this.signer.getAddress();
49
- const storageKey = `eth-${EIP4361_AUTH_METHOD}-message-${address}`;
50
- // If we have a signature in localStorage, return it
51
- const maybeSignature = this.storage.getAuthSignature(storageKey);
52
- if (maybeSignature) {
53
- return maybeSignature;
54
- }
55
- // If at this point we didn't return, we need to create a new message
56
- const authMessage = await this.createSIWEAuthMessage();
57
- this.storage.setAuthSignature(storageKey, authMessage);
58
- return authMessage;
59
- }
60
- async createSIWEAuthMessage() {
61
- const address = await this.signer.getAddress();
62
- const { domain, uri } = this.providerParams;
63
- const version = '1';
64
- const nonce = generateNonce();
65
- const chainId = (await this.provider.getNetwork()).chainId;
66
- const siweMessage = new SiweMessage({
67
- domain,
68
- address,
69
- statement: `${domain} wants you to sign in with your Ethereum account: ${address}`,
70
- uri,
71
- version,
72
- nonce,
73
- chainId,
74
- });
75
- const scheme = EIP4361_AUTH_METHOD;
76
- const message = siweMessage.prepareMessage();
77
- const signature = await this.signer.signMessage(message);
78
- return { signature, address, scheme, typedData: message };
79
- }
80
- }
81
- //# sourceMappingURL=eip4361.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"eip4361.js","sourceRoot":"","sources":["../../../src/providers/eip4361.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,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;AAO9D,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,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,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"}
@@ -1,9 +0,0 @@
1
- import { AuthSignature } from '../auth-sig';
2
- export declare class SingleSignOnEIP4361AuthProvider {
3
- private readonly existingSiweMessage;
4
- private readonly address;
5
- private readonly signature;
6
- static fromExistingSiweInfo(existingSiweMessage: string, signature: string): Promise<SingleSignOnEIP4361AuthProvider>;
7
- private constructor();
8
- getOrCreateAuthSignature(): Promise<AuthSignature>;
9
- }
@@ -1,30 +0,0 @@
1
- import { SiweMessage } from 'siwe';
2
- import { EIP4361_AUTH_METHOD } from '../auth-provider';
3
- export class SingleSignOnEIP4361AuthProvider {
4
- existingSiweMessage;
5
- address;
6
- signature;
7
- static async fromExistingSiweInfo(existingSiweMessage, signature) {
8
- // validation
9
- const siweMessage = new SiweMessage(existingSiweMessage);
10
- await siweMessage.verify({ signature });
11
- // create provider
12
- const authProvider = new SingleSignOnEIP4361AuthProvider(siweMessage.prepareMessage(), siweMessage.address, signature);
13
- return authProvider;
14
- }
15
- constructor(existingSiweMessage, address, signature) {
16
- this.existingSiweMessage = existingSiweMessage;
17
- this.address = address;
18
- this.signature = signature;
19
- }
20
- async getOrCreateAuthSignature() {
21
- const scheme = EIP4361_AUTH_METHOD;
22
- return {
23
- signature: this.signature,
24
- address: this.address,
25
- scheme,
26
- typedData: this.existingSiweMessage,
27
- };
28
- }
29
- }
30
- //# sourceMappingURL=external-eip4361.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"external-eip4361.js","sourceRoot":"","sources":["../../../src/providers/external-eip4361.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAGvD,MAAM,OAAO,+BAA+B;IAkBvB;IACA;IACA;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,EAC3B,OAAe,EACf,SAAiB;QAFjB,wBAAmB,GAAnB,mBAAmB,CAAQ;QAC3B,YAAO,GAAP,OAAO,CAAQ;QACf,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"}