@cryptforge/core 0.1.0 → 0.2.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/README.md CHANGED
@@ -0,0 +1,326 @@
1
+ # @cryptforge/core
2
+
3
+ Core TypeScript types and interfaces for the CryptForge SDK. This package provides shared type definitions used across all CryptForge packages.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @cryptforge/core
9
+ # or
10
+ pnpm add @cryptforge/core
11
+ # or
12
+ yarn add @cryptforge/core
13
+ ```
14
+
15
+ ## Overview
16
+
17
+ This package contains no runtime code - only TypeScript type definitions and interfaces. It's automatically installed as a dependency when you use any CryptForge package.
18
+
19
+ ## What's Included
20
+
21
+ ### Authentication Types (`types/auth.ts`)
22
+
23
+ Core types for authentication and key management:
24
+
25
+ - `Identity` - User identity metadata
26
+ - `Keys` - Derived cryptographic keys
27
+ - `Keystore` - Encrypted keystore structure
28
+ - `AuthState` - Authentication state machine
29
+ - `AuthChangeEvent` - Auth state change events
30
+ - `CreateIdentityOptions` - Identity creation parameters
31
+ - `UnlockOptions` - Wallet unlock parameters
32
+ - `ExportOptions` - Identity export options
33
+
34
+ ### Blockchain Types (`types/blockchain.ts`)
35
+
36
+ Types for blockchain adapters and operations:
37
+
38
+ - `BlockchainAdapter` - Interface for implementing blockchain adapters
39
+ - `KeyData` - Derived key information
40
+ - `ChainData` - Blockchain metadata
41
+ - `Transaction` - Transaction structure
42
+ - `TokenBalance` - Token balance information
43
+ - `TokenTransfer` - Token transfer details
44
+ - `TransactionOptions` - Transaction query options
45
+
46
+ ### Client Types (`types/client.ts`)
47
+
48
+ Types for client-side operations:
49
+
50
+ - Client configuration types
51
+ - Client state management types
52
+ - Event types for client operations
53
+
54
+ ### Application Types (`types/app.ts`)
55
+
56
+ Application-level types:
57
+
58
+ - App configuration
59
+ - App state management
60
+ - Plugin interfaces
61
+
62
+ ### Secrets Types (`types/secrets.ts`)
63
+
64
+ Types for secret management:
65
+
66
+ - Secret storage interfaces
67
+ - Encryption/decryption types
68
+ - Secret metadata
69
+
70
+ ### Presence Types (`types/presence.ts`)
71
+
72
+ Types for device presence and synchronization:
73
+
74
+ - Device presence information
75
+ - Peer discovery types
76
+ - Sync state management
77
+
78
+ ## Usage
79
+
80
+ This package is primarily used by library authors creating CryptForge-compatible packages. Most developers will use higher-level packages like `@cryptforge/auth` or `@cryptforge/blockchain-evm`.
81
+
82
+ ### Implementing a Custom Blockchain Adapter
83
+
84
+ ```typescript
85
+ import type {
86
+ BlockchainAdapter,
87
+ KeyData,
88
+ ChainData,
89
+ } from '@cryptforge/core';
90
+
91
+ class MyCustomAdapter implements BlockchainAdapter {
92
+ readonly chainData: ChainData = {
93
+ name: 'My Chain',
94
+ symbol: 'MYC',
95
+ cmc_id: 12345,
96
+ chainId: 1,
97
+ decimals: 18,
98
+ };
99
+
100
+ async deriveKeys(mnemonic: string): Promise<KeyData> {
101
+ // Implement key derivation
102
+ }
103
+
104
+ async deriveKeysAtIndex(mnemonic: string, index: number): Promise<KeyData> {
105
+ // Implement indexed key derivation
106
+ }
107
+
108
+ async deriveKeysAtPath(mnemonic: string, path: string): Promise<KeyData> {
109
+ // Implement path-based key derivation
110
+ }
111
+
112
+ async getAddressAtIndex(
113
+ mnemonic: string,
114
+ index: number
115
+ ): Promise<{ address: string; publicKey: string; path: string }> {
116
+ // Implement address generation
117
+ }
118
+
119
+ async getAddresses(
120
+ mnemonic: string,
121
+ startIndex: number,
122
+ count: number
123
+ ): Promise<Array<{ address: string; path: string; index: number }>> {
124
+ // Implement multiple address generation
125
+ }
126
+
127
+ async signMessage(
128
+ privateKey: Uint8Array,
129
+ message: string | Uint8Array
130
+ ): Promise<{ signature: string }> {
131
+ // Implement message signing
132
+ }
133
+
134
+ async signTransaction(
135
+ privateKey: Uint8Array,
136
+ transaction: any
137
+ ): Promise<{ signedTransaction: any; signature: string }> {
138
+ // Implement transaction signing
139
+ }
140
+
141
+ async verifySignature(
142
+ message: string | Uint8Array,
143
+ signature: string,
144
+ publicKey: string
145
+ ): Promise<boolean> {
146
+ // Implement signature verification
147
+ }
148
+
149
+ // Implement blockchain data query methods...
150
+ async getNativeBalance(address: string): Promise<any> {
151
+ // Get native token balance
152
+ }
153
+
154
+ async getTokenBalances(address: string): Promise<any[]> {
155
+ // Get all token balances
156
+ }
157
+
158
+ async getTransactions(address: string, options?: any): Promise<any[]> {
159
+ // Get transaction history
160
+ }
161
+
162
+ // ... other required methods
163
+ }
164
+ ```
165
+
166
+ ### Using Types in Your Application
167
+
168
+ ```typescript
169
+ import type {
170
+ Identity,
171
+ Keys,
172
+ ChainData,
173
+ Transaction,
174
+ } from '@cryptforge/core';
175
+
176
+ // Type-safe identity handling
177
+ const handleIdentity = (identity: Identity) => {
178
+ console.log('Identity ID:', identity.id);
179
+ console.log('Label:', identity.label);
180
+ console.log('Created:', identity.createdAt);
181
+ };
182
+
183
+ // Type-safe key handling
184
+ const handleKeys = (keys: Keys) => {
185
+ console.log('Address:', keys.address);
186
+ console.log('Chain:', keys.chain.name);
187
+ console.log('Expires:', keys.expiresAt);
188
+ };
189
+
190
+ // Type-safe chain data
191
+ const displayChainInfo = (chain: ChainData) => {
192
+ console.log(`${chain.name} (${chain.symbol})`);
193
+ };
194
+ ```
195
+
196
+ ## Key Interfaces
197
+
198
+ ### BlockchainAdapter
199
+
200
+ The `BlockchainAdapter` interface defines the contract that all blockchain adapters must implement:
201
+
202
+ ```typescript
203
+ interface BlockchainAdapter {
204
+ // Chain metadata
205
+ readonly chainData: ChainData;
206
+
207
+ // Key derivation
208
+ deriveKeys(mnemonic: string): Promise<KeyData>;
209
+ deriveKeysAtIndex(mnemonic: string, index: number): Promise<KeyData>;
210
+ deriveKeysAtPath(mnemonic: string, path: string): Promise<KeyData>;
211
+
212
+ // Address generation
213
+ getAddressAtIndex(
214
+ mnemonic: string,
215
+ index: number
216
+ ): Promise<{ address: string; publicKey: string; path: string }>;
217
+ getAddresses(
218
+ mnemonic: string,
219
+ startIndex: number,
220
+ count: number
221
+ ): Promise<Array<{ address: string; path: string; index: number }>>;
222
+
223
+ // Cryptographic operations
224
+ signMessage(
225
+ privateKey: Uint8Array,
226
+ message: string | Uint8Array
227
+ ): Promise<{ signature: string }>;
228
+ signTransaction(
229
+ privateKey: Uint8Array,
230
+ transaction: any
231
+ ): Promise<{ signedTransaction: any; signature: string }>;
232
+ verifySignature(
233
+ message: string | Uint8Array,
234
+ signature: string,
235
+ publicKey: string
236
+ ): Promise<boolean>;
237
+
238
+ // Blockchain data queries
239
+ getNativeBalance(address: string): Promise<any>;
240
+ getTokenBalances(address: string): Promise<any[]>;
241
+ getTokenBalance(address: string, tokenAddress: string): Promise<string>;
242
+ getTransactions(address: string, options?: any): Promise<any[]>;
243
+ getTokenTransfers(address: string, options?: any): Promise<any[]>;
244
+
245
+ // Transaction operations
246
+ sendNativeToken(params: {
247
+ privateKey: Uint8Array;
248
+ to: string;
249
+ amount: string;
250
+ }): Promise<any>;
251
+ sendToken(params: {
252
+ privateKey: Uint8Array;
253
+ to: string;
254
+ tokenAddress: string;
255
+ amount: string;
256
+ }): Promise<any>;
257
+ getTransactionStatus(hash: string): Promise<any>;
258
+ }
259
+ ```
260
+
261
+ ### ChainData
262
+
263
+ ```typescript
264
+ interface ChainData {
265
+ name: string; // Display name (e.g., "Ethereum")
266
+ symbol: string; // Token symbol (e.g., "ETH")
267
+ cmc_id: number; // CoinMarketCap ID
268
+ chainId?: number; // Chain ID for EVM chains
269
+ decimals?: number; // Token decimals (default: 18)
270
+ }
271
+ ```
272
+
273
+ ### KeyData
274
+
275
+ ```typescript
276
+ interface KeyData {
277
+ mnemonic: string; // BIP39 mnemonic phrase
278
+ seed: Uint8Array; // BIP39 seed (512 bits)
279
+ privateKey: Uint8Array; // Private key bytes
280
+ privateKeyHex: string; // Private key as hex string
281
+ publicKey: Uint8Array; // Public key bytes
282
+ publicKeyHex: string; // Public key as hex string
283
+ address: string; // Blockchain address
284
+ path: string; // BIP44 derivation path
285
+ }
286
+ ```
287
+
288
+ ## Related Packages
289
+
290
+ - **[@cryptforge/auth](../auth)** - Authentication and key management using these types
291
+ - **[@cryptforge/blockchain-evm](../blockchain-evm)** - EVM blockchain adapter implementation
292
+ - **[@cryptforge/blockchain-btc](../blockchain-btc)** - Bitcoin blockchain adapter implementation
293
+ - **[@cryptforge/key-exchange](../key-exchange)** - Device synchronization using presence types
294
+ - **[@cryptforge/client-vue](../client-vue)** - Vue.js UI components using client types
295
+
296
+ ## TypeScript Configuration
297
+
298
+ For best results, use these TypeScript compiler options:
299
+
300
+ ```json
301
+ {
302
+ "compilerOptions": {
303
+ "target": "ES2020",
304
+ "module": "ESNext",
305
+ "moduleResolution": "bundler",
306
+ "strict": true,
307
+ "esModuleInterop": true,
308
+ "skipLibCheck": true,
309
+ "resolveJsonModule": true
310
+ }
311
+ }
312
+ ```
313
+
314
+ ## Contributing
315
+
316
+ When adding new types to this package:
317
+
318
+ 1. Add types to the appropriate file in `src/types/`
319
+ 2. Export from `src/index.ts`
320
+ 3. Update this README with documentation
321
+ 4. Ensure all types are well-documented with JSDoc comments
322
+ 5. Keep types browser-compatible (no Node.js-specific types)
323
+
324
+ ## License
325
+
326
+ MIT
package/dist/index.d.mts CHANGED
@@ -153,12 +153,6 @@ interface AuthAdapter {
153
153
  address: string;
154
154
  path: string;
155
155
  }>;
156
- deriveBIP44DocumentID: (options: {
157
- appId: number;
158
- account?: number;
159
- purpose?: number;
160
- index?: number;
161
- }) => Promise<string>;
162
156
  deriveDataEncryptionKey: (options: DeriveDataKeyOptions) => Promise<CryptoKey>;
163
157
  getAddressForChain: (chainId: string, index?: number) => Promise<{
164
158
  address: string;
@@ -438,248 +432,6 @@ interface BlockchainAdapter {
438
432
  getTransactionStatus: (hash: string) => Promise<TransactionStatusUpdate>;
439
433
  }
440
434
 
441
- /**
442
- * Base document type that developers work with.
443
- * Includes managed metadata fields (id, createdAt, updatedAt) that are automatically set by the library.
444
- * Users should extend this interface to define their document types.
445
- *
446
- * @example
447
- * ```typescript
448
- * interface UserDocument extends BaseDocument {
449
- * type: 'user'
450
- * name: string
451
- * email: string
452
- * // id, createdAt, updatedAt are automatically available
453
- * }
454
- * ```
455
- */
456
- interface BaseDocument {
457
- /** The document type identifier (e.g., 'note', 'task', 'user') */
458
- type: string;
459
- /** The Automerge document URL - automatically set by the library */
460
- id: string;
461
- /** Timestamp when the document was created - automatically set by the library */
462
- createdAt: number;
463
- /** Timestamp of the last update - automatically set by the library */
464
- updatedAt: number;
465
- /** Additional fields can be added as needed */
466
- [key: string]: any;
467
- }
468
- /**
469
- * Helper type to ensure user's document type doesn't include managed fields.
470
- * This prevents conflicts and ensures the library controls these fields.
471
- * Users cannot pass id, createdAt, or updatedAt when creating documents.
472
- */
473
- type ExternalDocument<T extends BaseDocument> = Omit<T, "id" | "createdAt" | "updatedAt">;
474
- /**
475
- * Internal encrypted document wrapper.
476
- * This structure is what's actually stored in Automerge.
477
- * The encryption/decryption is handled transparently by the store.
478
- *
479
- * @template T - The type of the decrypted document content (used for type safety, not stored in interface)
480
- */
481
- interface EncryptedDocument<_T> extends BaseDocument {
482
- /** Always 'encrypted' to identify this as an encrypted wrapper */
483
- type: "encrypted";
484
- /** Base64-encoded encrypted data containing the actual document */
485
- encryptedData: string;
486
- /**
487
- * Optional owner identifier (e.g., master public key from auth).
488
- * Stored unencrypted for server-side ownership verification without decryption.
489
- */
490
- owner?: string;
491
- /** Metadata about the encrypted document */
492
- metadata: {
493
- /** The original document type before encryption */
494
- contentType: string;
495
- /** Timestamp when the document was last encrypted */
496
- encryptedAt: number;
497
- /** User ID who encrypted the document */
498
- encryptedBy: string;
499
- };
500
- }
501
- /**
502
- * Configuration for subscribing to document changes.
503
- *
504
- * @template T - The type of document being subscribed to
505
- */
506
- interface SubscribeConfig<T extends BaseDocument> {
507
- /** The Automerge document URL/ID to subscribe to */
508
- id: string;
509
- /**
510
- * Unique context identifier for this subscription.
511
- * Allows multiple subscriptions to the same document (e.g., 'sidebar', 'main-view').
512
- */
513
- context: string;
514
- /**
515
- * Callback invoked with the decrypted document whenever it changes.
516
- * Receives null if the document doesn't exist or was deleted.
517
- * The document includes id, createdAt, and updatedAt fields automatically.
518
- */
519
- onUpdate: (doc: T | null) => void;
520
- /**
521
- * Optional error handler for subscription failures.
522
- * Called when decryption fails or other errors occur.
523
- */
524
- onError?: (error: Error) => void;
525
- }
526
- /**
527
- * Configuration for unsubscribing from document changes.
528
- */
529
- interface UnsubscribeConfig {
530
- /** The document ID to unsubscribe from */
531
- id: string;
532
- /** The context identifier of the subscription to remove */
533
- context: string;
534
- }
535
- /**
536
- * Generic interface for cryptographic operations.
537
- *
538
- * @template TKey - The encryption key type (CryptoKey for browser, Buffer for Node.js)
539
- */
540
- interface CryptoOperations<TKey = unknown> {
541
- /**
542
- * Encryption key for all document operations.
543
- * All documents are encrypted at rest using this key.
544
- * Browser implementations use CryptoKey, Node.js implementations use Buffer.
545
- */
546
- setEncryptionKey?: (key: TKey) => void;
547
- /**
548
- * Creates an encryption function that encrypts string data using AES-GCM encryption.
549
- * Returns a curried function that uses the instance's encryption key from `getEncryptionKey`.
550
- *
551
- * The returned function signature:
552
- * - `data`: The plaintext string to encrypt
553
- * - Returns: A promise resolving to the encrypted data as a string
554
- */
555
- encrypt: () => (data: string) => Promise<string>;
556
- /**
557
- * Creates a decryption function that decrypts encrypted string data using AES-GCM decryption.
558
- * Returns a curried function that uses the instance's encryption key from `getEncryptionKey`.
559
- *
560
- * The returned function signature:
561
- * - `encryptedData`: The encrypted string data to decrypt
562
- * - Returns: A promise resolving to the decrypted plaintext string
563
- */
564
- decrypt: () => (encryptedData: string) => Promise<string>;
565
- }
566
- /**
567
- * Interface for document store adapters.
568
- * Provides a standard interface for document storage, retrieval, modification, and subscription operations.
569
- *
570
- * @template TKey - The encryption key type (CryptoKey for browser, Buffer for Node.js)
571
- */
572
- interface StoreAdapter {
573
- /**
574
- * Optional: Gets the network adapter for stores that support network synchronization.
575
- * Returns null if no network adapter is configured.
576
- * This property is only available on stores that implement network synchronization.
577
- * The type is `any` to avoid coupling core types to Automerge-specific types.
578
- */
579
- readonly networkAdapter?: any | null;
580
- /**
581
- * Sets the encryption key for the store. Store operations aren't possible until the encryption key is set.
582
- *
583
- * @template TKey - The encryption key type (CryptoKey for browser, Buffer for Node.js)
584
- * @param key - The encryption key to set
585
- */
586
- setEncryptionKey<TKey = unknown>(key: TKey): void;
587
- /**
588
- * Sets the owner identifier for document ownership (e.g., auth.masterPublicKey).
589
- * Stored unencrypted in EncryptedDocument for server-side verification.
590
- * Should be chain-independent for multi-blockchain applications.
591
- *
592
- * @param publicKey - The owner's public key
593
- */
594
- setOwnerPublicKey(publicKey: string): void;
595
- /**
596
- * Creates a new document with automatic encryption.
597
- *
598
- * The document is encrypted before being stored.
599
- * Returns the document URL which can be used to retrieve or subscribe to the document.
600
- *
601
- * @template T - The document type (must extend BaseDocument)
602
- * @param doc - The document to create (must include a 'type' field)
603
- * @param url - Optional Automerge URL for deterministic document IDs
604
- * @returns Promise resolving to the document URL
605
- * @throws {Error} If document is missing 'type' field or encryption fails
606
- */
607
- create<T extends BaseDocument>(doc: ExternalDocument<T>, url?: string): Promise<string>;
608
- /**
609
- * Retrieves and decrypts a document by ID.
610
- *
611
- * @template T - The expected document type
612
- * @param id - The document URL/ID
613
- * @returns Promise resolving to the decrypted document, or null if not found
614
- * @throws {Error} If document ID is invalid or decryption fails
615
- */
616
- get<T extends BaseDocument>(id: string): Promise<T | null>;
617
- /**
618
- * Modifies a document with automatic re-encryption.
619
- *
620
- * The document is decrypted, modified via the callback, then re-encrypted.
621
- * Changes are applied atomically.
622
- * The document includes id, createdAt, and updatedAt fields automatically.
623
- *
624
- * **Protected Fields**: The fields `id`, `createdAt`, and `updatedAt` are managed
625
- * by the library and cannot be modified. Any attempts to change these fields in
626
- * the callback will be ignored and restored to their original values. The library
627
- * automatically updates `updatedAt` when changes are made.
628
- *
629
- * @template T - The document type
630
- * @param id - The document ID to modify
631
- * @param callback - Function that receives the decrypted document to modify
632
- * @returns Promise that resolves when the change is applied
633
- * @throws {Error} If document not found or encryption fails
634
- */
635
- change<T extends BaseDocument>(id: string, callback: (doc: T) => void): Promise<void>;
636
- /**
637
- * Deletes a document and cleans up all associated subscriptions.
638
- *
639
- * This removes the document from storage and automatically
640
- * unsubscribes all active listeners to prevent memory leaks.
641
- *
642
- * @param id - The document ID to delete
643
- * @returns Promise that resolves when deletion is complete
644
- */
645
- delete(id: string): Promise<void>;
646
- /**
647
- * Subscribes to document changes with automatic decryption.
648
- *
649
- * The callback receives the decrypted document whenever it changes.
650
- * Multiple subscriptions to the same document are supported via different contexts.
651
- *
652
- * @template T - The document type
653
- * @param config - Subscription configuration
654
- * @returns Unsubscribe function to stop receiving updates
655
- */
656
- subscribe<T extends BaseDocument>(config: SubscribeConfig<T>): () => void;
657
- /**
658
- * Unsubscribes from document changes using document ID and context.
659
- *
660
- * Alternative to calling the unsubscribe function returned by subscribe().
661
- *
662
- * @param config - Object containing document ID and context
663
- * @returns true if subscription was found and removed, false otherwise
664
- */
665
- unsubscribe(config: UnsubscribeConfig): boolean;
666
- /**
667
- * Gets all active subscription contexts for a document.
668
- * Useful for debugging subscription state.
669
- *
670
- * @param id - The document ID
671
- * @returns Array of context identifiers currently subscribed to this document
672
- */
673
- getActiveSubscriptions(id: string): string[];
674
- /**
675
- * Gets all active subscriptions across all documents.
676
- * Useful for debugging memory leaks or subscription issues.
677
- *
678
- * @returns Object mapping document IDs to arrays of context identifiers
679
- */
680
- getAllActiveSubscriptions(): Record<string, string[]>;
681
- }
682
-
683
435
  type ActionType = "primary" | "secondary";
684
436
  interface SlideAction {
685
437
  type: ActionType;
@@ -696,9 +448,9 @@ interface AppInfo {
696
448
  appId: number;
697
449
  icon: string;
698
450
  name: string;
699
- secret: string;
700
451
  description: string;
701
452
  steps: WalkthroughStep[];
453
+ hideWalletUI?: boolean;
702
454
  }
703
455
 
704
456
  interface KeyTransportAdapter {
@@ -722,11 +474,13 @@ interface KeyTransportAdapter {
722
474
  getDeviceInfo: () => Promise<Record<string, any>>;
723
475
  getHostname: () => Promise<string>;
724
476
  connectPresence: (topic: string) => Promise<void>;
725
- broadcastClientState: (id: string, state: ClientConnectionState) => Promise<void>;
477
+ broadcastClientState: (id: string, state: ClientConnectionState, name?: string, isHeartbeat?: boolean) => Promise<void>;
726
478
  onClientStateRequest: (callback: () => void) => Promise<void> | Promise<() => void>;
727
479
  onClientStateUpdate: (callback: (response: {
728
480
  id: string;
729
481
  state: ClientConnectionState;
482
+ name?: string;
483
+ isHeartbeat?: boolean;
730
484
  }) => void) => Promise<void> | Promise<() => void>;
731
485
  getPeerState: (id: string) => ClientConnectionState | undefined;
732
486
  getAllPeers: () => ReadonlyMap<string, ClientConnectionState>;
@@ -738,11 +492,13 @@ type OnSetupEventCallback = (options: {
738
492
 
739
493
  interface PresenceAdapter {
740
494
  connectPresence: (topic: string) => Promise<void>;
741
- broadcastClientState: (id: string, state: ClientConnectionState) => Promise<void>;
495
+ broadcastClientState: (id: string, state: ClientConnectionState, name?: string, isHeartbeat?: boolean) => Promise<void>;
742
496
  onClientStateRequest: (callback: () => void) => Promise<void> | Promise<() => void>;
743
497
  onClientStateUpdate: (callback: (response: {
744
498
  id: string;
745
499
  state: ClientConnectionState;
500
+ name?: string;
501
+ isHeartbeat?: boolean;
746
502
  }) => void) => Promise<void> | Promise<() => void>;
747
503
  getPeerState: (id: string) => ClientConnectionState | undefined;
748
504
  getAllPeers: () => ReadonlyMap<string, ClientConnectionState>;
@@ -751,7 +507,6 @@ interface PresenceAdapter {
751
507
  interface CryptForgeClientOptions {
752
508
  secrets: KeyTransportAdapter;
753
509
  presence: PresenceAdapter;
754
- data: StoreAdapter;
755
510
  appInfo: AppInfo;
756
511
  blockchain: BlockchainAdapter;
757
512
  auth: AuthAdapter;
@@ -759,7 +514,6 @@ interface CryptForgeClientOptions {
759
514
  interface CryptForgeClient {
760
515
  secrets: KeyTransportAdapter;
761
516
  presence: PresenceAdapter;
762
- data: StoreAdapter;
763
517
  appInfo: AppInfo;
764
518
  blockchain: BlockchainAdapter;
765
519
  auth: AuthAdapter;
@@ -769,4 +523,4 @@ type ClientConnectionState = "unknown" | "connecting" | "connected" | "idle" | "
769
523
 
770
524
  declare const version = "0.1.0";
771
525
 
772
- export { type ActionType, type AppInfo, type AuthAdapter, type AuthChangeCallback, type AuthEvent, type AuthState, type BaseDocument, type BlockchainAdapter, type BlockchainType, type Chain, type ChainData, type ClientConnectionState, type CreateIdentityOptions, type CryptForgeClient, type CryptForgeClientOptions, type CryptoOperations, type DeriveDataKeyOptions, type DeriveKeyOptions, type EncryptedDocument, type ExternalDocument, type GenerateMnemonicOptions, type Identity, type KeyData, type KeyTransportAdapter, type Keys, type OnSetupEventCallback, type PresenceAdapter, type RestoreIdentityOptions, type SignMessageOptions, type SignTransactionOptions, type SlideAction, type StoreAdapter, type StoredIdentity, type SubscribeConfig, type TokenBalance, type TokenTransfer, type Transaction, type TransactionOptions, type TransactionReceipt, type TransactionStatusUpdate, type UnlockOptions, type UnsubscribeConfig, type WalkthroughStep, createCryptForgeClient, version };
526
+ export { type ActionType, type AppInfo, type AuthAdapter, type AuthChangeCallback, type AuthEvent, type AuthState, type BlockchainAdapter, type BlockchainType, type Chain, type ChainData, type ClientConnectionState, type CreateIdentityOptions, type CryptForgeClient, type CryptForgeClientOptions, type DeriveDataKeyOptions, type DeriveKeyOptions, type GenerateMnemonicOptions, type Identity, type KeyData, type KeyTransportAdapter, type Keys, type OnSetupEventCallback, type PresenceAdapter, type RestoreIdentityOptions, type SignMessageOptions, type SignTransactionOptions, type SlideAction, type StoredIdentity, type TokenBalance, type TokenTransfer, type Transaction, type TransactionOptions, type TransactionReceipt, type TransactionStatusUpdate, type UnlockOptions, type WalkthroughStep, createCryptForgeClient, version };
package/dist/index.d.ts CHANGED
@@ -153,12 +153,6 @@ interface AuthAdapter {
153
153
  address: string;
154
154
  path: string;
155
155
  }>;
156
- deriveBIP44DocumentID: (options: {
157
- appId: number;
158
- account?: number;
159
- purpose?: number;
160
- index?: number;
161
- }) => Promise<string>;
162
156
  deriveDataEncryptionKey: (options: DeriveDataKeyOptions) => Promise<CryptoKey>;
163
157
  getAddressForChain: (chainId: string, index?: number) => Promise<{
164
158
  address: string;
@@ -438,248 +432,6 @@ interface BlockchainAdapter {
438
432
  getTransactionStatus: (hash: string) => Promise<TransactionStatusUpdate>;
439
433
  }
440
434
 
441
- /**
442
- * Base document type that developers work with.
443
- * Includes managed metadata fields (id, createdAt, updatedAt) that are automatically set by the library.
444
- * Users should extend this interface to define their document types.
445
- *
446
- * @example
447
- * ```typescript
448
- * interface UserDocument extends BaseDocument {
449
- * type: 'user'
450
- * name: string
451
- * email: string
452
- * // id, createdAt, updatedAt are automatically available
453
- * }
454
- * ```
455
- */
456
- interface BaseDocument {
457
- /** The document type identifier (e.g., 'note', 'task', 'user') */
458
- type: string;
459
- /** The Automerge document URL - automatically set by the library */
460
- id: string;
461
- /** Timestamp when the document was created - automatically set by the library */
462
- createdAt: number;
463
- /** Timestamp of the last update - automatically set by the library */
464
- updatedAt: number;
465
- /** Additional fields can be added as needed */
466
- [key: string]: any;
467
- }
468
- /**
469
- * Helper type to ensure user's document type doesn't include managed fields.
470
- * This prevents conflicts and ensures the library controls these fields.
471
- * Users cannot pass id, createdAt, or updatedAt when creating documents.
472
- */
473
- type ExternalDocument<T extends BaseDocument> = Omit<T, "id" | "createdAt" | "updatedAt">;
474
- /**
475
- * Internal encrypted document wrapper.
476
- * This structure is what's actually stored in Automerge.
477
- * The encryption/decryption is handled transparently by the store.
478
- *
479
- * @template T - The type of the decrypted document content (used for type safety, not stored in interface)
480
- */
481
- interface EncryptedDocument<_T> extends BaseDocument {
482
- /** Always 'encrypted' to identify this as an encrypted wrapper */
483
- type: "encrypted";
484
- /** Base64-encoded encrypted data containing the actual document */
485
- encryptedData: string;
486
- /**
487
- * Optional owner identifier (e.g., master public key from auth).
488
- * Stored unencrypted for server-side ownership verification without decryption.
489
- */
490
- owner?: string;
491
- /** Metadata about the encrypted document */
492
- metadata: {
493
- /** The original document type before encryption */
494
- contentType: string;
495
- /** Timestamp when the document was last encrypted */
496
- encryptedAt: number;
497
- /** User ID who encrypted the document */
498
- encryptedBy: string;
499
- };
500
- }
501
- /**
502
- * Configuration for subscribing to document changes.
503
- *
504
- * @template T - The type of document being subscribed to
505
- */
506
- interface SubscribeConfig<T extends BaseDocument> {
507
- /** The Automerge document URL/ID to subscribe to */
508
- id: string;
509
- /**
510
- * Unique context identifier for this subscription.
511
- * Allows multiple subscriptions to the same document (e.g., 'sidebar', 'main-view').
512
- */
513
- context: string;
514
- /**
515
- * Callback invoked with the decrypted document whenever it changes.
516
- * Receives null if the document doesn't exist or was deleted.
517
- * The document includes id, createdAt, and updatedAt fields automatically.
518
- */
519
- onUpdate: (doc: T | null) => void;
520
- /**
521
- * Optional error handler for subscription failures.
522
- * Called when decryption fails or other errors occur.
523
- */
524
- onError?: (error: Error) => void;
525
- }
526
- /**
527
- * Configuration for unsubscribing from document changes.
528
- */
529
- interface UnsubscribeConfig {
530
- /** The document ID to unsubscribe from */
531
- id: string;
532
- /** The context identifier of the subscription to remove */
533
- context: string;
534
- }
535
- /**
536
- * Generic interface for cryptographic operations.
537
- *
538
- * @template TKey - The encryption key type (CryptoKey for browser, Buffer for Node.js)
539
- */
540
- interface CryptoOperations<TKey = unknown> {
541
- /**
542
- * Encryption key for all document operations.
543
- * All documents are encrypted at rest using this key.
544
- * Browser implementations use CryptoKey, Node.js implementations use Buffer.
545
- */
546
- setEncryptionKey?: (key: TKey) => void;
547
- /**
548
- * Creates an encryption function that encrypts string data using AES-GCM encryption.
549
- * Returns a curried function that uses the instance's encryption key from `getEncryptionKey`.
550
- *
551
- * The returned function signature:
552
- * - `data`: The plaintext string to encrypt
553
- * - Returns: A promise resolving to the encrypted data as a string
554
- */
555
- encrypt: () => (data: string) => Promise<string>;
556
- /**
557
- * Creates a decryption function that decrypts encrypted string data using AES-GCM decryption.
558
- * Returns a curried function that uses the instance's encryption key from `getEncryptionKey`.
559
- *
560
- * The returned function signature:
561
- * - `encryptedData`: The encrypted string data to decrypt
562
- * - Returns: A promise resolving to the decrypted plaintext string
563
- */
564
- decrypt: () => (encryptedData: string) => Promise<string>;
565
- }
566
- /**
567
- * Interface for document store adapters.
568
- * Provides a standard interface for document storage, retrieval, modification, and subscription operations.
569
- *
570
- * @template TKey - The encryption key type (CryptoKey for browser, Buffer for Node.js)
571
- */
572
- interface StoreAdapter {
573
- /**
574
- * Optional: Gets the network adapter for stores that support network synchronization.
575
- * Returns null if no network adapter is configured.
576
- * This property is only available on stores that implement network synchronization.
577
- * The type is `any` to avoid coupling core types to Automerge-specific types.
578
- */
579
- readonly networkAdapter?: any | null;
580
- /**
581
- * Sets the encryption key for the store. Store operations aren't possible until the encryption key is set.
582
- *
583
- * @template TKey - The encryption key type (CryptoKey for browser, Buffer for Node.js)
584
- * @param key - The encryption key to set
585
- */
586
- setEncryptionKey<TKey = unknown>(key: TKey): void;
587
- /**
588
- * Sets the owner identifier for document ownership (e.g., auth.masterPublicKey).
589
- * Stored unencrypted in EncryptedDocument for server-side verification.
590
- * Should be chain-independent for multi-blockchain applications.
591
- *
592
- * @param publicKey - The owner's public key
593
- */
594
- setOwnerPublicKey(publicKey: string): void;
595
- /**
596
- * Creates a new document with automatic encryption.
597
- *
598
- * The document is encrypted before being stored.
599
- * Returns the document URL which can be used to retrieve or subscribe to the document.
600
- *
601
- * @template T - The document type (must extend BaseDocument)
602
- * @param doc - The document to create (must include a 'type' field)
603
- * @param url - Optional Automerge URL for deterministic document IDs
604
- * @returns Promise resolving to the document URL
605
- * @throws {Error} If document is missing 'type' field or encryption fails
606
- */
607
- create<T extends BaseDocument>(doc: ExternalDocument<T>, url?: string): Promise<string>;
608
- /**
609
- * Retrieves and decrypts a document by ID.
610
- *
611
- * @template T - The expected document type
612
- * @param id - The document URL/ID
613
- * @returns Promise resolving to the decrypted document, or null if not found
614
- * @throws {Error} If document ID is invalid or decryption fails
615
- */
616
- get<T extends BaseDocument>(id: string): Promise<T | null>;
617
- /**
618
- * Modifies a document with automatic re-encryption.
619
- *
620
- * The document is decrypted, modified via the callback, then re-encrypted.
621
- * Changes are applied atomically.
622
- * The document includes id, createdAt, and updatedAt fields automatically.
623
- *
624
- * **Protected Fields**: The fields `id`, `createdAt`, and `updatedAt` are managed
625
- * by the library and cannot be modified. Any attempts to change these fields in
626
- * the callback will be ignored and restored to their original values. The library
627
- * automatically updates `updatedAt` when changes are made.
628
- *
629
- * @template T - The document type
630
- * @param id - The document ID to modify
631
- * @param callback - Function that receives the decrypted document to modify
632
- * @returns Promise that resolves when the change is applied
633
- * @throws {Error} If document not found or encryption fails
634
- */
635
- change<T extends BaseDocument>(id: string, callback: (doc: T) => void): Promise<void>;
636
- /**
637
- * Deletes a document and cleans up all associated subscriptions.
638
- *
639
- * This removes the document from storage and automatically
640
- * unsubscribes all active listeners to prevent memory leaks.
641
- *
642
- * @param id - The document ID to delete
643
- * @returns Promise that resolves when deletion is complete
644
- */
645
- delete(id: string): Promise<void>;
646
- /**
647
- * Subscribes to document changes with automatic decryption.
648
- *
649
- * The callback receives the decrypted document whenever it changes.
650
- * Multiple subscriptions to the same document are supported via different contexts.
651
- *
652
- * @template T - The document type
653
- * @param config - Subscription configuration
654
- * @returns Unsubscribe function to stop receiving updates
655
- */
656
- subscribe<T extends BaseDocument>(config: SubscribeConfig<T>): () => void;
657
- /**
658
- * Unsubscribes from document changes using document ID and context.
659
- *
660
- * Alternative to calling the unsubscribe function returned by subscribe().
661
- *
662
- * @param config - Object containing document ID and context
663
- * @returns true if subscription was found and removed, false otherwise
664
- */
665
- unsubscribe(config: UnsubscribeConfig): boolean;
666
- /**
667
- * Gets all active subscription contexts for a document.
668
- * Useful for debugging subscription state.
669
- *
670
- * @param id - The document ID
671
- * @returns Array of context identifiers currently subscribed to this document
672
- */
673
- getActiveSubscriptions(id: string): string[];
674
- /**
675
- * Gets all active subscriptions across all documents.
676
- * Useful for debugging memory leaks or subscription issues.
677
- *
678
- * @returns Object mapping document IDs to arrays of context identifiers
679
- */
680
- getAllActiveSubscriptions(): Record<string, string[]>;
681
- }
682
-
683
435
  type ActionType = "primary" | "secondary";
684
436
  interface SlideAction {
685
437
  type: ActionType;
@@ -696,9 +448,9 @@ interface AppInfo {
696
448
  appId: number;
697
449
  icon: string;
698
450
  name: string;
699
- secret: string;
700
451
  description: string;
701
452
  steps: WalkthroughStep[];
453
+ hideWalletUI?: boolean;
702
454
  }
703
455
 
704
456
  interface KeyTransportAdapter {
@@ -722,11 +474,13 @@ interface KeyTransportAdapter {
722
474
  getDeviceInfo: () => Promise<Record<string, any>>;
723
475
  getHostname: () => Promise<string>;
724
476
  connectPresence: (topic: string) => Promise<void>;
725
- broadcastClientState: (id: string, state: ClientConnectionState) => Promise<void>;
477
+ broadcastClientState: (id: string, state: ClientConnectionState, name?: string, isHeartbeat?: boolean) => Promise<void>;
726
478
  onClientStateRequest: (callback: () => void) => Promise<void> | Promise<() => void>;
727
479
  onClientStateUpdate: (callback: (response: {
728
480
  id: string;
729
481
  state: ClientConnectionState;
482
+ name?: string;
483
+ isHeartbeat?: boolean;
730
484
  }) => void) => Promise<void> | Promise<() => void>;
731
485
  getPeerState: (id: string) => ClientConnectionState | undefined;
732
486
  getAllPeers: () => ReadonlyMap<string, ClientConnectionState>;
@@ -738,11 +492,13 @@ type OnSetupEventCallback = (options: {
738
492
 
739
493
  interface PresenceAdapter {
740
494
  connectPresence: (topic: string) => Promise<void>;
741
- broadcastClientState: (id: string, state: ClientConnectionState) => Promise<void>;
495
+ broadcastClientState: (id: string, state: ClientConnectionState, name?: string, isHeartbeat?: boolean) => Promise<void>;
742
496
  onClientStateRequest: (callback: () => void) => Promise<void> | Promise<() => void>;
743
497
  onClientStateUpdate: (callback: (response: {
744
498
  id: string;
745
499
  state: ClientConnectionState;
500
+ name?: string;
501
+ isHeartbeat?: boolean;
746
502
  }) => void) => Promise<void> | Promise<() => void>;
747
503
  getPeerState: (id: string) => ClientConnectionState | undefined;
748
504
  getAllPeers: () => ReadonlyMap<string, ClientConnectionState>;
@@ -751,7 +507,6 @@ interface PresenceAdapter {
751
507
  interface CryptForgeClientOptions {
752
508
  secrets: KeyTransportAdapter;
753
509
  presence: PresenceAdapter;
754
- data: StoreAdapter;
755
510
  appInfo: AppInfo;
756
511
  blockchain: BlockchainAdapter;
757
512
  auth: AuthAdapter;
@@ -759,7 +514,6 @@ interface CryptForgeClientOptions {
759
514
  interface CryptForgeClient {
760
515
  secrets: KeyTransportAdapter;
761
516
  presence: PresenceAdapter;
762
- data: StoreAdapter;
763
517
  appInfo: AppInfo;
764
518
  blockchain: BlockchainAdapter;
765
519
  auth: AuthAdapter;
@@ -769,4 +523,4 @@ type ClientConnectionState = "unknown" | "connecting" | "connected" | "idle" | "
769
523
 
770
524
  declare const version = "0.1.0";
771
525
 
772
- export { type ActionType, type AppInfo, type AuthAdapter, type AuthChangeCallback, type AuthEvent, type AuthState, type BaseDocument, type BlockchainAdapter, type BlockchainType, type Chain, type ChainData, type ClientConnectionState, type CreateIdentityOptions, type CryptForgeClient, type CryptForgeClientOptions, type CryptoOperations, type DeriveDataKeyOptions, type DeriveKeyOptions, type EncryptedDocument, type ExternalDocument, type GenerateMnemonicOptions, type Identity, type KeyData, type KeyTransportAdapter, type Keys, type OnSetupEventCallback, type PresenceAdapter, type RestoreIdentityOptions, type SignMessageOptions, type SignTransactionOptions, type SlideAction, type StoreAdapter, type StoredIdentity, type SubscribeConfig, type TokenBalance, type TokenTransfer, type Transaction, type TransactionOptions, type TransactionReceipt, type TransactionStatusUpdate, type UnlockOptions, type UnsubscribeConfig, type WalkthroughStep, createCryptForgeClient, version };
526
+ export { type ActionType, type AppInfo, type AuthAdapter, type AuthChangeCallback, type AuthEvent, type AuthState, type BlockchainAdapter, type BlockchainType, type Chain, type ChainData, type ClientConnectionState, type CreateIdentityOptions, type CryptForgeClient, type CryptForgeClientOptions, type DeriveDataKeyOptions, type DeriveKeyOptions, type GenerateMnemonicOptions, type Identity, type KeyData, type KeyTransportAdapter, type Keys, type OnSetupEventCallback, type PresenceAdapter, type RestoreIdentityOptions, type SignMessageOptions, type SignTransactionOptions, type SlideAction, type StoredIdentity, type TokenBalance, type TokenTransfer, type Transaction, type TransactionOptions, type TransactionReceipt, type TransactionStatusUpdate, type UnlockOptions, type WalkthroughStep, createCryptForgeClient, version };
package/dist/index.js CHANGED
@@ -30,7 +30,6 @@ function createCryptForgeClient(options) {
30
30
  return {
31
31
  secrets: options.secrets,
32
32
  presence: options.presence,
33
- data: options.data,
34
33
  appInfo: options.appInfo,
35
34
  blockchain: options.blockchain,
36
35
  auth: options.auth
package/dist/index.mjs CHANGED
@@ -3,7 +3,6 @@ function createCryptForgeClient(options) {
3
3
  return {
4
4
  secrets: options.secrets,
5
5
  presence: options.presence,
6
- data: options.data,
7
6
  appInfo: options.appInfo,
8
7
  blockchain: options.blockchain,
9
8
  auth: options.auth
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptforge/core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Core types and interfaces for the CryptForge SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",