shogun-core 1.2.7 → 1.2.8
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/README.md +0 -1
- package/dist/browser/shogun-core.js +1 -1
- package/dist/browser/shogun-core.js.LICENSE.txt +2 -0
- package/dist/browser/shogun-core.light.js +1 -1
- package/dist/browser/shogun-core.vendors.light.js +1 -1
- package/dist/core.js +31 -71
- package/dist/gundb/{instance.js → gunInstance.js} +135 -115
- package/dist/gundb/index.js +3 -20
- package/dist/plugins/index.js +23 -1
- package/dist/plugins/nostr/index.js +1 -0
- package/dist/plugins/nostr/nostrChain.js +128 -0
- package/dist/plugins/nostr/nostrConnector.js +42 -7
- package/dist/plugins/nostr/nostrConnectorPlugin.js +157 -1
- package/dist/plugins/nostr/nostrSigner.js +343 -0
- package/dist/plugins/oauth/index.js +13 -0
- package/dist/plugins/oauth/oauthChain.js +161 -0
- package/dist/plugins/oauth/oauthConnector.js +542 -0
- package/dist/plugins/oauth/oauthPlugin.js +302 -0
- package/dist/plugins/oauth/types.js +2 -0
- package/dist/plugins/web3/index.js +1 -0
- package/dist/plugins/web3/web3Chain.js +77 -2
- package/dist/plugins/web3/web3Connector.js +159 -37
- package/dist/plugins/web3/web3ConnectorPlugin.js +157 -1
- package/dist/plugins/web3/web3Signer.js +268 -0
- package/dist/plugins/webauthn/webauthnChain.js +78 -0
- package/dist/plugins/webauthn/webauthnPlugin.js +154 -1
- package/dist/plugins/webauthn/webauthnSigner.js +318 -0
- package/dist/storage/storage.js +0 -8
- package/dist/types/core.d.ts +10 -34
- package/dist/types/gundb/gun-es/gun-es.d.ts +1 -0
- package/dist/types/gundb/{instance.d.ts → gunInstance.d.ts} +2 -2
- package/dist/types/gundb/index.d.ts +1 -4
- package/dist/types/plugins/index.d.ts +4 -0
- package/dist/types/plugins/nostr/index.d.ts +1 -0
- package/dist/types/plugins/nostr/nostrConnector.d.ts +3 -2
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +82 -0
- package/dist/types/plugins/nostr/nostrSigner.d.ts +104 -0
- package/dist/types/plugins/oauth/index.d.ts +4 -0
- package/dist/types/plugins/oauth/oauthChain.d.ts +2 -0
- package/dist/types/plugins/oauth/oauthConnector.d.ts +100 -0
- package/dist/types/plugins/oauth/oauthPlugin.d.ts +89 -0
- package/dist/types/plugins/oauth/types.d.ts +106 -0
- package/dist/types/plugins/web3/index.d.ts +1 -0
- package/dist/types/plugins/web3/types.d.ts +1 -0
- package/dist/types/plugins/web3/web3Connector.d.ts +8 -2
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +82 -0
- package/dist/types/plugins/web3/web3Signer.d.ts +93 -0
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +81 -0
- package/dist/types/plugins/webauthn/webauthnSigner.d.ts +90 -0
- package/dist/types/shogun.js +1 -28
- package/dist/types/types/events.d.ts +2 -2
- package/dist/types/types/shogun.d.ts +13 -49
- package/package.json +2 -1
- package/dist/browser.js +0 -107
- package/dist/contracts/base.js +0 -152
- package/dist/contracts/entryPoint.js +0 -407
- package/dist/contracts/index.js +0 -47
- package/dist/contracts/registry.js +0 -259
- package/dist/contracts/relay.js +0 -494
- package/dist/contracts/utils.js +0 -582
- package/dist/types/browser.d.ts +0 -27
- package/dist/types/contracts/base.d.ts +0 -82
- package/dist/types/contracts/entryPoint.d.ts +0 -138
- package/dist/types/contracts/index.d.ts +0 -17
- package/dist/types/contracts/registry.d.ts +0 -97
- package/dist/types/contracts/relay.d.ts +0 -165
- package/dist/types/contracts/utils.d.ts +0 -173
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BasePlugin } from "../base";
|
|
2
2
|
import { ShogunCore } from "../../index";
|
|
3
|
+
import { Web3SigningCredential } from "./web3Signer";
|
|
3
4
|
import { Web3ConnectorCredentials, ConnectionResult, Web3ConectorPluginInterface } from "./types";
|
|
4
5
|
import { ethers } from "ethers";
|
|
5
6
|
import { AuthResult } from "../../types/shogun";
|
|
@@ -11,6 +12,7 @@ export declare class Web3ConnectorPlugin extends BasePlugin implements Web3Conec
|
|
|
11
12
|
version: string;
|
|
12
13
|
description: string;
|
|
13
14
|
private Web3;
|
|
15
|
+
private signer;
|
|
14
16
|
/**
|
|
15
17
|
* @inheritdoc
|
|
16
18
|
*/
|
|
@@ -24,6 +26,11 @@ export declare class Web3ConnectorPlugin extends BasePlugin implements Web3Conec
|
|
|
24
26
|
* @private
|
|
25
27
|
*/
|
|
26
28
|
private assertMetaMask;
|
|
29
|
+
/**
|
|
30
|
+
* Assicura che il signer sia inizializzato
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private assertSigner;
|
|
27
34
|
/**
|
|
28
35
|
* @inheritdoc
|
|
29
36
|
*/
|
|
@@ -60,6 +67,81 @@ export declare class Web3ConnectorPlugin extends BasePlugin implements Web3Conec
|
|
|
60
67
|
* @inheritdoc
|
|
61
68
|
*/
|
|
62
69
|
verifySignature(message: string, signature: string): Promise<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new Web3 signing credential
|
|
72
|
+
* CONSISTENT with normal Web3 approach
|
|
73
|
+
*/
|
|
74
|
+
createSigningCredential(address: string): Promise<Web3SigningCredential>;
|
|
75
|
+
/**
|
|
76
|
+
* Creates an authenticator function for Web3 signing
|
|
77
|
+
*/
|
|
78
|
+
createAuthenticator(address: string): (data: any) => Promise<string>;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a derived key pair from Web3 credential
|
|
81
|
+
*/
|
|
82
|
+
createDerivedKeyPair(address: string, extra?: string[]): Promise<{
|
|
83
|
+
pub: string;
|
|
84
|
+
priv: string;
|
|
85
|
+
epub: string;
|
|
86
|
+
epriv: string;
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* Signs data with derived keys after Web3 verification
|
|
90
|
+
*/
|
|
91
|
+
signWithDerivedKeys(data: any, address: string, extra?: string[]): Promise<string>;
|
|
92
|
+
/**
|
|
93
|
+
* Get signing credential by address
|
|
94
|
+
*/
|
|
95
|
+
getSigningCredential(address: string): Web3SigningCredential | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* List all signing credentials
|
|
98
|
+
*/
|
|
99
|
+
listSigningCredentials(): Web3SigningCredential[];
|
|
100
|
+
/**
|
|
101
|
+
* Remove a signing credential
|
|
102
|
+
*/
|
|
103
|
+
removeSigningCredential(address: string): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Creates a Gun user from Web3 signing credential
|
|
106
|
+
* This ensures the SAME user is created as with normal approach
|
|
107
|
+
*/
|
|
108
|
+
createGunUserFromSigningCredential(address: string): Promise<{
|
|
109
|
+
success: boolean;
|
|
110
|
+
userPub?: string;
|
|
111
|
+
error?: string;
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Get the Gun user public key for a signing credential
|
|
115
|
+
*/
|
|
116
|
+
getGunUserPubFromSigningCredential(address: string): string | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Get the password (for consistency checking)
|
|
119
|
+
*/
|
|
120
|
+
getPassword(address: string): string | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Verify consistency between oneshot and normal approaches
|
|
123
|
+
* This ensures both approaches create the same Gun user
|
|
124
|
+
*/
|
|
125
|
+
verifyConsistency(address: string, expectedUserPub?: string): Promise<{
|
|
126
|
+
consistent: boolean;
|
|
127
|
+
actualUserPub?: string;
|
|
128
|
+
expectedUserPub?: string;
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* Complete oneshot workflow that creates the SAME Gun user as normal approach
|
|
132
|
+
* This is the recommended method for oneshot signing with full consistency
|
|
133
|
+
*/
|
|
134
|
+
setupConsistentOneshotSigning(address: string): Promise<{
|
|
135
|
+
credential: Web3SigningCredential;
|
|
136
|
+
authenticator: (data: any) => Promise<string>;
|
|
137
|
+
gunUser: {
|
|
138
|
+
success: boolean;
|
|
139
|
+
userPub?: string;
|
|
140
|
+
error?: string;
|
|
141
|
+
};
|
|
142
|
+
username: string;
|
|
143
|
+
password: string;
|
|
144
|
+
}>;
|
|
63
145
|
/**
|
|
64
146
|
* Login con Web3
|
|
65
147
|
* @param address - Indirizzo Ethereum
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Web3Connector } from "./web3Connector";
|
|
2
|
+
/**
|
|
3
|
+
* Web3 Signing Credential for oneshot signing
|
|
4
|
+
*/
|
|
5
|
+
export interface Web3SigningCredential {
|
|
6
|
+
address: string;
|
|
7
|
+
signature: string;
|
|
8
|
+
message: string;
|
|
9
|
+
username: string;
|
|
10
|
+
password: string;
|
|
11
|
+
gunUserPub?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Web3 Signer - Provides oneshot signing functionality
|
|
15
|
+
* Similar to webauthn.js but for Web3/MetaMask
|
|
16
|
+
* CONSISTENT with normal Web3 approach
|
|
17
|
+
*/
|
|
18
|
+
export declare class Web3Signer {
|
|
19
|
+
private web3Connector;
|
|
20
|
+
private credentials;
|
|
21
|
+
private readonly MESSAGE_TO_SIGN;
|
|
22
|
+
constructor(web3Connector?: Web3Connector);
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new Web3 signing credential
|
|
25
|
+
* CONSISTENT with normal Web3 approach
|
|
26
|
+
*/
|
|
27
|
+
createSigningCredential(address: string): Promise<Web3SigningCredential>;
|
|
28
|
+
/**
|
|
29
|
+
* Request signature from MetaMask
|
|
30
|
+
* Uses the same approach as normal Web3Connector
|
|
31
|
+
*/
|
|
32
|
+
private requestSignature;
|
|
33
|
+
/**
|
|
34
|
+
* Creates an authenticator function compatible with SEA.sign
|
|
35
|
+
* This is the key function that makes it work like webauthn.js but for Web3
|
|
36
|
+
*/
|
|
37
|
+
createAuthenticator(address: string): (data: any) => Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a derived key pair from Web3 credential
|
|
40
|
+
* CONSISTENT with normal approach: uses password as seed
|
|
41
|
+
*/
|
|
42
|
+
createDerivedKeyPair(address: string, extra?: string[]): Promise<{
|
|
43
|
+
pub: string;
|
|
44
|
+
priv: string;
|
|
45
|
+
epub: string;
|
|
46
|
+
epriv: string;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a Gun user from Web3 credential
|
|
50
|
+
* This ensures the SAME user is created as with normal approach
|
|
51
|
+
*/
|
|
52
|
+
createGunUser(address: string, gunInstance: any): Promise<{
|
|
53
|
+
success: boolean;
|
|
54
|
+
userPub?: string;
|
|
55
|
+
error?: string;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Signs data using Web3 + derived keys
|
|
59
|
+
* This provides a hybrid approach: Web3 for user verification + derived keys for actual signing
|
|
60
|
+
* CONSISTENT with normal approach
|
|
61
|
+
*/
|
|
62
|
+
signWithDerivedKeys(data: any, address: string, extra?: string[]): Promise<string>;
|
|
63
|
+
/**
|
|
64
|
+
* Get the Gun user public key for a credential
|
|
65
|
+
* This allows checking if the same user would be created
|
|
66
|
+
*/
|
|
67
|
+
getGunUserPub(address: string): string | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Get the password (for consistency checking)
|
|
70
|
+
*/
|
|
71
|
+
getPassword(address: string): string | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Check if this credential would create the same Gun user as normal approach
|
|
74
|
+
*/
|
|
75
|
+
verifyConsistency(address: string, expectedUserPub?: string): Promise<{
|
|
76
|
+
consistent: boolean;
|
|
77
|
+
actualUserPub?: string;
|
|
78
|
+
expectedUserPub?: string;
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Get credential by address
|
|
82
|
+
*/
|
|
83
|
+
getCredential(address: string): Web3SigningCredential | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* List all stored credentials
|
|
86
|
+
*/
|
|
87
|
+
listCredentials(): Web3SigningCredential[];
|
|
88
|
+
/**
|
|
89
|
+
* Remove a credential
|
|
90
|
+
*/
|
|
91
|
+
removeCredential(address: string): boolean;
|
|
92
|
+
}
|
|
93
|
+
export default Web3Signer;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BasePlugin } from "../base";
|
|
2
2
|
import { ShogunCore } from "../../index";
|
|
3
|
+
import { WebAuthnSigningCredential } from "./webauthnSigner";
|
|
3
4
|
import { WebauthnPluginInterface } from "./types";
|
|
4
5
|
import { WebAuthnCredentials, CredentialResult } from "./types";
|
|
5
6
|
import { AuthResult } from "../../types/shogun";
|
|
@@ -11,6 +12,7 @@ export declare class WebauthnPlugin extends BasePlugin implements WebauthnPlugin
|
|
|
11
12
|
version: string;
|
|
12
13
|
description: string;
|
|
13
14
|
private webauthn;
|
|
15
|
+
private signer;
|
|
14
16
|
/**
|
|
15
17
|
* @inheritdoc
|
|
16
18
|
*/
|
|
@@ -24,6 +26,11 @@ export declare class WebauthnPlugin extends BasePlugin implements WebauthnPlugin
|
|
|
24
26
|
* @private
|
|
25
27
|
*/
|
|
26
28
|
private assertWebauthn;
|
|
29
|
+
/**
|
|
30
|
+
* Assicura che il signer sia inizializzato
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private assertSigner;
|
|
27
34
|
/**
|
|
28
35
|
* @inheritdoc
|
|
29
36
|
*/
|
|
@@ -51,6 +58,80 @@ export declare class WebauthnPlugin extends BasePlugin implements WebauthnPlugin
|
|
|
51
58
|
success: boolean;
|
|
52
59
|
updatedCredentials?: WebAuthnCredentials;
|
|
53
60
|
}>;
|
|
61
|
+
/**
|
|
62
|
+
* @inheritdoc
|
|
63
|
+
*/
|
|
64
|
+
createSigningCredential(username: string): Promise<WebAuthnSigningCredential>;
|
|
65
|
+
/**
|
|
66
|
+
* @inheritdoc
|
|
67
|
+
*/
|
|
68
|
+
createAuthenticator(credentialId: string): (data: any) => Promise<AuthenticatorAssertionResponse>;
|
|
69
|
+
/**
|
|
70
|
+
* @inheritdoc
|
|
71
|
+
*/
|
|
72
|
+
createDerivedKeyPair(credentialId: string, username: string, extra?: string[]): Promise<{
|
|
73
|
+
pub: string;
|
|
74
|
+
priv: string;
|
|
75
|
+
epub: string;
|
|
76
|
+
epriv: string;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* @inheritdoc
|
|
80
|
+
*/
|
|
81
|
+
signWithDerivedKeys(data: any, credentialId: string, username: string, extra?: string[]): Promise<string>;
|
|
82
|
+
/**
|
|
83
|
+
* @inheritdoc
|
|
84
|
+
*/
|
|
85
|
+
getSigningCredential(credentialId: string): WebAuthnSigningCredential | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* @inheritdoc
|
|
88
|
+
*/
|
|
89
|
+
listSigningCredentials(): WebAuthnSigningCredential[];
|
|
90
|
+
/**
|
|
91
|
+
* @inheritdoc
|
|
92
|
+
*/
|
|
93
|
+
removeSigningCredential(credentialId: string): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a Gun user from WebAuthn signing credential
|
|
96
|
+
* This ensures the SAME user is created as with normal approach
|
|
97
|
+
*/
|
|
98
|
+
createGunUserFromSigningCredential(credentialId: string, username: string): Promise<{
|
|
99
|
+
success: boolean;
|
|
100
|
+
userPub?: string;
|
|
101
|
+
error?: string;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Get the Gun user public key for a signing credential
|
|
105
|
+
*/
|
|
106
|
+
getGunUserPubFromSigningCredential(credentialId: string): string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Get the hashed credential ID (for consistency checking)
|
|
109
|
+
*/
|
|
110
|
+
getHashedCredentialId(credentialId: string): string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Verify consistency between oneshot and normal approaches
|
|
113
|
+
* This ensures both approaches create the same Gun user
|
|
114
|
+
*/
|
|
115
|
+
verifyConsistency(credentialId: string, username: string, expectedUserPub?: string): Promise<{
|
|
116
|
+
consistent: boolean;
|
|
117
|
+
actualUserPub?: string;
|
|
118
|
+
expectedUserPub?: string;
|
|
119
|
+
}>;
|
|
120
|
+
/**
|
|
121
|
+
* Complete oneshot workflow that creates the SAME Gun user as normal approach
|
|
122
|
+
* This is the recommended method for oneshot signing with full consistency
|
|
123
|
+
*/
|
|
124
|
+
setupConsistentOneshotSigning(username: string): Promise<{
|
|
125
|
+
credential: WebAuthnSigningCredential;
|
|
126
|
+
authenticator: (data: any) => Promise<AuthenticatorAssertionResponse>;
|
|
127
|
+
gunUser: {
|
|
128
|
+
success: boolean;
|
|
129
|
+
userPub?: string;
|
|
130
|
+
error?: string;
|
|
131
|
+
};
|
|
132
|
+
pub: string;
|
|
133
|
+
hashedCredentialId: string;
|
|
134
|
+
}>;
|
|
54
135
|
/**
|
|
55
136
|
* Login with WebAuthn
|
|
56
137
|
* This is the recommended method for WebAuthn authentication
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Webauthn } from "./webauthn";
|
|
2
|
+
/**
|
|
3
|
+
* WebAuthn Credential for oneshot signing
|
|
4
|
+
*/
|
|
5
|
+
export interface WebAuthnSigningCredential {
|
|
6
|
+
id: string;
|
|
7
|
+
rawId: ArrayBuffer;
|
|
8
|
+
publicKey: {
|
|
9
|
+
x: string;
|
|
10
|
+
y: string;
|
|
11
|
+
};
|
|
12
|
+
pub: string;
|
|
13
|
+
hashedCredentialId: string;
|
|
14
|
+
gunUserPub?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* WebAuthn Signer - Provides oneshot signing functionality
|
|
18
|
+
* Similar to webauthn.js but integrated with our architecture
|
|
19
|
+
* CONSISTENT with normal WebAuthn approach
|
|
20
|
+
*/
|
|
21
|
+
export declare class WebAuthnSigner {
|
|
22
|
+
private webauthn;
|
|
23
|
+
private credentials;
|
|
24
|
+
constructor(webauthn?: Webauthn);
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new WebAuthn credential for signing
|
|
27
|
+
* Similar to webauthn.js create functionality but CONSISTENT with normal approach
|
|
28
|
+
*/
|
|
29
|
+
createSigningCredential(username: string): Promise<WebAuthnSigningCredential>;
|
|
30
|
+
/**
|
|
31
|
+
* Creates an authenticator function compatible with SEA.sign
|
|
32
|
+
* This is the key function that makes it work like webauthn.js
|
|
33
|
+
*/
|
|
34
|
+
createAuthenticator(credentialId: string): (data: any) => Promise<AuthenticatorAssertionResponse>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a derived key pair from WebAuthn credential
|
|
37
|
+
* CONSISTENT with normal approach: uses hashedCredentialId as password
|
|
38
|
+
*/
|
|
39
|
+
createDerivedKeyPair(credentialId: string, username: string, extra?: string[]): Promise<{
|
|
40
|
+
pub: string;
|
|
41
|
+
priv: string;
|
|
42
|
+
epub: string;
|
|
43
|
+
epriv: string;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a Gun user from WebAuthn credential
|
|
47
|
+
* This ensures the SAME user is created as with normal approach
|
|
48
|
+
*/
|
|
49
|
+
createGunUser(credentialId: string, username: string, gunInstance: any): Promise<{
|
|
50
|
+
success: boolean;
|
|
51
|
+
userPub?: string;
|
|
52
|
+
error?: string;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* Signs data using WebAuthn + derived keys
|
|
56
|
+
* This provides a hybrid approach: WebAuthn for user verification + derived keys for actual signing
|
|
57
|
+
* CONSISTENT with normal approach
|
|
58
|
+
*/
|
|
59
|
+
signWithDerivedKeys(data: any, credentialId: string, username: string, extra?: string[]): Promise<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Get the Gun user public key for a credential
|
|
62
|
+
* This allows checking if the same user would be created
|
|
63
|
+
*/
|
|
64
|
+
getGunUserPub(credentialId: string): string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Get the hashed credential ID (for consistency checking)
|
|
67
|
+
*/
|
|
68
|
+
getHashedCredentialId(credentialId: string): string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Check if this credential would create the same Gun user as normal approach
|
|
71
|
+
*/
|
|
72
|
+
verifyConsistency(credentialId: string, username: string, expectedUserPub?: string): Promise<{
|
|
73
|
+
consistent: boolean;
|
|
74
|
+
actualUserPub?: string;
|
|
75
|
+
expectedUserPub?: string;
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* Get credential by ID
|
|
79
|
+
*/
|
|
80
|
+
getCredential(credentialId: string): WebAuthnSigningCredential | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* List all stored credentials
|
|
83
|
+
*/
|
|
84
|
+
listCredentials(): WebAuthnSigningCredential[];
|
|
85
|
+
/**
|
|
86
|
+
* Remove a credential
|
|
87
|
+
*/
|
|
88
|
+
removeCredential(credentialId: string): boolean;
|
|
89
|
+
}
|
|
90
|
+
export default WebAuthnSigner;
|
package/dist/types/shogun.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CorePlugins = exports.PluginCategory = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Standard plugin categories in ShogunCore
|
|
6
6
|
*/
|
|
@@ -29,30 +29,3 @@ var CorePlugins;
|
|
|
29
29
|
/** Bitcoin wallet plugin */
|
|
30
30
|
CorePlugins["Nostr"] = "nostr";
|
|
31
31
|
})(CorePlugins || (exports.CorePlugins = CorePlugins = {}));
|
|
32
|
-
/**
|
|
33
|
-
* Authentication states for the state machine
|
|
34
|
-
*/
|
|
35
|
-
var AuthState;
|
|
36
|
-
(function (AuthState) {
|
|
37
|
-
AuthState["UNAUTHENTICATED"] = "unauthenticated";
|
|
38
|
-
AuthState["AUTHENTICATING"] = "authenticating";
|
|
39
|
-
AuthState["AUTHENTICATED"] = "authenticated";
|
|
40
|
-
AuthState["AUTHENTICATION_FAILED"] = "authentication_failed";
|
|
41
|
-
AuthState["WALLET_INITIALIZING"] = "wallet_initializing";
|
|
42
|
-
AuthState["WALLET_READY"] = "wallet_ready";
|
|
43
|
-
AuthState["ERROR"] = "error";
|
|
44
|
-
})(AuthState || (exports.AuthState = AuthState = {}));
|
|
45
|
-
/**
|
|
46
|
-
* Authentication events that trigger state transitions
|
|
47
|
-
*/
|
|
48
|
-
var AuthEvent;
|
|
49
|
-
(function (AuthEvent) {
|
|
50
|
-
AuthEvent["LOGIN_START"] = "login_start";
|
|
51
|
-
AuthEvent["LOGIN_SUCCESS"] = "login_success";
|
|
52
|
-
AuthEvent["LOGIN_FAILED"] = "login_failed";
|
|
53
|
-
AuthEvent["LOGOUT"] = "logout";
|
|
54
|
-
AuthEvent["WALLET_INIT_START"] = "wallet_init_start";
|
|
55
|
-
AuthEvent["WALLET_INIT_SUCCESS"] = "wallet_init_success";
|
|
56
|
-
AuthEvent["WALLET_INIT_FAILED"] = "wallet_init_failed";
|
|
57
|
-
AuthEvent["ERROR"] = "error";
|
|
58
|
-
})(AuthEvent || (exports.AuthEvent = AuthEvent = {}));
|
|
@@ -4,12 +4,12 @@ import { EventEmitter } from "../utils/eventEmitter";
|
|
|
4
4
|
* @interface AuthEventData
|
|
5
5
|
* @property {string} userPub - The user's public key
|
|
6
6
|
* @property {string} [username] - Optional username
|
|
7
|
-
* @property {"password" | "webauthn" | "
|
|
7
|
+
* @property {"password" | "webauthn" | "web3" | "nostr" | "oauth" } method - Authentication method used
|
|
8
8
|
*/
|
|
9
9
|
export interface AuthEventData {
|
|
10
10
|
userPub: string;
|
|
11
11
|
username?: string;
|
|
12
|
-
method: "password" | "webauthn" | "
|
|
12
|
+
method: "password" | "webauthn" | "web3" | "nostr" | "oauth";
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Interface representing wallet event data
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IGunInstance } from "gun/types";
|
|
2
2
|
import { ethers } from "ethers";
|
|
3
3
|
import { ShogunError } from "../utils/errorHandler";
|
|
4
|
-
import {
|
|
4
|
+
import { GunInstance } from "../gundb/gunInstance";
|
|
5
5
|
import { GunRxJS } from "../gundb/rxjs-integration";
|
|
6
6
|
import { ShogunPlugin, PluginManager } from "./plugin";
|
|
7
7
|
import { ShogunStorage } from "../storage/storage";
|
|
@@ -31,13 +31,19 @@ export declare enum CorePlugins {
|
|
|
31
31
|
/** Bitcoin wallet plugin */
|
|
32
32
|
Nostr = "nostr"
|
|
33
33
|
}
|
|
34
|
-
export type AuthMethod = "password" | "webauthn" | "web3" | "nostr";
|
|
34
|
+
export type AuthMethod = "password" | "webauthn" | "web3" | "nostr" | "oauth";
|
|
35
35
|
export interface AuthResult {
|
|
36
36
|
success: boolean;
|
|
37
37
|
error?: string;
|
|
38
38
|
userPub?: string;
|
|
39
39
|
username?: string;
|
|
40
|
+
sessionToken?: string;
|
|
40
41
|
authMethod?: AuthMethod;
|
|
42
|
+
redirectUrl?: string;
|
|
43
|
+
pendingAuth?: boolean;
|
|
44
|
+
message?: string;
|
|
45
|
+
provider?: string;
|
|
46
|
+
isNewUser?: boolean;
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
49
|
* Sign up result interface
|
|
@@ -53,7 +59,7 @@ export interface SignUpResult {
|
|
|
53
59
|
}
|
|
54
60
|
export interface IShogunCore extends PluginManager {
|
|
55
61
|
gun: IGunInstance<any>;
|
|
56
|
-
gundb:
|
|
62
|
+
gundb: GunInstance;
|
|
57
63
|
rx: GunRxJS;
|
|
58
64
|
storage: ShogunStorage;
|
|
59
65
|
config: ShogunSDKConfig;
|
|
@@ -108,6 +114,10 @@ export interface ShogunSDKConfig {
|
|
|
108
114
|
nostr?: {
|
|
109
115
|
enabled?: boolean;
|
|
110
116
|
};
|
|
117
|
+
oauth?: {
|
|
118
|
+
enabled?: boolean;
|
|
119
|
+
providers?: Record<string, any>;
|
|
120
|
+
};
|
|
111
121
|
logging?: LoggingConfig;
|
|
112
122
|
timeouts?: {
|
|
113
123
|
login?: number;
|
|
@@ -133,49 +143,3 @@ export interface ShogunEvents {
|
|
|
133
143
|
}) => void;
|
|
134
144
|
"auth:logout": (data: Record<string, never>) => void;
|
|
135
145
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Authentication states for the state machine
|
|
138
|
-
*/
|
|
139
|
-
export declare enum AuthState {
|
|
140
|
-
UNAUTHENTICATED = "unauthenticated",
|
|
141
|
-
AUTHENTICATING = "authenticating",
|
|
142
|
-
AUTHENTICATED = "authenticated",
|
|
143
|
-
AUTHENTICATION_FAILED = "authentication_failed",
|
|
144
|
-
WALLET_INITIALIZING = "wallet_initializing",
|
|
145
|
-
WALLET_READY = "wallet_ready",
|
|
146
|
-
ERROR = "error"
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Authentication events that trigger state transitions
|
|
150
|
-
*/
|
|
151
|
-
export declare enum AuthEvent {
|
|
152
|
-
LOGIN_START = "login_start",
|
|
153
|
-
LOGIN_SUCCESS = "login_success",
|
|
154
|
-
LOGIN_FAILED = "login_failed",
|
|
155
|
-
LOGOUT = "logout",
|
|
156
|
-
WALLET_INIT_START = "wallet_init_start",
|
|
157
|
-
WALLET_INIT_SUCCESS = "wallet_init_success",
|
|
158
|
-
WALLET_INIT_FAILED = "wallet_init_failed",
|
|
159
|
-
ERROR = "error"
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Authentication state machine context
|
|
163
|
-
*/
|
|
164
|
-
export interface AuthContext {
|
|
165
|
-
userPub?: string;
|
|
166
|
-
username?: string;
|
|
167
|
-
error?: string;
|
|
168
|
-
walletCount?: number;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Authentication state machine interface
|
|
172
|
-
*/
|
|
173
|
-
export interface AuthStateMachine {
|
|
174
|
-
currentState: AuthState;
|
|
175
|
-
context: AuthContext;
|
|
176
|
-
transition(event: AuthEvent, data?: Partial<AuthContext>): void;
|
|
177
|
-
canTransition(event: AuthEvent): boolean;
|
|
178
|
-
isAuthenticated(): boolean;
|
|
179
|
-
isWalletReady(): boolean;
|
|
180
|
-
waitForState(targetState: AuthState, timeoutMs?: number): Promise<boolean>;
|
|
181
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shogun-core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
4
4
|
"description": "SHOGUN SDK - Core library for Shogun SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"ethers": "^6.13.5",
|
|
48
48
|
"gun": "^0.2020.1240",
|
|
49
49
|
"keccak256": "^1.0.6",
|
|
50
|
+
"paillier-bigint": "^3.4.3",
|
|
50
51
|
"qs": "^6.14.0",
|
|
51
52
|
"rxjs": "^7.8.2",
|
|
52
53
|
"uuid": "^11.1.0",
|
package/dist/browser.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ShogunCore = exports.modules = void 0;
|
|
40
|
-
exports.initShogunBrowser = initShogunBrowser;
|
|
41
|
-
const index_1 = require("./index");
|
|
42
|
-
Object.defineProperty(exports, "ShogunCore", { enumerable: true, get: function () { return index_1.ShogunCore; } });
|
|
43
|
-
const webauthn_1 = require("./plugins/webauthn");
|
|
44
|
-
const web3_1 = require("./plugins/web3");
|
|
45
|
-
// Lazy loading modules - organized by functionality
|
|
46
|
-
const lazyModules = {
|
|
47
|
-
// Authentication modules
|
|
48
|
-
webauthn: {
|
|
49
|
-
webauthn: () => Promise.resolve().then(() => __importStar(require("./plugins/webauthn/webauthn"))),
|
|
50
|
-
},
|
|
51
|
-
// Web3 connection modules
|
|
52
|
-
web3: {
|
|
53
|
-
web3Connector: () => Promise.resolve().then(() => __importStar(require("./plugins/web3/web3ConnectorPlugin"))),
|
|
54
|
-
},
|
|
55
|
-
nostr: {
|
|
56
|
-
nostrConnector: () => Promise.resolve().then(() => __importStar(require("./plugins/nostr/nostrConnectorPlugin"))),
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
// Instance tracking
|
|
60
|
-
let shogunCoreInstance = null;
|
|
61
|
-
let gun = null;
|
|
62
|
-
/**
|
|
63
|
-
* Function to initialize Shogun in a browser environment
|
|
64
|
-
*
|
|
65
|
-
* @param config - Configuration for the Shogun SDK
|
|
66
|
-
* @returns A new instance of ShogunCore
|
|
67
|
-
*
|
|
68
|
-
* @important For production use:
|
|
69
|
-
* - Always set custom GunDB peers via config.gundb.peers or config.peers
|
|
70
|
-
* - Always set a valid Ethereum RPC provider URL via config.providerUrl
|
|
71
|
-
* - Default values are provided only for development and testing
|
|
72
|
-
*/
|
|
73
|
-
function initShogunBrowser(config) {
|
|
74
|
-
// Apply default browser settings
|
|
75
|
-
const browserConfig = {
|
|
76
|
-
...config,
|
|
77
|
-
};
|
|
78
|
-
// Create a new ShogunCore instance with browser-optimized configuration
|
|
79
|
-
shogunCoreInstance = new index_1.ShogunCore(browserConfig);
|
|
80
|
-
gun = shogunCoreInstance?.gun;
|
|
81
|
-
(0, webauthn_1.webauthnChain)();
|
|
82
|
-
(0, web3_1.web3Chain)();
|
|
83
|
-
// Support use as a global variable when included via <script>
|
|
84
|
-
if (typeof window !== "undefined") {
|
|
85
|
-
window.shogun = shogunCoreInstance;
|
|
86
|
-
window.gun = gun;
|
|
87
|
-
}
|
|
88
|
-
return shogunCoreInstance;
|
|
89
|
-
}
|
|
90
|
-
// Export lazy loading modules in a more organized structure
|
|
91
|
-
exports.modules = {
|
|
92
|
-
webauthn: {
|
|
93
|
-
loadWebAuthn: lazyModules.webauthn.webauthn,
|
|
94
|
-
},
|
|
95
|
-
web3: {
|
|
96
|
-
loadMetaMask: lazyModules.web3.web3Connector,
|
|
97
|
-
},
|
|
98
|
-
nostr: {
|
|
99
|
-
loadNostrConnector: lazyModules.nostr.nostrConnector,
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
// Export types and interfaces
|
|
103
|
-
__exportStar(require("./types/shogun"), exports);
|
|
104
|
-
// Make initialization function available globally when in browser
|
|
105
|
-
if (typeof window !== "undefined") {
|
|
106
|
-
window.initShogunBrowser = initShogunBrowser;
|
|
107
|
-
}
|