shogun-core 3.0.4 → 3.0.6

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.
Files changed (93) hide show
  1. package/dist/browser/shogun-core.js +91002 -0
  2. package/dist/browser/shogun-core.js.map +1 -0
  3. package/dist/config/simplified-config.js +230 -0
  4. package/dist/core.js +338 -0
  5. package/dist/gundb/crypto.js +268 -0
  6. package/dist/gundb/db.js +1829 -0
  7. package/dist/gundb/derive.js +229 -0
  8. package/dist/gundb/errors.js +66 -0
  9. package/dist/gundb/index.js +6 -0
  10. package/dist/gundb/rxjs.js +445 -0
  11. package/dist/gundb/simple-api.js +438 -0
  12. package/dist/gundb/types.js +4 -0
  13. package/dist/index.js +16 -0
  14. package/dist/interfaces/common.js +1 -0
  15. package/dist/interfaces/events.js +36 -0
  16. package/dist/interfaces/plugin.js +1 -0
  17. package/dist/interfaces/shogun.js +34 -0
  18. package/dist/managers/AuthManager.js +225 -0
  19. package/dist/managers/CoreInitializer.js +227 -0
  20. package/dist/managers/EventManager.js +67 -0
  21. package/dist/managers/PluginManager.js +296 -0
  22. package/dist/migration-test.js +91 -0
  23. package/dist/plugins/base.js +47 -0
  24. package/dist/plugins/index.js +15 -0
  25. package/dist/plugins/nostr/index.js +4 -0
  26. package/dist/plugins/nostr/nostrConnector.js +413 -0
  27. package/dist/plugins/nostr/nostrConnectorPlugin.js +446 -0
  28. package/dist/plugins/nostr/nostrSigner.js +313 -0
  29. package/dist/plugins/nostr/types.js +1 -0
  30. package/dist/plugins/oauth/index.js +3 -0
  31. package/dist/plugins/oauth/oauthConnector.js +753 -0
  32. package/dist/plugins/oauth/oauthPlugin.js +396 -0
  33. package/dist/plugins/oauth/types.js +1 -0
  34. package/dist/plugins/web3/index.js +4 -0
  35. package/dist/plugins/web3/types.js +1 -0
  36. package/dist/plugins/web3/web3Connector.js +528 -0
  37. package/dist/plugins/web3/web3ConnectorPlugin.js +448 -0
  38. package/dist/plugins/web3/web3Signer.js +308 -0
  39. package/dist/plugins/webauthn/index.js +3 -0
  40. package/dist/plugins/webauthn/types.js +11 -0
  41. package/dist/plugins/webauthn/webauthn.js +478 -0
  42. package/dist/plugins/webauthn/webauthnPlugin.js +398 -0
  43. package/dist/plugins/webauthn/webauthnSigner.js +304 -0
  44. package/dist/storage/storage.js +147 -0
  45. package/dist/types/config/simplified-config.d.ts +114 -0
  46. package/dist/types/core.d.ts +305 -0
  47. package/dist/types/gundb/crypto.d.ts +95 -0
  48. package/dist/types/gundb/db.d.ts +401 -0
  49. package/dist/types/gundb/derive.d.ts +21 -0
  50. package/dist/types/gundb/errors.d.ts +42 -0
  51. package/dist/types/gundb/index.d.ts +3 -0
  52. package/dist/types/gundb/rxjs.d.ts +110 -0
  53. package/dist/types/gundb/simple-api.d.ts +90 -0
  54. package/dist/types/gundb/types.d.ts +264 -0
  55. package/dist/types/index.d.ts +14 -0
  56. package/dist/types/interfaces/common.d.ts +85 -0
  57. package/dist/types/interfaces/events.d.ts +131 -0
  58. package/dist/types/interfaces/plugin.d.ts +162 -0
  59. package/dist/types/interfaces/shogun.d.ts +215 -0
  60. package/dist/types/managers/AuthManager.d.ts +72 -0
  61. package/dist/types/managers/CoreInitializer.d.ts +40 -0
  62. package/dist/types/managers/EventManager.d.ts +49 -0
  63. package/dist/types/managers/PluginManager.d.ts +145 -0
  64. package/dist/types/migration-test.d.ts +16 -0
  65. package/dist/types/plugins/base.d.ts +35 -0
  66. package/dist/types/plugins/index.d.ts +14 -0
  67. package/dist/types/plugins/nostr/index.d.ts +4 -0
  68. package/dist/types/plugins/nostr/nostrConnector.d.ts +119 -0
  69. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +163 -0
  70. package/dist/types/plugins/nostr/nostrSigner.d.ts +105 -0
  71. package/dist/types/plugins/nostr/types.d.ts +122 -0
  72. package/dist/types/plugins/oauth/index.d.ts +3 -0
  73. package/dist/types/plugins/oauth/oauthConnector.d.ts +110 -0
  74. package/dist/types/plugins/oauth/oauthPlugin.d.ts +91 -0
  75. package/dist/types/plugins/oauth/types.d.ts +114 -0
  76. package/dist/types/plugins/web3/index.d.ts +4 -0
  77. package/dist/types/plugins/web3/types.d.ts +107 -0
  78. package/dist/types/plugins/web3/web3Connector.d.ts +129 -0
  79. package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +160 -0
  80. package/dist/types/plugins/web3/web3Signer.d.ts +114 -0
  81. package/dist/types/plugins/webauthn/index.d.ts +3 -0
  82. package/dist/types/plugins/webauthn/types.d.ts +162 -0
  83. package/dist/types/plugins/webauthn/webauthn.d.ts +129 -0
  84. package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +158 -0
  85. package/dist/types/plugins/webauthn/webauthnSigner.d.ts +91 -0
  86. package/dist/types/storage/storage.d.ts +50 -0
  87. package/dist/types/utils/errorHandler.d.ts +119 -0
  88. package/dist/types/utils/eventEmitter.d.ts +39 -0
  89. package/dist/types/utils/validation.d.ts +27 -0
  90. package/dist/utils/errorHandler.js +241 -0
  91. package/dist/utils/eventEmitter.js +76 -0
  92. package/dist/utils/validation.js +72 -0
  93. package/package.json +1 -1
