Skip to content

Commit 12672cf

Browse files
Merge pull request #3 from synonymdev/feat/derive-store-id
feat: add store id derivation
2 parents 931d287 + af508ef commit 12672cf

20 files changed

Lines changed: 243 additions & 17 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vss-rust-client-ffi"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
66

README.md

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ cargo build --release
3232
```swift
3333
import vss_rust_client_ffi
3434

35-
// Initialize VSS client with LNURL-auth
35+
let mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
36+
let passphrase: String? = nil
37+
let storeId = try vssDeriveStoreId(
38+
prefix: "bitkit_v1_regtest",
39+
mnemonic: mnemonic,
40+
passphrase: passphrase
41+
)
42+
3643
try await vssNewClientWithLnurlAuth(
3744
baseUrl: "https://vss.example.com",
38-
storeId: "my-app-store",
39-
mnemonic: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
40-
passphrase: nil,
45+
storeId: storeId,
46+
mnemonic: mnemonic,
47+
passphrase: passphrase,
4148
lnurlAuthServerUrl: "https://auth.example.com/lnurl"
4249
)
4350

@@ -73,12 +80,19 @@ vssShutdownClient()
7380
```python
7481
from vss_rust_client_ffi import *
7582

76-
# Initialize VSS client with LNURL-auth
83+
mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
84+
passphrase = None
85+
store_id = vss_derive_store_id(
86+
prefix="bitkit_v1_regtest",
87+
mnemonic=mnemonic,
88+
passphrase=passphrase
89+
)
90+
7791
await vss_new_client_with_lnurl_auth(
7892
"https://vss.example.com",
79-
"my-app-store",
80-
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
81-
None, # passphrase
93+
store_id,
94+
mnemonic,
95+
passphrase,
8296
"https://auth.example.com/lnurl"
8397
)
8498

