Skip to content

Commit 1f83438

Browse files
feat: add account derivation functions for extended private keys (#132)
* feat: add account derivation functions for extended private keys * docs
1 parent bc2a532 commit 1f83438

File tree

12 files changed

+1604
-316
lines changed

12 files changed

+1604
-316
lines changed

key-wallet-ffi/FFI_API.md

Lines changed: 166 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document provides a comprehensive reference for all FFI (Foreign Function I
44

55
**Auto-generated**: This documentation is automatically generated from the source code. Do not edit manually.
66

7-
**Total Functions**: 222
7+
**Total Functions**: 232
88

99
## Table of Contents
1010

@@ -130,7 +130,7 @@ Functions: 57
130130

131131
### Account Management
132132

133-
Functions: 81
133+
Functions: 92
134134

135135
| Function | Description | Module |
136136
|----------|-------------|--------|
@@ -161,17 +161,28 @@ Functions: 81
161161
| `account_collection_summary` | Get a human-readable summary of all accounts in the collection Returns a for... | account_collection |
162162
| `account_collection_summary_data` | Get structured account collection summary data Returns a struct containing a... | account_collection |
163163
| `account_collection_summary_free` | Free an account collection summary and all its allocated memory # Safety - ... | account_collection |
164+
| `account_derive_extended_private_key_at` | Derive an extended private key from an account at a given index, using the pr... | account_derivation |
165+
| `account_derive_extended_private_key_from_mnemonic` | Derive an extended private key from a mnemonic + optional passphrase at the g... | account_derivation |
166+
| `account_derive_extended_private_key_from_seed` | Derive an extended private key from a raw seed buffer at the given index | account_derivation |
167+
| `account_derive_private_key_as_wif_at` | Derive a private key from an account at a given chain/index and return as WIF... | account_derivation |
168+
| `account_derive_private_key_at` | Derive a private key (secp256k1) from an account at a given chain/index, usin... | account_derivation |
169+
| `account_derive_private_key_from_mnemonic` | Derive a private key from a mnemonic + optional passphrase at the given index | account_derivation |
170+
| `account_derive_private_key_from_seed` | Derive a private key from a raw seed buffer at the given index | account_derivation |
164171
| `account_free` | Free an account handle # Safety - `account` must be a valid pointer to an F... | account |
165172
| `account_get_account_type` | Get the account type of an account # Safety - `account` must be a valid poi... | account |
166173
| `account_get_extended_public_key_as_string` | Get the extended public key of an account as a string # Safety - `account` ... | account |
167174
| `account_get_is_watch_only` | Check if an account is watch-only # Safety - `account` must be a valid poin... | account |
168175
| `account_get_network` | Get the network of an account # Safety - `account` must be a valid pointer ... | account |
176+
| `bls_account_derive_private_key_from_mnemonic` | No description | account_derivation |
177+
| `bls_account_derive_private_key_from_seed` | No description | account_derivation |
169178
| `bls_account_free` | No description | account |
170179
| `bls_account_get_account_type` | No description | account |
171180
| `bls_account_get_extended_public_key_as_string` | No description | account |
172181
| `bls_account_get_is_watch_only` | No description | account |
173182
| `bls_account_get_network` | No description | account |
174183
| `derivation_bip44_account_path` | Derive a BIP44 account path (m/44'/5'/account') | derivation |
184+
| `eddsa_account_derive_private_key_from_mnemonic` | No description | account_derivation |
185+
| `eddsa_account_derive_private_key_from_seed` | No description | account_derivation |
175186
| `eddsa_account_free` | No description | account |
176187
| `eddsa_account_get_account_type` | No description | account |
177188
| `eddsa_account_get_extended_public_key_as_string` | No description | account |
@@ -255,15 +266,14 @@ Functions: 13
255266

256267
### Key Management
257268

258-
Functions: 15
269+
Functions: 14
259270

260271
| Function | Description | Module |
261272
|----------|-------------|--------|
262273
| `bip38_decrypt_private_key` | Decrypt a BIP38 encrypted private key # Safety This function is unsafe beca... | bip38 |
263274
| `bip38_encrypt_private_key` | Encrypt a private key with BIP38 # Safety This function is unsafe because i... | bip38 |
264275
| `derivation_derive_private_key_from_seed` | Derive private key for a specific path from seed # Safety - `seed` must be ... | derivation |
265276
| `derivation_new_master_key` | Create a new master extended private key from seed # Safety - `seed` must b... | derivation |
266-
| `dip9_derive_identity_key` | Derive key using DIP9 path constants for identity # Safety - `seed` must be... | derivation |
267277
| `extended_private_key_free` | Free an extended private key # Safety - `key` must be a valid pointer creat... | keys |
268278
| `extended_private_key_get_private_key` | Get the private key from an extended private key Extracts the non-extended p... | keys |
269279
| `extended_private_key_to_string` | Get extended private key as string (xprv format) Returns the extended privat... | keys |
@@ -1982,6 +1992,118 @@ Free an account collection summary and all its allocated memory # Safety - `su
19821992

19831993
---
19841994

1995+
#### `account_derive_extended_private_key_at`
1996+
1997+
```c
1998+
account_derive_extended_private_key_at(account: *const FFIAccount, master_xpriv: *const FFIExtendedPrivateKey, index: c_uint, error: *mut FFIError,) -> *mut FFIExtendedPrivateKey
1999+
```
2000+
2001+
**Description:**
2002+
Derive an extended private key from an account at a given index, using the provided master xpriv. Returns an opaque FFIExtendedPrivateKey pointer that must be freed with `extended_private_key_free`. Notes: - This is chain-agnostic. For accounts with internal/external chains, this returns an error. - For hardened-only account types (e.g., EdDSA), a hardened index is used. # Safety - `account` and `master_xpriv` must be valid, non-null pointers allocated by this library. - `error` must be a valid pointer to an FFIError or null. - The caller must free the returned pointer with `extended_private_key_free`.
2003+
2004+
**Safety:**
2005+
- `account` and `master_xpriv` must be valid, non-null pointers allocated by this library. - `error` must be a valid pointer to an FFIError or null. - The caller must free the returned pointer with `extended_private_key_free`.
2006+
2007+
**Module:** `account_derivation`
2008+
2009+
---
2010+
2011+
#### `account_derive_extended_private_key_from_mnemonic`
2012+
2013+
```c
2014+
account_derive_extended_private_key_from_mnemonic(account: *const FFIAccount, mnemonic: *const c_char, passphrase: *const c_char, index: c_uint, error: *mut FFIError,) -> *mut FFIExtendedPrivateKey
2015+
```
2016+
2017+
**Description:**
2018+
Derive an extended private key from a mnemonic + optional passphrase at the given index. Returns an opaque FFIExtendedPrivateKey pointer that must be freed with `extended_private_key_free`. # Safety - `account` must be a valid pointer to an FFIAccount - `mnemonic` must be a valid, null-terminated C string - `passphrase` may be null; if not null, must be a valid C string - `error` must be a valid pointer to an FFIError or null
2019+
2020+
**Safety:**
2021+
- `account` must be a valid pointer to an FFIAccount - `mnemonic` must be a valid, null-terminated C string - `passphrase` may be null; if not null, must be a valid C string - `error` must be a valid pointer to an FFIError or null
2022+
2023+
**Module:** `account_derivation`
2024+
2025+
---
2026+
2027+
#### `account_derive_extended_private_key_from_seed`
2028+
2029+
```c
2030+
account_derive_extended_private_key_from_seed(account: *const FFIAccount, seed: *const u8, seed_len: usize, index: c_uint, error: *mut FFIError,) -> *mut FFIExtendedPrivateKey
2031+
```
2032+
2033+
**Description:**
2034+
Derive an extended private key from a raw seed buffer at the given index. Returns an opaque FFIExtendedPrivateKey pointer that must be freed with `extended_private_key_free`. # Safety - `account` must be a valid pointer to an FFIAccount - `seed` must point to a valid buffer of length `seed_len` - `error` must be a valid pointer to an FFIError or null
2035+
2036+
**Safety:**
2037+
- `account` must be a valid pointer to an FFIAccount - `seed` must point to a valid buffer of length `seed_len` - `error` must be a valid pointer to an FFIError or null
2038+
2039+
**Module:** `account_derivation`
2040+
2041+
---
2042+
2043+
#### `account_derive_private_key_as_wif_at`
2044+
2045+
```c
2046+
account_derive_private_key_as_wif_at(account: *const FFIAccount, master_xpriv: *const FFIExtendedPrivateKey, index: c_uint, error: *mut FFIError,) -> *mut c_char
2047+
```
2048+
2049+
**Description:**
2050+
Derive a private key from an account at a given chain/index and return as WIF string. Caller must free the returned string with `string_free`. # Safety - `account` and `master_xpriv` must be valid pointers allocated by this library - `error` must be a valid pointer to an FFIError or null
2051+
2052+
**Safety:**
2053+
- `account` and `master_xpriv` must be valid pointers allocated by this library - `error` must be a valid pointer to an FFIError or null
2054+
2055+
**Module:** `account_derivation`
2056+
2057+
---
2058+
2059+
#### `account_derive_private_key_at`
2060+
2061+
```c
2062+
account_derive_private_key_at(account: *const FFIAccount, master_xpriv: *const FFIExtendedPrivateKey, index: c_uint, error: *mut FFIError,) -> *mut FFIPrivateKey
2063+
```
2064+
2065+
**Description:**
2066+
Derive a private key (secp256k1) from an account at a given chain/index, using the provided master xpriv. Returns an opaque FFIPrivateKey pointer that must be freed with `private_key_free`. # Safety - `account` and `master_xpriv` must be valid pointers allocated by this library - `error` must be a valid pointer to an FFIError or null
2067+
2068+
**Safety:**
2069+
- `account` and `master_xpriv` must be valid pointers allocated by this library - `error` must be a valid pointer to an FFIError or null
2070+
2071+
**Module:** `account_derivation`
2072+
2073+
---
2074+
2075+
#### `account_derive_private_key_from_mnemonic`
2076+
2077+
```c
2078+
account_derive_private_key_from_mnemonic(account: *const FFIAccount, mnemonic: *const c_char, passphrase: *const c_char, index: c_uint, error: *mut FFIError,) -> *mut FFIPrivateKey
2079+
```
2080+
2081+
**Description:**
2082+
Derive a private key from a mnemonic + optional passphrase at the given index. Returns an opaque FFIPrivateKey pointer that must be freed with `private_key_free`. # Safety - `account` must be a valid pointer to an FFIAccount - `mnemonic` must be a valid, null-terminated C string - `passphrase` may be null; if not null, must be a valid C string - `error` must be a valid pointer to an FFIError or null
2083+
2084+
**Safety:**
2085+
- `account` must be a valid pointer to an FFIAccount - `mnemonic` must be a valid, null-terminated C string - `passphrase` may be null; if not null, must be a valid C string - `error` must be a valid pointer to an FFIError or null
2086+
2087+
**Module:** `account_derivation`
2088+
2089+
---
2090+
2091+
#### `account_derive_private_key_from_seed`
2092+
2093+
```c
2094+
account_derive_private_key_from_seed(account: *const FFIAccount, seed: *const u8, seed_len: usize, index: c_uint, error: *mut FFIError,) -> *mut FFIPrivateKey
2095+
```
2096+
2097+
**Description:**
2098+
Derive a private key from a raw seed buffer at the given index. Returns an opaque FFIPrivateKey pointer that must be freed with `private_key_free`. # Safety - `account` must be a valid pointer to an FFIAccount - `seed` must point to a valid buffer of length `seed_len` - `error` must be a valid pointer to an FFIError or null
2099+
2100+
**Safety:**
2101+
- `account` must be a valid pointer to an FFIAccount - `seed` must point to a valid buffer of length `seed_len` - `error` must be a valid pointer to an FFIError or null
2102+
2103+
**Module:** `account_derivation`
2104+
2105+
---
2106+
19852107
#### `account_free`
19862108

19872109
```c
@@ -2062,6 +2184,26 @@ Get the network of an account # Safety - `account` must be a valid pointer to
20622184

20632185
---
20642186

2187+
#### `bls_account_derive_private_key_from_mnemonic`
2188+
2189+
```c
2190+
bls_account_derive_private_key_from_mnemonic(account: *const FFIBLSAccount, mnemonic: *const c_char, passphrase: *const c_char, index: c_uint, error: *mut FFIError,) -> *mut c_char
2191+
```
2192+
2193+
**Module:** `account_derivation`
2194+
2195+
---
2196+
2197+
#### `bls_account_derive_private_key_from_seed`
2198+
2199+
```c
2200+
bls_account_derive_private_key_from_seed(account: *const FFIBLSAccount, seed: *const u8, seed_len: usize, index: c_uint, error: *mut FFIError,) -> *mut c_char
2201+
```
2202+
2203+
**Module:** `account_derivation`
2204+
2205+
---
2206+
20652207
#### `bls_account_free`
20662208

20672209
```c
@@ -2125,6 +2267,26 @@ Derive a BIP44 account path (m/44'/5'/account')
21252267

21262268
---
21272269

2270+
#### `eddsa_account_derive_private_key_from_mnemonic`
2271+
2272+
```c
2273+
eddsa_account_derive_private_key_from_mnemonic(account: *const FFIEdDSAAccount, mnemonic: *const c_char, passphrase: *const c_char, index: c_uint, error: *mut FFIError,) -> *mut c_char
2274+
```
2275+
2276+
**Module:** `account_derivation`
2277+
2278+
---
2279+
2280+
#### `eddsa_account_derive_private_key_from_seed`
2281+
2282+
```c
2283+
eddsa_account_derive_private_key_from_seed(account: *const FFIEdDSAAccount, seed: *const u8, seed_len: usize, index: c_uint, error: *mut FFIError,) -> *mut c_char
2284+
```
2285+
2286+
**Module:** `account_derivation`
2287+
2288+
---
2289+
21282290
#### `eddsa_account_free`
21292291

21302292
```c
@@ -3218,22 +3380,6 @@ Create a new master extended private key from seed # Safety - `seed` must be a
32183380

32193381
---
32203382

3221-
#### `dip9_derive_identity_key`
3222-
3223-
```c
3224-
dip9_derive_identity_key(seed: *const u8, seed_len: usize, network: FFINetwork, identity_index: c_uint, key_index: c_uint, key_type: FFIDerivationPathType, error: *mut FFIError,) -> *mut FFIExtendedPrivKey
3225-
```
3226-
3227-
**Description:**
3228-
Derive key using DIP9 path constants for identity # Safety - `seed` must be a valid pointer to a byte array of `seed_len` length - `error` must be a valid pointer to an FFIError structure or null - The caller must ensure the seed pointer remains valid for the duration of this call
3229-
3230-
**Safety:**
3231-
- `seed` must be a valid pointer to a byte array of `seed_len` length - `error` must be a valid pointer to an FFIError structure or null - The caller must ensure the seed pointer remains valid for the duration of this call
3232-
3233-
**Module:** `derivation`
3234-
3235-
---
3236-
32373383
#### `extended_private_key_free`
32383384

32393385
```c

0 commit comments

Comments
 (0)