@opensecret/react 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  This is a React SDK for the [OpenSecret](https://opensecret.cloud) platform.
4
4
 
5
+ 🚧 We're currently in preview mode, please contact us at team@opensecret.cloud for the preview URL and getting started info 🚧
6
+
5
7
  ## Installation
6
8
 
7
9
  ```bash
@@ -17,7 +19,7 @@ import { OpenSecretProvider } from "@opensecret/react";
17
19
 
18
20
  function App() {
19
21
  return (
20
- <OpenSecretProvider apiUrl="https://preview-enclave.opensecret.cloud">
22
+ <OpenSecretProvider apiUrl="{URL}">
21
23
  <App />
22
24
  </OpenSecretProvider>
23
25
  );
@@ -53,7 +55,7 @@ function App() {
53
55
  The `OpenSecretProvider` component is the main entry point for the SDK. It requires a single prop, `apiUrl`, which should be set to the URL of your OpenSecret backend.
54
56
 
55
57
  ```tsx
56
- <OpenSecretProvider apiUrl="https://preview-enclave.opensecret.cloud">
58
+ <OpenSecretProvider apiUrl="{URL}">
57
59
  <App />
58
60
  </OpenSecretProvider>
59
61
  ```
@@ -82,13 +84,40 @@ The `useOpenSecret` hook provides access to the OpenSecret API. It returns an ob
82
84
  - `generateThirdPartyToken(audience: string): Promise<{ token: string }>`: Generates a JWT token for use with pre-authorized third-party services (e.g. "https://api.devservice.com"). Developers must register this URL in advance (coming soon).
83
85
 
84
86
  #### Cryptographic Methods
85
- - `getPrivateKey(): Promise<PrivateKeyResponse>`: Retrieves the user's private key mnemonic phrase. This is used for cryptographic operations and should be kept secure.
86
-
87
- - `getPublicKey(algorithm: 'schnorr' | 'ecdsa'): Promise<PublicKeyResponse>`: Retrieves the user's public key for the specified signing algorithm. Supports two algorithms:
87
+ - `getPrivateKey(): Promise<{ mnemonic: string }>`: Retrieves the user's private key mnemonic phrase. This is used for cryptographic operations and should be kept secure.
88
+
89
+ - `getPrivateKeyBytes(derivationPath?: string): Promise<{ private_key: string }>`: Retrieves the private key bytes for a given BIP32 derivation path. If no path is provided, returns the master private key bytes.
90
+ - Supports both absolute (starting with "m/") and relative paths
91
+ - Supports hardened derivation using either ' or h notation
92
+ Examples:
93
+ - Absolute path: "m/44'/0'/0'/0/0"
94
+ - Relative path: "0'/0'/0'/0/0"
95
+ - Hardened notation: "44'" or "44h"
96
+ - Common paths:
97
+ - BIP44 (Legacy): `m/44'/0'/0'/0/0`
98
+ - BIP49 (SegWit): `m/49'/0'/0'/0/0`
99
+ - BIP84 (Native SegWit): `m/84'/0'/0'/0/0`
100
+ - BIP86 (Taproot): `m/86'/0'/0'/0/0`
101
+
102
+ - `getPublicKey(algorithm: 'schnorr' | 'ecdsa', derivationPath?: string): Promise<PublicKeyResponse>`: Retrieves the user's public key for the specified signing algorithm and optional derivation path. The derivation path determines which child key pair is used, allowing different public keys to be generated from the same master key. This is useful for:
103
+ - Separating keys by purpose (e.g., different chains or applications)
104
+ - Generating deterministic addresses
105
+ - Supporting different address formats (Legacy, SegWit, Native SegWit, Taproot)
106
+
107
+ Supports two algorithms:
88
108
  - `'schnorr'`: For Schnorr signatures
89
109
  - `'ecdsa'`: For ECDSA signatures
90
110
 
91
- - `signMessage(messageBytes: Uint8Array, algorithm: 'schnorr' | 'ecdsa'): Promise<SignatureResponse>`: Signs a message using the specified algorithm. The message must be provided as a Uint8Array of bytes. Returns a signature that can be verified using the corresponding public key.
111
+ - `signMessage(messageBytes: Uint8Array, algorithm: 'schnorr' | 'ecdsa', derivationPath?: string): Promise<SignatureResponse>`: Signs a message using the specified algorithm and optional derivation path. The message must be provided as a Uint8Array of bytes. Returns a signature that can be verified using the corresponding public key.
112
+
113
+ Example message preparation:
114
+ ```typescript
115
+ // From string
116
+ const messageBytes = new TextEncoder().encode("Hello, World!");
117
+
118
+ // From hex
119
+ const messageBytes = new Uint8Array(Buffer.from("deadbeef", "hex"));
120
+ ```
92
121
 
93
122
  ### AI Integration
94
123
 
@@ -152,6 +181,12 @@ To pack the library (for publishing) run the following command:
152
181
  bun run pack
153
182
  ```
154
183
 
184
+ To deploy:
185
+
186
+ ```bash
187
+ NPM_CONFIG_TOKEN=$NPM_CONFIG_TOKEN bun publish --access public
188
+ ```
189
+
155
190
  ## License
156
191
 
157
192
  This project is licensed under the MIT License.
package/dist/index.d.ts CHANGED
@@ -28,6 +28,7 @@ declare namespace api {
28
28
  initiateGoogleAuth,
29
29
  handleGoogleCallback,
30
30
  fetchPrivateKey,
31
+ fetchPrivateKeyBytes,
31
32
  signMessage,
32
33
  fetchPublicKey,
33
34
  convertGuestToEmailAccount,
@@ -38,7 +39,9 @@ declare namespace api {
38
39
  GithubAuthResponse,
39
40
  GoogleAuthResponse,
40
41
  PrivateKeyResponse,
42
+ PrivateKeyBytesResponse,
41
43
  SignMessageResponse,
44
+ SignMessageRequest,
42
45
  PublicKeyResponse,
43
46
  ThirdPartyTokenRequest,
44
47
  ThirdPartyTokenResponse
@@ -114,7 +117,36 @@ declare function fetchLogout(refresh_token: string): Promise<void>;
114
117
 
115
118
  declare function fetchPrivateKey(): Promise<PrivateKeyResponse>;
116
119
 
117
- declare function fetchPublicKey(algorithm: SigningAlgorithm): Promise<PublicKeyResponse>;
120
+ /**
121
+ * Fetches private key bytes for a given derivation path
122
+ * @param derivationPath - Optional BIP32 derivation path
123
+ *
124
+ * Supports both absolute and relative paths with hardened derivation:
125
+ * - Absolute path: "m/44'/0'/0'/0/0"
126
+ * - Relative path: "0'/0'/0'/0/0"
127
+ * - Hardened notation: "44'" or "44h"
128
+ *
129
+ * Common paths:
130
+ * - BIP44 (Legacy): m/44'/0'/0'/0/0
131
+ * - BIP49 (SegWit): m/49'/0'/0'/0/0
132
+ * - BIP84 (Native SegWit): m/84'/0'/0'/0/0
133
+ * - BIP86 (Taproot): m/86'/0'/0'/0/0
134
+ */
135
+ declare function fetchPrivateKeyBytes(derivationPath?: string): Promise<PrivateKeyBytesResponse>;
136
+
137
+ /**
138
+ * Retrieves the public key for a given algorithm and derivation path
139
+ * @param algorithm - Signing algorithm (schnorr or ecdsa)
140
+ * @param derivationPath - Optional BIP32 derivation path
141
+ *
142
+ * The derivation path determines which child key pair is used,
143
+ * allowing different public keys to be generated from the same master key.
144
+ * This is useful for:
145
+ * - Separating keys by purpose (e.g., different chains or applications)
146
+ * - Generating deterministic addresses
147
+ * - Supporting different address formats (Legacy, SegWit, Native SegWit, Taproot)
148
+ */
149
+ declare function fetchPublicKey(algorithm: SigningAlgorithm, derivationPath?: string): Promise<PublicKeyResponse>;
118
150
 
119
151
  declare function fetchPut(key: string, value: string): Promise<string>;
120
152
 
@@ -126,7 +158,7 @@ export declare function generateSecureSecret(): string;
126
158
 
127
159
  declare function generateThirdPartyToken(audience: string): Promise<ThirdPartyTokenResponse>;
128
160
 
129
- declare function getAttestation(forceRefresh?: boolean): Promise<Attestation>;
161
+ declare function getAttestation(forceRefresh?: boolean, apiUrl?: string): Promise<Attestation>;
130
162
 
131
163
  export declare type GithubAuthResponse = {
132
164
  auth_url: string;
@@ -335,9 +367,29 @@ export declare type OpenSecretContextType = {
335
367
  * @throws {Error} If the private key cannot be retrieved
336
368
  */
337
369
  getPrivateKey: typeof api.fetchPrivateKey;
370
+ /**
371
+ * Retrieves the private key bytes for a given derivation path
372
+ * @param derivationPath - Optional BIP32 derivation path (e.g. "m/44'/0'/0'/0/0")
373
+ * @returns A promise resolving to the private key bytes response
374
+ * @throws {Error} If:
375
+ * - The private key bytes cannot be retrieved
376
+ * - The derivation path is invalid
377
+ *
378
+ * @description
379
+ * - If no derivation path is provided, returns the master private key bytes
380
+ * - Supports both absolute (starting with "m/") and relative paths
381
+ * - Supports hardened derivation using either ' or h notation
382
+ * - Common paths:
383
+ * - BIP44 (Legacy): m/44'/0'/0'/0/0
384
+ * - BIP49 (SegWit): m/49'/0'/0'/0/0
385
+ * - BIP84 (Native SegWit): m/84'/0'/0'/0/0
386
+ * - BIP86 (Taproot): m/86'/0'/0'/0/0
387
+ */
388
+ getPrivateKeyBytes: typeof api.fetchPrivateKeyBytes;
338
389
  /**
339
390
  * Retrieves the user's public key for the specified algorithm
340
391
  * @param algorithm - The signing algorithm ('schnorr' or 'ecdsa')
392
+ * @param derivationPath - Optional BIP32 derivation path
341
393
  * @returns A promise resolving to the public key response
342
394
  * @throws {Error} If the public key cannot be retrieved
343
395
  */
@@ -346,6 +398,7 @@ export declare type OpenSecretContextType = {
346
398
  * Signs a message using the specified algorithm
347
399
  * @param messageBytes - The message to sign as a Uint8Array
348
400
  * @param algorithm - The signing algorithm ('schnorr' or 'ecdsa')
401
+ * @param derivationPath - Optional BIP32 derivation path
349
402
  * @returns A promise resolving to the signature response
350
403
  * @throws {Error} If the message signing fails
351
404
  */
@@ -487,12 +540,20 @@ export declare type PcrConfig = {
487
540
  pcr0DevValues?: string[];
488
541
  };
489
542
 
543
+ declare type PrivateKeyBytesResponse = {
544
+ /** 32-byte hex string (64 characters) representing the private key */
545
+ private_key: string;
546
+ };
547
+
490
548
  declare type PrivateKeyResponse = {
549
+ /** 12-word BIP39 mnemonic phrase */
491
550
  mnemonic: string;
492
551
  };
493
552
 
494
553
  declare type PublicKeyResponse = {
554
+ /** Public key in hex format */
495
555
  public_key: string;
556
+ /** The algorithm used (schnorr or ecdsa) */
496
557
  algorithm: SigningAlgorithm;
497
558
  };
498
559
 
@@ -511,10 +572,36 @@ declare function setApiUrl(url: string): void;
511
572
 
512
573
  declare type SigningAlgorithm = "schnorr" | "ecdsa";
513
574
 
514
- declare function signMessage(message_bytes: Uint8Array, algorithm: SigningAlgorithm): Promise<SignMessageResponse>;
575
+ /**
576
+ * Signs a message using the specified algorithm and derivation path
577
+ * @param message_bytes - Message to sign as Uint8Array
578
+ * @param algorithm - Signing algorithm (schnorr or ecdsa)
579
+ * @param derivationPath - Optional BIP32 derivation path
580
+ *
581
+ * Example message preparation:
582
+ * ```typescript
583
+ * // From string
584
+ * const messageBytes = new TextEncoder().encode("Hello, World!");
585
+ *
586
+ * // From hex
587
+ * const messageBytes = new Uint8Array(Buffer.from("deadbeef", "hex"));
588
+ * ```
589
+ */
590
+ declare function signMessage(message_bytes: Uint8Array, algorithm: SigningAlgorithm, derivationPath?: string): Promise<SignMessageResponse>;
591
+
592
+ declare type SignMessageRequest = {
593
+ /** Base64-encoded message to sign */
594
+ message_base64: string;
595
+ /** Signing algorithm to use (schnorr or ecdsa) */
596
+ algorithm: SigningAlgorithm;
597
+ /** Optional BIP32 derivation path (e.g., "m/44'/0'/0'/0/0") */
598
+ derivation_path?: string;
599
+ };
515
600
 
516
601
  declare type SignMessageResponse = {
602
+ /** Signature in hex format */
517
603
  signature: string;
604
+ /** Message hash in hex format */
518
605
  message_hash: string;
519
606
  };
520
607