@@ -0,0 +1,114 @@
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
+ * Authenticate with existing pair (for login)
50
+ * This generates the deterministic pair from address and authenticates with GunDB
51
+ * GunDB will recognize the user because the pair is deterministic
52
+ */
53
+ authenticateWithExistingPair(address: string, gunInstance: any): Promise<{
54
+ success: boolean;
55
+ userPub?: string;
56
+ error?: string;
57
+ }>;
58
+ /**
59
+ * Creates a derived key pair directly from address (deterministic)
60
+ * This ensures the same pair is generated every time for the same address
61
+ */
62
+ createDerivedKeyPairFromAddress(address: string, extra?: string[]): Promise<{
63
+ pub: string;
64
+ priv: string;
65
+ epub: string;
66
+ epriv: string;
67
+ }>;
68
+ /**
69
+ * Creates a Gun user from Web3 credential
70
+ * This ensures the SAME user is created as with normal approach
71
+ * FIX: Use derived pair instead of username/password for GunDB auth
72
+ */
73
+ createGunUser(address: string, gunInstance: any): Promise<{
74
+ success: boolean;
75
+ userPub?: string;
76
+ error?: string;
77
+ }>;
78
+ /**
79
+ * Signs data using Web3 + derived keys
80
+ * This provides a hybrid approach: Web3 for user verification + derived keys for actual signing
81
+ * CONSISTENT with normal approach
82
+ */
83
+ signWithDerivedKeys(data: any, address: string, extra?: string[]): Promise<string>;
84
+ /**
85
+ * Get the Gun user public key for a credential
86
+ * This allows checking if the same user would be created
87
+ */
88
+ getGunUserPub(address: string): Promise<string | undefined>;
89
+ /**
90
+ * Get the password (for consistency checking)
91
+ */
92
+ getPassword(address: string): string | undefined;
93
+ /**
94
+ * Check if this credential would create the same Gun user as normal approach
95
+ */
96
+ verifyConsistency(address: string, expectedUserPub?: string): Promise<{
97
+ consistent: boolean;
98
+ actualUserPub?: string;
99
+ expectedUserPub?: string;
100
+ }>;
101
+ /**
102
+ * Get credential by address
103
+ */
104
+ getCredential(address: string): Web3SigningCredential | undefined;
105
+ /**
106
+ * List all stored credentials
107
+ */
108
+ listCredentials(): Web3SigningCredential[];
109
+ /**
110
+ * Remove a credential
111
+ */
112
+ removeCredential(address: string): boolean;
113
+ }
114
+ export default Web3Signer;
@@ -0,0 +1,3 @@
1
+ export * from "./webauthnPlugin";
2
+ export * from "./types";
3
+ export * from "./webauthn";
@@ -0,0 +1,162 @@
1
+ import { AuthResult, SignUpResult } from "../../interfaces/shogun";
2
+ import { BaseEvent, BaseConfig, BaseDeviceInfo, BaseResult, BaseAuthResult } from "../../interfaces/common";
3
+ /**
4
+ * WebAuthn types definitions
5
+ */
6
+ /**
7
+ * WebAuthn device information
8
+ */
9
+ export interface DeviceInfo extends BaseDeviceInfo {
10
+ registeredBy?: string;
11
+ }
12
+ /**
13
+ * WebAuthn credentials storage
14
+ */
15
+ export interface WebAuthnCredentials {
16
+ salt: string;
17
+ timestamp: number;
18
+ credentials: Record<string, DeviceInfo>;
19
+ }
20
+ /**
21
+ * Result of credential operations
22
+ */
23
+ export interface CredentialResult extends BaseAuthResult {
24
+ credentialId?: string;
25
+ deviceInfo?: DeviceInfo;
26
+ webAuthnCredentials?: WebAuthnCredentials;
27
+ publicKey?: ArrayBuffer | null;
28
+ }
29
+ /**
30
+ * WebAuthn configuration options
31
+ */
32
+ export interface WebAuthnConfig extends BaseConfig {
33
+ rpName: string;
34
+ rpId?: string;
35
+ userVerification?: UserVerificationRequirement;
36
+ attestation?: AttestationConveyancePreference;
37
+ authenticatorAttachment?: AuthenticatorAttachment;
38
+ requireResidentKey?: boolean;
39
+ }
40
+ /**
41
+ * WebAuthn event types
42
+ */
43
+ export declare enum WebAuthnEventType {
44
+ DEVICE_REGISTERED = "deviceRegistered",
45
+ DEVICE_REMOVED = "deviceRemoved",
46
+ AUTHENTICATION_SUCCESS = "authenticationSuccess",
47
+ AUTHENTICATION_FAILED = "authenticationFailed",
48
+ ERROR = "error"
49
+ }
50
+ /**
51
+ * WebAuthn event data
52
+ */
53
+ export interface WebAuthnEvent extends BaseEvent {
54
+ type: WebAuthnEventType;
55
+ }
56
+ /**
57
+ * WebAuthn operation options
58
+ */
59
+ export interface WebAuthnOperationOptions extends BaseConfig {
60
+ userVerification?: UserVerificationRequirement;
61
+ attestation?: AttestationConveyancePreference;
62
+ }
63
+ /**
64
+ * WebAuthn credential data
65
+ */
66
+ export interface WebAuthnCredentialData {
67
+ id: string;
68
+ rawId: ArrayBuffer;
69
+ response: {
70
+ clientDataJSON: ArrayBuffer;
71
+ attestationObject?: ArrayBuffer;
72
+ authenticatorData?: ArrayBuffer;
73
+ signature?: ArrayBuffer;
74
+ userHandle?: ArrayBuffer;
75
+ getPublicKey?: () => ArrayBuffer;
76
+ };
77
+ type: string;
78
+ getClientExtensionResults: () => AuthenticationExtensionsClientOutputs;
79
+ }
80
+ /**
81
+ * WebAuthn verification result
82
+ */
83
+ export interface WebAuthnVerificationResult extends BaseResult {
84
+ username?: string;
85
+ credentialId?: string;
86
+ error?: string;
87
+ }
88
+ /**
89
+ * WebAuthn credential creation options with extensions
90
+ */
91
+ export interface WebAuthnCredentialCreationOptions extends PublicKeyCredentialCreationOptions {
92
+ signal?: AbortSignal;
93
+ }
94
+ /**
95
+ * Interfaccia per il plugin WebAuthn
96
+ */
97
+ export interface WebauthnPluginInterface {
98
+ /**
99
+ * Verifica se WebAuthn è supportato nel browser corrente
100
+ * @returns true se WebAuthn è supportato, false altrimenti
101
+ */
102
+ isSupported(): boolean;
103
+ /**
104
+ * Genera credenziali WebAuthn
105
+ * @param username Nome utente
106
+ * @param existingCredential Credenziali esistenti (opzionale)
107
+ * @param isLogin Flag che indica se è per login
108
+ * @returns Promise con il risultato dell'operazione
109
+ */
110
+ generateCredentials(username: string, existingCredential?: WebAuthnCredentials | null, isLogin?: boolean): Promise<CredentialResult>;
111
+ /**
112
+ * Crea un nuovo account WebAuthn
113
+ * @param username Nome utente
114
+ * @param credentials Credenziali WebAuthn
115
+ * @param isNewDevice Flag che indica se è un nuovo dispositivo
116
+ * @returns Promise con il risultato dell'operazione
117
+ */
118
+ createAccount(username: string, credentials: WebAuthnCredentials | null, isNewDevice?: boolean): Promise<CredentialResult>;
119
+ /**
120
+ * Autentica un utente con WebAuthn
121
+ * @param username Nome utente
122
+ * @param salt Salt per l'autenticazione
123
+ * @param options Opzioni per l'operazione
124
+ * @returns Promise con il risultato dell'autenticazione
125
+ */
126
+ authenticateUser(username: string, salt: string | null, options?: any): Promise<CredentialResult>;
127
+ /**
128
+ * Interrompe un tentativo di autenticazione in corso
129
+ */
130
+ abortAuthentication(): void;
131
+ /**
132
+ * Rimuove un dispositivo WebAuthn
133
+ * @param username Nome utente
134
+ * @param credentialId ID della credenziale
135
+ * @param credentials Credenziali WebAuthn
136
+ * @returns Promise con il risultato dell'operazione
137
+ */
138
+ removeDevice(username: string, credentialId: string, credentials: WebAuthnCredentials): Promise<{
139
+ success: boolean;
140
+ updatedCredentials?: WebAuthnCredentials;
141
+ }>;
142
+ /**
143
+ * Login con WebAuthn
144
+ * @param username Nome utente
145
+ * @returns Promise con il risultato dell'operazione
146
+ */
147
+ login(username: string): Promise<AuthResult>;
148
+ /**
149
+ * Signup con WebAuthn
150
+ * @param username Nome utente
151
+ * @returns Promise con il risultato dell'operazione
152
+ */
153
+ signUp(username: string): Promise<SignUpResult>;
154
+ }
155
+ export interface WebAuthnUniformCredentials {
156
+ success: boolean;
157
+ username: string;
158
+ key: any;
159
+ credentialId: string;
160
+ publicKey?: ArrayBuffer | null;
161
+ error?: string;
162
+ }
@@ -0,0 +1,129 @@
1
+ import { EventEmitter } from "../../utils/eventEmitter";
2
+ import { DeviceInfo, WebAuthnCredentials, CredentialResult, WebAuthnConfig, WebAuthnOperationOptions } from "./types";
3
+ import { IGunInstance } from "gun";
4
+ /**
5
+ * Extends Window interface to include WebauthnAuth
6
+ */
7
+ declare global {
8
+ interface Window {
9
+ Webauthn?: typeof Webauthn;
10
+ }
11
+ }
12
+ /**
13
+ * Extends NodeJS Global interface to include WebauthnAuth
14
+ */
15
+ declare global {
16
+ namespace NodeJS {
17
+ interface Global {
18
+ Webauthn?: typeof Webauthn;
19
+ }
20
+ }
21
+ }
22
+ /**
23
+ * Main WebAuthn class for authentication management
24
+ */
25
+ export declare class Webauthn extends EventEmitter {
26
+ private readonly config;
27
+ private readonly gunInstance?;
28
+ private credential;
29
+ private abortController;
30
+ /**
31
+ * Creates a new WebAuthn instance
32
+ */
33
+ constructor(gunInstance?: IGunInstance, config?: Partial<WebAuthnConfig>);
34
+ /**
35
+ * Validates a username
36
+ */
37
+ validateUsername(username: string): void;
38
+ /**
39
+ * Creates a new WebAuthn account with retry logic
40
+ */
41
+ createAccount(username: string, credentials: WebAuthnCredentials | null, isNewDevice?: boolean): Promise<CredentialResult>;
42
+ /**
43
+ * Authenticates a user with timeout and abort handling
44
+ */
45
+ authenticateUser(username: string, salt: string | null, options?: WebAuthnOperationOptions): Promise<CredentialResult>;
46
+ /**
47
+ * Aborts current authentication attempt
48
+ */
49
+ abortAuthentication(): void;
50
+ /**
51
+ * Gets device information
52
+ */
53
+ private getDeviceInfo;
54
+ /**
55
+ * Gets platform information
56
+ */
57
+ private getPlatformInfo;
58
+ /**
59
+ * Generates a challenge for WebAuthn operations
60
+ */
61
+ private generateChallenge;
62
+ /**
63
+ * Gets cryptographically secure random bytes
64
+ */
65
+ private getRandomBytes;
66
+ /**
67
+ * Converts Uint8Array to hexadecimal string
68
+ */
69
+ private uint8ArrayToHex;
70
+ /**
71
+ * Converts ArrayBuffer to URL-safe base64 string
72
+ */
73
+ private bufferToBase64;
74
+ /**
75
+ * Generates credentials from username and salt
76
+ */
77
+ private generateCredentialsFromSalt;
78
+ /**
79
+ * Checks if WebAuthn is supported
80
+ */
81
+ isSupported(): boolean;
82
+ /**
83
+ * Creates a WebAuthn credential for registration
84
+ */
85
+ private createCredential;
86
+ /**
87
+ * Generates WebAuthn credentials (uniforme con altri plugin)
88
+ */
89
+ generateCredentials(username: string, existingCredential?: WebAuthnCredentials | null, isLogin?: boolean): Promise<{
90
+ success: boolean;
91
+ username: string;
92
+ key: any;
93
+ credentialId: string;
94
+ publicKey?: ArrayBuffer | null;
95
+ error?: string;
96
+ }>;
97
+ /**
98
+ * Verifies a credential
99
+ */
100
+ private verifyCredential;
101
+ /**
102
+ * Removes device credentials
103
+ */
104
+ removeDevice(username: string, credentialId: string, credentials: WebAuthnCredentials): Promise<{
105
+ success: boolean;
106
+ updatedCredentials?: WebAuthnCredentials;
107
+ }>;
108
+ /**
109
+ * Signs data with the credential
110
+ */
111
+ sign(data: Record<string, unknown>): Promise<unknown>;
112
+ }
113
+ export type { WebAuthnCredentials, DeviceInfo, CredentialResult };
114
+ export declare function deriveWebauthnKeys(username: string, credentialId: string): Promise<{
115
+ pub: string;
116
+ priv: string;
117
+ epub: string;
118
+ epriv: string;
119
+ secp256k1Bitcoin: {
120
+ privateKey: string;
121
+ publicKey: string;
122
+ address: string;
123
+ };
124
+ secp256k1Ethereum: {
125
+ privateKey: string;
126
+ publicKey: string;
127
+ address: string;
128
+ };
129
+ }>;
@@ -0,0 +1,158 @@
1
+ import { BasePlugin } from "../base";
2
+ import { ShogunCore } from "../../core";
3
+ import { WebAuthnSigningCredential } from "./webauthnSigner";
4
+ import { WebAuthnCredentials, CredentialResult, WebauthnPluginInterface, WebAuthnUniformCredentials } from "./types";
5
+ import { AuthResult, SignUpResult } from "../../interfaces/shogun";
6
+ /**
7
+ * Plugin per la gestione delle funzionalità WebAuthn in ShogunCore
8
+ */
9
+ export declare class WebauthnPlugin extends BasePlugin implements WebauthnPluginInterface {
10
+ name: string;
11
+ version: string;
12
+ description: string;
13
+ private webauthn;
14
+ private signer;
15
+ /**
16
+ * @inheritdoc
17
+ */
18
+ initialize(core: ShogunCore): void;
19
+ /**
20
+ * @inheritdoc
21
+ */
22
+ destroy(): void;
23
+ /**
24
+ * Assicura che il modulo Webauthn sia inizializzato
25
+ * @private
26
+ */
27
+ private assertWebauthn;
28
+ /**
29
+ * Assicura che il signer sia inizializzato
30
+ * @private
31
+ */
32
+ private assertSigner;
33
+ /**
34
+ * Genera un pair SEA dalle credenziali WebAuthn
35
+ * @private
36
+ */
37
+ private generatePairFromCredentials;
38
+ /**
39
+ * @inheritdoc
40
+ */
41
+ isSupported(): boolean;
42
+ /**
43
+ * @inheritdoc
44
+ */
45
+ generateCredentials(username: string, existingCredential?: WebAuthnCredentials | null, isLogin?: boolean): Promise<WebAuthnUniformCredentials>;
46
+ /**
47
+ * @inheritdoc
48
+ */
49
+ createAccount(username: string, credentials: WebAuthnCredentials | null, isNewDevice?: boolean): Promise<CredentialResult>;
50
+ /**
51
+ * @inheritdoc
52
+ */
53
+ authenticateUser(username: string, salt: string | null, options?: any): Promise<CredentialResult>;
54
+ /**
55
+ * @inheritdoc
56
+ */
57
+ abortAuthentication(): void;
58
+ /**
59
+ * @inheritdoc
60
+ */
61
+ removeDevice(username: string, credentialId: string, credentials: WebAuthnCredentials): Promise<{
62
+ success: boolean;
63
+ updatedCredentials?: WebAuthnCredentials;
64
+ }>;
65
+ /**
66
+ * @inheritdoc
67
+ */
68
+ createSigningCredential(username: string): Promise<WebAuthnSigningCredential>;
69
+ /**
70
+ * @inheritdoc
71
+ */
72
+ createAuthenticator(credentialId: string): (data: any) => Promise<AuthenticatorAssertionResponse>;
73
+ /**
74
+ * @inheritdoc
75
+ */
76
+ createDerivedKeyPair(credentialId: string, username: string, extra?: string[]): Promise<{
77
+ pub: string;
78
+ priv: string;
79
+ epub: string;
80
+ epriv: string;
81
+ }>;
82
+ /**
83
+ * @inheritdoc
84
+ */
85
+ signWithDerivedKeys(data: any, credentialId: string, username: string, extra?: string[]): Promise<string>;
86
+ /**
87
+ * @inheritdoc
88
+ */
89
+ getSigningCredential(credentialId: string): WebAuthnSigningCredential | undefined;
90
+ /**
91
+ * @inheritdoc
92
+ */
93
+ listSigningCredentials(): WebAuthnSigningCredential[];
94
+ /**
95
+ * @inheritdoc
96
+ */
97
+ removeSigningCredential(credentialId: string): boolean;
98
+ /**
99
+ * Creates a Gun user from WebAuthn signing credential
100
+ * This ensures the SAME user is created as with normal approach
101
+ */
102
+ createGunUserFromSigningCredential(credentialId: string, username: string): Promise<{
103
+ success: boolean;
104
+ userPub?: string;
105
+ error?: string;
106
+ }>;
107
+ /**
108
+ * Get the Gun user public key for a signing credential
109
+ */
110
+ getGunUserPubFromSigningCredential(credentialId: string): string | undefined;
111
+ /**
112
+ * Get the hashed credential ID (for consistency checking)
113
+ */
114
+ getHashedCredentialId(credentialId: string): string | undefined;
115
+ /**
116
+ * Verify consistency between oneshot and normal approaches
117
+ * This ensures both approaches create the same Gun user
118
+ */
119
+ verifyConsistency(credentialId: string, username: string, expectedUserPub?: string): Promise<{
120
+ consistent: boolean;
121
+ actualUserPub?: string;
122
+ expectedUserPub?: string;
123
+ }>;
124
+ /**
125
+ * Complete oneshot workflow that creates the SAME Gun user as normal approach
126
+ * This is the recommended method for oneshot signing with full consistency
127
+ */
128
+ setupConsistentOneshotSigning(username: string): Promise<{
129
+ credential: WebAuthnSigningCredential;
130
+ authenticator: (data: any) => Promise<AuthenticatorAssertionResponse>;
131
+ gunUser: {
132
+ success: boolean;
133
+ userPub?: string;
134
+ error?: string;
135
+ };
136
+ pub: string;
137
+ hashedCredentialId: string;
138
+ }>;
139
+ /**
140
+ * Login with WebAuthn
141
+ * This is the recommended method for WebAuthn authentication
142
+ * @param username - Username
143
+ * @returns {Promise<AuthResult>} Authentication result
144
+ * @description Authenticates user using WebAuthn credentials.
145
+ * Requires browser support for WebAuthn and existing credentials.
146
+ */
147
+ login(username: string): Promise<AuthResult>;
148
+ /**
149
+ * Register new user with WebAuthn
150
+ * This is the recommended method for WebAuthn registration
151
+ * @param username - Username
152
+ * @returns {Promise<SignUpResult>} Registration result
153
+ * @description Creates a new user account using WebAuthn credentials.
154
+ * Requires browser support for WebAuthn.
155
+ */
156
+ signUp(username: string): Promise<SignUpResult>;
157
+ }
158
+ export type { WebauthnPluginInterface } from "./types";
@@ -0,0 +1,91 @@
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
+ * FIX: Use derived pair instead of username/password for GunDB auth
49
+ */
50
+ createGunUser(credentialId: string, username: string, gunInstance: any): Promise<{
51
+ success: boolean;
52
+ userPub?: string;
53
+ error?: string;
54
+ }>;
55
+ /**
56
+ * Signs data using WebAuthn + derived keys
57
+ * This provides a hybrid approach: WebAuthn for user verification + derived keys for actual signing
58
+ * CONSISTENT with normal approach
59
+ */
60
+ signWithDerivedKeys(data: any, credentialId: string, username: string, extra?: string[]): Promise<string>;
61
+ /**
62
+ * Get the Gun user public key for a credential
63
+ * This allows checking if the same user would be created
64
+ */
65
+ getGunUserPub(credentialId: string): string | undefined;
66
+ /**
67
+ * Get the hashed credential ID (for consistency checking)
68
+ */
69
+ getHashedCredentialId(credentialId: string): string | undefined;
70
+ /**
71
+ * Check if this credential would create the same Gun user as normal approach
72
+ */
73
+ verifyConsistency(credentialId: string, username: string, expectedUserPub?: string): Promise<{
74
+ consistent: boolean;
75
+ actualUserPub?: string;
76
+ expectedUserPub?: string;
77
+ }>;
78
+ /**
79
+ * Get credential by ID
80
+ */
81
+ getCredential(credentialId: string): WebAuthnSigningCredential | undefined;
82
+ /**
83
+ * List all stored credentials
84
+ */
85
+ listCredentials(): WebAuthnSigningCredential[];
86
+ /**
87
+ * Remove a credential
88
+ */
89
+ removeCredential(credentialId: string): boolean;
90
+ }
91
+ export default WebAuthnSigner;