@@ -117,12 +131,19 @@ vss_shutdown_client()
117131
```kotlin
118132
import uniffi.vss_rust_client_ffi.*
119133

120-
// Initialize VSS client with LNURL-auth
134+
val mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
135+
val passphrase: String? = null
136+
val storeId = vssDeriveStoreId(
137+
prefix = "bitkit_v1_regtest",
138+
mnemonic = mnemonic,
139+
passphrase = passphrase
140+
)
141+
121142
vssNewClientWithLnurlAuth(
122143
baseUrl = "https://vss.example.com",
123-
storeId = "my-app-store",
124-
mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
125-
passphrase = null,
144+
storeId = storeId,
145+
mnemonic = mnemonic,
146+
passphrase = passphrase,
126147
lnurlAuthServerUrl = "https://auth.example.com/lnurl"
127148
)
128149

@@ -171,6 +192,15 @@ Initialize the global VSS client connection with LNURL-auth authentication. Prov
171192
#### `vssShutdownClient() -> Void`
172193
Shutdown the VSS client and clean up resources. Optional but recommended for clean application shutdown.
173194

195+
### Utility Functions
196+
197+
#### `vssDeriveStoreId(prefix: String, mnemonic: String, passphrase: String?) -> String`
198+
Derives a deterministic VSS store ID from a mnemonic and optional passphrase using BIP32 key derivation.
199+
200+
- `prefix`: A prefix to include in the store ID (e.g., "bitkit_v1_regtest")
201+
- `mnemonic`: BIP39 mnemonic phrase (12 or 24 words)
202+
- `passphrase`: Optional BIP39 passphrase
203+
174204
### Data Operations
175205

176206
#### `vssStore(key: String, value: Data) -> VssItem`
@@ -294,4 +324,4 @@ This project is licensed under the MIT License - see the LICENSE file for detail
294324

295325
- [VSS Server](https://github.com/lightningdevkit/vss-server) - The VSS server implementation
296326
- [vss-client](https://crates.io/crates/vss-client) - The underlying Rust client library
297-
- [UniFFI](https://mozilla.github.io/uniffi-rs/) - The FFI binding generator
327+
- [UniFFI](https://mozilla.github.io/uniffi-rs/) - The FFI binding generator

bindings/android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ android.useAndroidX=true
33
android.nonTransitiveRClass=true
44
kotlin.code.style=official
55
# project settings:
6-
version=0.2.0
6+
version=0.3.0
Binary file not shown.
Binary file not shown.
13.5 KB
Binary file not shown.
Binary file not shown.

bindings/android/src/main/kotlin/com/synonym/vssclient/vss_rust_client_ffi.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,13 @@ internal interface _UniFFILib : Library {
415415

416416
fun uniffi_vss_rust_client_ffi_fn_func_vss_delete(`key`: RustBuffer.ByValue): Pointer
417417

418+
fun uniffi_vss_rust_client_ffi_fn_func_vss_derive_store_id(
419+
`prefix`: RustBuffer.ByValue,
420+
`mnemonic`: RustBuffer.ByValue,
421+
`passphrase`: RustBuffer.ByValue,
422+
_uniffi_out_err: RustCallStatus,
423+
): RustBuffer.ByValue
424+
418425
fun uniffi_vss_rust_client_ffi_fn_func_vss_get(`key`: RustBuffer.ByValue): Pointer
419426

420427
fun uniffi_vss_rust_client_ffi_fn_func_vss_list(`prefix`: RustBuffer.ByValue): Pointer
@@ -650,6 +657,8 @@ internal interface _UniFFILib : Library {
650657

651658
fun uniffi_vss_rust_client_ffi_checksum_func_vss_delete(): Short
652659

660+
fun uniffi_vss_rust_client_ffi_checksum_func_vss_derive_store_id(): Short
661+
653662
fun uniffi_vss_rust_client_ffi_checksum_func_vss_get(): Short
654663

655664
fun uniffi_vss_rust_client_ffi_checksum_func_vss_list(): Short
@@ -684,6 +693,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
684693
if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_delete() != 46571.toShort()) {
685694
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
686695
}
696+
if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_derive_store_id() != 61324.toShort()) {
697+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
698+
}
687699
if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_get() != 59657.toShort()) {
688700
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
689701
}
@@ -1397,6 +1409,23 @@ suspend fun `vssDelete`(`key`: String): Boolean =
13971409
VssException.ErrorHandler,
13981410
)
13991411

1412+
@Throws(VssException::class)
1413+
fun `vssDeriveStoreId`(
1414+
`prefix`: String,
1415+
`mnemonic`: String,
1416+
`passphrase`: String?,
1417+
): String =
1418+
FfiConverterString.lift(
1419+
rustCallWithError(VssException) { _status ->
1420+
_UniFFILib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_derive_store_id(
1421+
FfiConverterString.lower(`prefix`),
1422+
FfiConverterString.lower(`mnemonic`),
1423+
FfiConverterOptionalString.lower(`passphrase`),
1424+
_status,
1425+
)
1426+
},
1427+
)
1428+
14001429
@Throws(VssException::class)
14011430
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
14021431
suspend fun `vssGet`(`key`: String): VssItem? =

bindings/ios/VssRustClientFfi.xcframework/ios-arm64-simulator/Headers/vss_rust_client_ffiFFI.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ typedef void (*UniFfiRustFutureContinuation)(void * _Nonnull, int8_t);
6565
// Scaffolding functions
6666
void* _Nonnull uniffi_vss_rust_client_ffi_fn_func_vss_delete(RustBuffer key
6767
);
68+
RustBuffer uniffi_vss_rust_client_ffi_fn_func_vss_derive_store_id(RustBuffer prefix, RustBuffer mnemonic, RustBuffer passphrase, RustCallStatus *_Nonnull out_status
69+
);
6870
void* _Nonnull uniffi_vss_rust_client_ffi_fn_func_vss_get(RustBuffer key
6971
);
7072
void* _Nonnull uniffi_vss_rust_client_ffi_fn_func_vss_list(RustBuffer prefix
@@ -198,6 +200,9 @@ void ffi_vss_rust_client_ffi_rust_future_complete_void(void* _Nonnull handle, Ru
198200
);
199201
uint16_t uniffi_vss_rust_client_ffi_checksum_func_vss_delete(void
200202

203+
);
204+
uint16_t uniffi_vss_rust_client_ffi_checksum_func_vss_derive_store_id(void
205+
201206
);
202207
uint16_t uniffi_vss_rust_client_ffi_checksum_func_vss_get(void
203208

0 commit comments

Comments
 (0)