@opensecret/react 0.3.1 → 0.3.3
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 +40 -5
- package/dist/index.d.ts +89 -2
- package/dist/opensecret-react.es.js +1792 -1772
- package/dist/opensecret-react.umd.js +26 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -82,13 +82,40 @@ The `useOpenSecret` hook provides access to the OpenSecret API. It returns an ob
|
|
|
82
82
|
- `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
83
|
|
|
84
84
|
#### Cryptographic Methods
|
|
85
|
-
- `getPrivateKey(): Promise<
|
|
86
|
-
|
|
87
|
-
- `
|
|
85
|
+
- `getPrivateKey(): Promise<{ mnemonic: string }>`: Retrieves the user's private key mnemonic phrase. This is used for cryptographic operations and should be kept secure.
|
|
86
|
+
|
|
87
|
+
- `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.
|
|
88
|
+
- Supports both absolute (starting with "m/") and relative paths
|
|
89
|
+
- Supports hardened derivation using either ' or h notation
|
|
90
|
+
Examples:
|
|
91
|
+
- Absolute path: "m/44'/0'/0'/0/0"
|
|
92
|
+
- Relative path: "0'/0'/0'/0/0"
|
|
93
|
+
- Hardened notation: "44'" or "44h"
|
|
94
|
+
- Common paths:
|
|
95
|
+
- BIP44 (Legacy): `m/44'/0'/0'/0/0`
|
|
96
|
+
- BIP49 (SegWit): `m/49'/0'/0'/0/0`
|
|
97
|
+
- BIP84 (Native SegWit): `m/84'/0'/0'/0/0`
|
|
98
|
+
- BIP86 (Taproot): `m/86'/0'/0'/0/0`
|
|
99
|
+
|
|
100
|
+
- `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:
|
|
101
|
+
- Separating keys by purpose (e.g., different chains or applications)
|
|
102
|
+
- Generating deterministic addresses
|
|
103
|
+
- Supporting different address formats (Legacy, SegWit, Native SegWit, Taproot)
|
|
104
|
+
|
|
105
|
+
Supports two algorithms:
|
|
88
106
|
- `'schnorr'`: For Schnorr signatures
|
|
89
107
|
- `'ecdsa'`: For ECDSA signatures
|
|
90
108
|
|
|
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.
|
|
109
|
+
- `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.
|
|
110
|
+
|
|
111
|
+
Example message preparation:
|
|
112
|
+
```typescript
|
|
113
|
+
// From string
|
|
114
|
+
const messageBytes = new TextEncoder().encode("Hello, World!");
|
|
115
|
+
|
|
116
|
+
// From hex
|
|
117
|
+
const messageBytes = new Uint8Array(Buffer.from("deadbeef", "hex"));
|
|
118
|
+
```
|
|
92
119
|
|
|
93
120
|
### AI Integration
|
|
94
121
|
|
|
@@ -144,12 +171,20 @@ To build the library, run the following command:
|
|
|
144
171
|
bun run build
|
|
145
172
|
```
|
|
146
173
|
|
|
147
|
-
|
|
174
|
+
Currently this build step requires `npx` because of [a Bun incompatibility with `vite-plugin-dts`](https://github.com/OpenSecretCloud/OpenSecret-SDK/issues/16).
|
|
175
|
+
|
|
176
|
+
To pack the library (for publishing) run the following command:
|
|
148
177
|
|
|
149
178
|
```bash
|
|
150
179
|
bun run pack
|
|
151
180
|
```
|
|
152
181
|
|
|
182
|
+
To deploy:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
NPM_CONFIG_TOKEN=$NPM_CONFIG_TOKEN bun publish --access public
|
|
186
|
+
```
|
|
187
|
+
|
|
153
188
|
## License
|
|
154
189
|
|
|
155
190
|
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
|
-
|
|
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
|
|
|
@@ -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
|
-
|
|
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
|
|