signer-test-sdk-core 0.0.1

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 (63) hide show
  1. package/README.md +81 -0
  2. package/dist/src/components/OnboardingUI/auth.d.ts +158 -0
  3. package/dist/src/components/OnboardingUI/auth.js +230 -0
  4. package/dist/src/components/OnboardingUI/auth.js.map +1 -0
  5. package/dist/src/components/OnboardingUI/index.d.ts +9 -0
  6. package/dist/src/components/OnboardingUI/index.js +9 -0
  7. package/dist/src/components/OnboardingUI/index.js.map +1 -0
  8. package/dist/src/components/OnboardingUI/types.d.ts +159 -0
  9. package/dist/src/components/OnboardingUI/types.js +5 -0
  10. package/dist/src/components/OnboardingUI/types.js.map +1 -0
  11. package/dist/src/core/AbstraxnWallet.d.ts +162 -0
  12. package/dist/src/core/AbstraxnWallet.js +593 -0
  13. package/dist/src/core/AbstraxnWallet.js.map +1 -0
  14. package/dist/src/core/AuthManager.d.ts +112 -0
  15. package/dist/src/core/AuthManager.js +685 -0
  16. package/dist/src/core/AuthManager.js.map +1 -0
  17. package/dist/src/core/Signer.d.ts +35 -0
  18. package/dist/src/core/Signer.js +156 -0
  19. package/dist/src/core/Signer.js.map +1 -0
  20. package/dist/src/index.d.ts +17 -0
  21. package/dist/src/index.js +19 -0
  22. package/dist/src/index.js.map +1 -0
  23. package/dist/src/interfaces/IAuth.d.ts +26 -0
  24. package/dist/src/interfaces/IAuth.js +2 -0
  25. package/dist/src/interfaces/IAuth.js.map +1 -0
  26. package/dist/src/interfaces/ISigner.d.ts +14 -0
  27. package/dist/src/interfaces/ISigner.js +2 -0
  28. package/dist/src/interfaces/ISigner.js.map +1 -0
  29. package/dist/src/interfaces/IStorage.d.ts +15 -0
  30. package/dist/src/interfaces/IStorage.js +2 -0
  31. package/dist/src/interfaces/IStorage.js.map +1 -0
  32. package/dist/src/interfaces/IWallet.d.ts +45 -0
  33. package/dist/src/interfaces/IWallet.js +2 -0
  34. package/dist/src/interfaces/IWallet.js.map +1 -0
  35. package/dist/src/services/ApiService.d.ts +131 -0
  36. package/dist/src/services/ApiService.js +626 -0
  37. package/dist/src/services/ApiService.js.map +1 -0
  38. package/dist/src/services/TokenService.d.ts +29 -0
  39. package/dist/src/services/TokenService.js +40 -0
  40. package/dist/src/services/TokenService.js.map +1 -0
  41. package/dist/src/services/TurnkeyService.d.ts +54 -0
  42. package/dist/src/services/TurnkeyService.js +91 -0
  43. package/dist/src/services/TurnkeyService.js.map +1 -0
  44. package/dist/src/storage/IndexedDBStorage.d.ts +39 -0
  45. package/dist/src/storage/IndexedDBStorage.js +280 -0
  46. package/dist/src/storage/IndexedDBStorage.js.map +1 -0
  47. package/dist/src/utils/constants.d.ts +52 -0
  48. package/dist/src/utils/constants.js +78 -0
  49. package/dist/src/utils/constants.js.map +1 -0
  50. package/dist/src/utils/errors.d.ts +23 -0
  51. package/dist/src/utils/errors.js +48 -0
  52. package/dist/src/utils/errors.js.map +1 -0
  53. package/dist/src/utils/helpers.d.ts +12 -0
  54. package/dist/src/utils/helpers.js +30 -0
  55. package/dist/src/utils/helpers.js.map +1 -0
  56. package/dist/src/utils/passkey.d.ts +33 -0
  57. package/dist/src/utils/passkey.js +122 -0
  58. package/dist/src/utils/passkey.js.map +1 -0
  59. package/dist/src/utils/types.d.ts +182 -0
  60. package/dist/src/utils/types.js +5 -0
  61. package/dist/src/utils/types.js.map +1 -0
  62. package/dist/tsconfig.tsbuildinfo +1 -0
  63. package/package.json +49 -0
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Constants for Abstraxn Wallet SDK
3
+ */
4
+ export const DEFAULT_CHAIN_ID = 1; // Ethereum Mainnet
5
+ export const SUPPORTED_CHAINS = [
6
+ {
7
+ id: 1,
8
+ name: 'Ethereum Mainnet',
9
+ rpcUrl: 'https://eth.llamarpc.com',
10
+ nativeCurrency: {
11
+ name: 'Ether',
12
+ symbol: 'ETH',
13
+ decimals: 18,
14
+ },
15
+ },
16
+ {
17
+ id: 137,
18
+ name: 'Polygon',
19
+ rpcUrl: 'https://rpc.ankr.com/polygon',
20
+ nativeCurrency: {
21
+ name: 'POL',
22
+ symbol: 'POL',
23
+ decimals: 18,
24
+ },
25
+ },
26
+ {
27
+ id: 80002,
28
+ name: 'Polygon Amoy',
29
+ rpcUrl: 'https://rpc-amoy.polygon.technology',
30
+ nativeCurrency: {
31
+ name: 'MATIC',
32
+ symbol: 'MATIC',
33
+ decimals: 18,
34
+ },
35
+ },
36
+ ];
37
+ export const STORAGE_KEYS = {
38
+ ACCESS_TOKEN: 'abstraxn_access_token',
39
+ REFRESH_TOKEN: 'abstraxn_refresh_token',
40
+ USER: 'abstraxn_user',
41
+ WALLET_CONFIG: 'abstraxn_wallet_config',
42
+ VERIFY_RESPONSE: 'abstraxn_verify_response',
43
+ WHOAMI: 'abstraxn_whoami',
44
+ };
45
+ // Fixed backend API base URL (set via environment variable or use default)
46
+ // Users don't need to configure this - it's handled by the SDK
47
+ export const API_BASE_URL = (typeof process !== 'undefined' && process.env?.ABSTRAXN_API_URL) ||
48
+ 'https://signer.abstraxn.com';
49
+ export const API_ENDPOINTS = {
50
+ INIT_OTP: '/login/otp/init',
51
+ VERIFY_OTP: '/login/otp/verify',
52
+ GOOGLE_AUTH: '/login/google',
53
+ GOOGLE_CALLBACK: '/login/google/callback',
54
+ DISCORD_AUTH: '/login/discord',
55
+ DISCORD_CALLBACK: '/login/discord/callback',
56
+ X_AUTH: '/login/x',
57
+ X_CALLBACK: '/login/x/callback',
58
+ PASSKEY_SIGNUP: '/login/passkey/signup',
59
+ PASSKEY_LOGIN: '/login/passkey/login',
60
+ REFRESH_TOKEN: '/auth/refresh',
61
+ SIGN_TRANSACTION: '/sign/transaction',
62
+ PROXY: '/proxy/',
63
+ WHOAMI: '/whoami',
64
+ EXPORT_WALLET: '/export-wallet',
65
+ };
66
+ export const TURNKEY_CONFIG = {
67
+ BASE_URL: 'https://api.turnkey.com',
68
+ STAMPER_DB_NAME: 'abstraxn-turnkey-stamper',
69
+ };
70
+ export const TURNKEY_ENDPOINTS = {
71
+ CREATE_POLICY: '/public/v1/submit/create_policy',
72
+ SIGN_TRANSACTION: '/public/v1/submit/sign_transaction',
73
+ SIGN_MESSAGE: '/public/v1/submit/sign_message',
74
+ SIGN_TYPED_DATA: '/public/v1/submit/sign_typed_data',
75
+ GET_WHOAMI: '/public/v1/query/whoami',
76
+ STAMP_EXPORT_WALLET_ACCOUNT: '/public/v1/submit/export_wallet_account',
77
+ };
78
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,CAAC,mBAAmB;AAEtD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B;QACE,EAAE,EAAE,CAAC;QACL,IAAI,EAAE,kBAAkB;QACxB,MAAM,EAAE,0BAA0B;QAClC,cAAc,EAAE;YACd,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,KAAK;YACb,QAAQ,EAAE,EAAE;SACb;KACF;IACD;QACE,EAAE,EAAE,GAAG;QACP,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,8BAA8B;QACtC,cAAc,EAAE;YACd,IAAI,EAAE,KAAK;YACX,MAAM,EAAE,KAAK;YACb,QAAQ,EAAE,EAAE;SACb;KACF;IACD;QACE,EAAE,EAAE,KAAK;QACT,IAAI,EAAE,cAAc;QACpB,MAAM,EAAE,qCAAqC;QAC7C,cAAc,EAAE;YACd,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,EAAE;SACb;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,YAAY,EAAE,uBAAuB;IACrC,aAAa,EAAE,wBAAwB;IACvC,IAAI,EAAE,eAAe;IACrB,aAAa,EAAE,wBAAwB;IACvC,eAAe,EAAE,0BAA0B;IAC3C,MAAM,EAAE,iBAAiB;CACjB,CAAC;AAEX,2EAA2E;AAC3E,+DAA+D;AAC/D,MAAM,CAAC,MAAM,YAAY,GACvB,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,gBAAgB,CAAC;IACjE,6BAA6B,CAAC;AAEhC,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,QAAQ,EAAE,iBAAiB;IAC3B,UAAU,EAAE,mBAAmB;IAC/B,WAAW,EAAE,eAAe;IAC5B,eAAe,EAAE,wBAAwB;IACzC,YAAY,EAAE,gBAAgB;IAC9B,gBAAgB,EAAE,yBAAyB;IAC3C,MAAM,EAAE,UAAU;IAClB,UAAU,EAAE,mBAAmB;IAC/B,cAAc,EAAE,uBAAuB;IACvC,aAAa,EAAE,sBAAsB;IACrC,aAAa,EAAE,eAAe;IAC9B,gBAAgB,EAAE,mBAAmB;IACrC,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,SAAS;IACjB,aAAa,EAAE,gBAAgB;CACvB,CAAC;AAEX,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,QAAQ,EAAE,yBAAyB;IACnC,eAAe,EAAE,0BAA0B;CACnC,CAAC;AAEX,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,aAAa,EAAE,iCAAiC;IAChD,gBAAgB,EAAE,oCAAoC;IACtD,YAAY,EAAE,gCAAgC;IAC9C,eAAe,EAAE,mCAAmC;IACpD,UAAU,EAAE,yBAAyB;IACrC,2BAA2B,EAAE,yCAAyC;CAC9D,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Custom error classes for Abstraxn Wallet SDK
3
+ */
4
+ export declare class AbstraxnWalletError extends Error {
5
+ code?: string | undefined;
6
+ constructor(message: string, code?: string | undefined);
7
+ }
8
+ export declare class WalletNotConnectedError extends AbstraxnWalletError {
9
+ constructor();
10
+ }
11
+ export declare class AuthenticationError extends AbstraxnWalletError {
12
+ constructor(message: string);
13
+ }
14
+ export declare class TransactionError extends AbstraxnWalletError {
15
+ txHash?: string | undefined;
16
+ constructor(message: string, txHash?: string | undefined);
17
+ }
18
+ export declare class NetworkError extends AbstraxnWalletError {
19
+ constructor(message: string);
20
+ }
21
+ export declare class StorageError extends AbstraxnWalletError {
22
+ constructor(message: string);
23
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Custom error classes for Abstraxn Wallet SDK
3
+ */
4
+ export class AbstraxnWalletError extends Error {
5
+ constructor(message, code) {
6
+ super(message);
7
+ this.code = code;
8
+ this.name = 'AbstraxnWalletError';
9
+ Object.setPrototypeOf(this, AbstraxnWalletError.prototype);
10
+ }
11
+ }
12
+ export class WalletNotConnectedError extends AbstraxnWalletError {
13
+ constructor() {
14
+ super('Wallet is not connected. Please call connect() first.', 'WALLET_NOT_CONNECTED');
15
+ this.name = 'WalletNotConnectedError';
16
+ Object.setPrototypeOf(this, WalletNotConnectedError.prototype);
17
+ }
18
+ }
19
+ export class AuthenticationError extends AbstraxnWalletError {
20
+ constructor(message) {
21
+ super(message, 'AUTHENTICATION_ERROR');
22
+ this.name = 'AuthenticationError';
23
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
24
+ }
25
+ }
26
+ export class TransactionError extends AbstraxnWalletError {
27
+ constructor(message, txHash) {
28
+ super(message, 'TRANSACTION_ERROR');
29
+ this.txHash = txHash;
30
+ this.name = 'TransactionError';
31
+ Object.setPrototypeOf(this, TransactionError.prototype);
32
+ }
33
+ }
34
+ export class NetworkError extends AbstraxnWalletError {
35
+ constructor(message) {
36
+ super(message, 'NETWORK_ERROR');
37
+ this.name = 'NetworkError';
38
+ Object.setPrototypeOf(this, NetworkError.prototype);
39
+ }
40
+ }
41
+ export class StorageError extends AbstraxnWalletError {
42
+ constructor(message) {
43
+ super(message, 'STORAGE_ERROR');
44
+ this.name = 'StorageError';
45
+ Object.setPrototypeOf(this, StorageError.prototype);
46
+ }
47
+ }
48
+ //# sourceMappingURL=errors.js.map
@@ -0,0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Ae,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,mBAAmB;IACnD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Helper functions for Abstraxn Wallet SDK
3
+ */
4
+ import { TransactionRequest } from './types';
5
+ /**
6
+ * Parse transaction request to ensure proper format
7
+ */
8
+ export declare function parseTransactionRequest(tx: TransactionRequest): TransactionRequest;
9
+ /**
10
+ * Get error message from response
11
+ */
12
+ export declare function getErrorMessage(error: unknown): string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Helper functions for Abstraxn Wallet SDK
3
+ */
4
+ /**
5
+ * Parse transaction request to ensure proper format
6
+ */
7
+ export function parseTransactionRequest(tx) {
8
+ return {
9
+ ...tx,
10
+ value: typeof tx.value === 'string' ? BigInt(tx.value) : tx.value,
11
+ gasLimit: tx.gasLimit ? BigInt(tx.gasLimit) : undefined,
12
+ gasPrice: tx.gasPrice ? BigInt(tx.gasPrice) : undefined,
13
+ maxFeePerGas: tx.maxFeePerGas ? BigInt(tx.maxFeePerGas) : undefined,
14
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas ? BigInt(tx.maxPriorityFeePerGas) : undefined,
15
+ };
16
+ }
17
+ /**
18
+ * Get error message from response
19
+ */
20
+ export function getErrorMessage(error) {
21
+ if (error instanceof Error) {
22
+ return error.message;
23
+ }
24
+ if (typeof error === 'object' && error !== null) {
25
+ const err = error;
26
+ return err.message || err.error || 'Unknown error';
27
+ }
28
+ return String(error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CAAC;AACvB,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Passkey utility functions for WebAuthn operations
3
+ */
4
+ /**
5
+ * Helper function to generate a random challenge (base64url encoded)
6
+ */
7
+ export declare const generateChallenge: () => string;
8
+ /**
9
+ * Helper function to convert ArrayBuffer to base64url
10
+ */
11
+ export declare const arrayBufferToBase64url: (buffer: ArrayBuffer) => string;
12
+ /**
13
+ * Generate authenticator name in format: domain-date-time
14
+ */
15
+ export declare const generateAuthenticatorName: (rpId: string) => string;
16
+ /**
17
+ * Generate user name with timestamp
18
+ */
19
+ export declare const generateUserName: () => string;
20
+ /**
21
+ * Generate organization name with timestamp
22
+ */
23
+ export declare const generateOrganizationName: () => string;
24
+ /**
25
+ * Create passkey credential using WebAuthn API
26
+ */
27
+ export declare const createPasskeyCredential: (rpId: string, challengeBase64: string) => Promise<{
28
+ credentialId: string;
29
+ attestationObject: string;
30
+ clientDataJson: string;
31
+ transports: string[];
32
+ challenge: string;
33
+ }>;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Passkey utility functions for WebAuthn operations
3
+ */
4
+ /**
5
+ * Helper function to generate a random challenge (base64url encoded)
6
+ */
7
+ export const generateChallenge = () => {
8
+ const array = new Uint8Array(32);
9
+ crypto.getRandomValues(array);
10
+ return btoa(String.fromCharCode(...array))
11
+ .replace(/\+/g, '-')
12
+ .replace(/\//g, '_')
13
+ .replace(/=/g, '');
14
+ };
15
+ /**
16
+ * Helper function to convert ArrayBuffer to base64url
17
+ */
18
+ export const arrayBufferToBase64url = (buffer) => {
19
+ const bytes = new Uint8Array(buffer);
20
+ return btoa(String.fromCharCode(...bytes))
21
+ .replace(/\+/g, '-')
22
+ .replace(/\//g, '_')
23
+ .replace(/=/g, '');
24
+ };
25
+ /**
26
+ * Generate authenticator name in format: domain-date-time
27
+ */
28
+ export const generateAuthenticatorName = (rpId) => {
29
+ const now = new Date();
30
+ const dateStr = `${String(now.getMonth() + 1).padStart(2, '0')}/${String(now.getDate()).padStart(2, '0')}/${now.getFullYear()}`;
31
+ const timeStr = `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
32
+ return `${rpId}-${dateStr}-${timeStr}`;
33
+ };
34
+ /**
35
+ * Generate user name with timestamp
36
+ */
37
+ export const generateUserName = () => {
38
+ return `user-${Date.now()}`;
39
+ };
40
+ /**
41
+ * Generate organization name with timestamp
42
+ */
43
+ export const generateOrganizationName = () => {
44
+ return `sub-org-${Date.now()}`;
45
+ };
46
+ /**
47
+ * Create passkey credential using WebAuthn API
48
+ */
49
+ export const createPasskeyCredential = async (rpId, challengeBase64) => {
50
+ // Convert base64url challenge to Uint8Array for WebAuthn API
51
+ const challengeBytes = Uint8Array.from(atob(challengeBase64.replace(/-/g, '+').replace(/_/g, '/')), (c) => c.charCodeAt(0));
52
+ // Generate a unique user ID
53
+ const userId = crypto.randomUUID();
54
+ const userIdBytes = new TextEncoder().encode(userId);
55
+ // Create credential creation options
56
+ const publicKeyCredentialCreationOptions = {
57
+ rp: {
58
+ name: 'Abstraxn',
59
+ id: rpId,
60
+ },
61
+ user: {
62
+ id: userIdBytes,
63
+ name: `wallet@${rpId}-${new Date().toISOString()}`,
64
+ displayName: `Wallet at ${rpId}`,
65
+ },
66
+ challenge: challengeBytes,
67
+ pubKeyCredParams: [
68
+ {
69
+ type: 'public-key',
70
+ alg: -7, // ES256
71
+ },
72
+ {
73
+ type: 'public-key',
74
+ alg: -257, // RS256
75
+ },
76
+ ],
77
+ authenticatorSelection: {
78
+ authenticatorAttachment: 'platform',
79
+ userVerification: 'required',
80
+ residentKey: 'preferred',
81
+ },
82
+ attestation: 'direct',
83
+ timeout: 60000,
84
+ };
85
+ // Create the credential using native WebAuthn API
86
+ const credential = (await navigator.credentials.create({
87
+ publicKey: publicKeyCredentialCreationOptions,
88
+ }));
89
+ if (!credential || !credential.response) {
90
+ throw new Error('Failed to create credential');
91
+ }
92
+ // Extract the attestation data
93
+ const response = credential.response;
94
+ const credentialId = arrayBufferToBase64url(credential.rawId);
95
+ const attestationObject = arrayBufferToBase64url(response.attestationObject);
96
+ const clientDataJson = arrayBufferToBase64url(response.clientDataJSON);
97
+ const transports = response.getTransports?.() || [];
98
+ // Decode clientDataJSON to extract challenge
99
+ const clientData = JSON.parse(new TextDecoder().decode(new Uint8Array(response.clientDataJSON)));
100
+ const actualChallenge = clientData.challenge;
101
+ return {
102
+ credentialId,
103
+ attestationObject,
104
+ clientDataJson,
105
+ transports: transports.map((t) => {
106
+ // Map to Turnkey transport format
107
+ if (t === 'hybrid')
108
+ return 'AUTHENTICATOR_TRANSPORT_HYBRID';
109
+ if (t === 'internal')
110
+ return 'AUTHENTICATOR_TRANSPORT_INTERNAL';
111
+ if (t === 'usb')
112
+ return 'AUTHENTICATOR_TRANSPORT_USB';
113
+ if (t === 'nfc')
114
+ return 'AUTHENTICATOR_TRANSPORT_NFC';
115
+ if (t === 'ble')
116
+ return 'AUTHENTICATOR_TRANSPORT_BLE';
117
+ return `AUTHENTICATOR_TRANSPORT_${t.toUpperCase()}`;
118
+ }),
119
+ challenge: actualChallenge,
120
+ };
121
+ };
122
+ //# sourceMappingURL=passkey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passkey.js","sourceRoot":"","sources":["../../../src/utils/passkey.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAW,EAAE;IAC5C,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACjC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,CAAC;SACvC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF;;GAEG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CAAC;YACtD,OAAO,2BAA2B,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;QACtD,CAAC,CAAa;QACd,SAAS,EAAE,eAAe;KAC3B,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Core types for Abstraxn Wallet SDK
3
+ */
4
+ export interface AbstraxnWalletConfig {
5
+ /** API Key for authentication (required) */
6
+ apiKey: string;
7
+ /** Authentication methods to support */
8
+ authMethods?: ('otp' | 'google' | 'passkey' | 'twitter' | 'discord')[];
9
+ /** Google OAuth client ID (required for Google auth) */
10
+ googleClientId?: string;
11
+ /** Default chain ID */
12
+ defaultChainId?: number;
13
+ /** Supported chains */
14
+ supportedChains?: Chain[];
15
+ /** Auto-connect on initialization */
16
+ autoConnect?: boolean;
17
+ /** Enable debug logging */
18
+ enableLogging?: boolean;
19
+ }
20
+ export interface Chain {
21
+ id: number;
22
+ name: string;
23
+ rpcUrl: string;
24
+ nativeCurrency: {
25
+ name: string;
26
+ symbol: string;
27
+ decimals: number;
28
+ };
29
+ }
30
+ export interface User {
31
+ id: string;
32
+ email: string;
33
+ userName: string;
34
+ subOrganizationId: string;
35
+ userId: string | null;
36
+ appId: string;
37
+ publicKey: string | null;
38
+ isPolicy: boolean;
39
+ authProvider: 'email' | 'google';
40
+ createdAt: Date;
41
+ updatedAt: Date;
42
+ }
43
+ export interface TransactionRequest {
44
+ to: string;
45
+ value?: string | bigint;
46
+ data?: string;
47
+ gasLimit?: bigint;
48
+ gasPrice?: bigint;
49
+ maxFeePerGas?: bigint;
50
+ maxPriorityFeePerGas?: bigint;
51
+ nonce?: number;
52
+ chainId?: number;
53
+ from?: string;
54
+ }
55
+ export interface TransactionResponse {
56
+ hash: string;
57
+ receipt?: any;
58
+ }
59
+ export interface TypedData {
60
+ domain: {
61
+ name?: string;
62
+ version?: string;
63
+ chainId?: number;
64
+ verifyingContract?: string;
65
+ };
66
+ types: Record<string, Array<{
67
+ name: string;
68
+ type: string;
69
+ }>>;
70
+ message: Record<string, any>;
71
+ }
72
+ export interface WalletInfo {
73
+ walletId: string;
74
+ addresses: string[];
75
+ chainId: number;
76
+ }
77
+ export type WalletEvent = 'connect' | 'disconnect' | 'accountChanged' | 'chainChanged';
78
+ export type WalletEventHandler = (...args: any[]) => void;
79
+ export interface InitOtpResponse {
80
+ orgId: string;
81
+ otpId: string;
82
+ }
83
+ export interface VerifyOtpResponse {
84
+ error: boolean;
85
+ message: string;
86
+ statusCode: number;
87
+ accessToken?: string;
88
+ refreshToken?: string;
89
+ result: {
90
+ user: User;
91
+ };
92
+ }
93
+ export interface AuthTokens {
94
+ accessToken: string;
95
+ refreshToken: string;
96
+ }
97
+ export interface WhoamiResponse {
98
+ organizationId: string;
99
+ organizationName: string;
100
+ userId: string;
101
+ username: string;
102
+ address?: string;
103
+ solanaAddress?: string;
104
+ email?: string;
105
+ rootQuorumThreshold?: number;
106
+ rootUsers?: Array<{
107
+ userId: string;
108
+ userName: string;
109
+ apiKeys?: Array<{
110
+ apiKeyId: string;
111
+ apiKeyName: string;
112
+ }>;
113
+ }>;
114
+ rootOrgId?: string;
115
+ wallets?: Array<{
116
+ walletId: string;
117
+ walletName: string;
118
+ accounts?: Array<{
119
+ address: string;
120
+ path: string;
121
+ pathFormat: string;
122
+ curve: string;
123
+ }>;
124
+ }>;
125
+ policies?: Array<{
126
+ policyId: string;
127
+ policyName: string;
128
+ }>;
129
+ }
130
+ export interface ExportWalletResponse {
131
+ exportBundle: string;
132
+ }
133
+ export interface PasskeyAuthenticator {
134
+ authenticatorName: string;
135
+ challenge: string;
136
+ attestation: {
137
+ credentialId: string;
138
+ attestationObject: string;
139
+ clientDataJson: string;
140
+ transports: Array<'AUTHENTICATOR_TRANSPORT_BLE' | 'AUTHENTICATOR_TRANSPORT_INTERNAL' | 'AUTHENTICATOR_TRANSPORT_NFC' | 'AUTHENTICATOR_TRANSPORT_USB' | 'AUTHENTICATOR_TRANSPORT_HYBRID'>;
141
+ };
142
+ }
143
+ export interface PasskeySignupRequest {
144
+ userName: string;
145
+ authenticators: PasskeyAuthenticator[];
146
+ organizationName: string;
147
+ targetPublicKey: string;
148
+ }
149
+ export interface PasskeySignupResponse {
150
+ error: boolean;
151
+ message: string;
152
+ statusCode: number;
153
+ accessToken?: string;
154
+ refreshToken?: string;
155
+ result?: {
156
+ user: User;
157
+ };
158
+ }
159
+ export interface PasskeyLoginRequest {
160
+ body: any;
161
+ stamp: any;
162
+ }
163
+ export interface PasskeyLoginResponse {
164
+ error: boolean;
165
+ message: string;
166
+ statusCode: number;
167
+ accessToken?: string;
168
+ refreshToken?: string;
169
+ result?: {
170
+ user: User;
171
+ };
172
+ }
173
+ export interface PasskeyLoginResponse {
174
+ error: boolean;
175
+ message: string;
176
+ statusCode: number;
177
+ accessToken?: string;
178
+ refreshToken?: string;
179
+ result?: {
180
+ user: User;
181
+ };
182
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Core types for Abstraxn Wallet SDK
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}