Skip to content

Commit

Permalink
add pubkey_from_seed to bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Oct 17, 2023
1 parent b61032e commit b5ca72b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sphinx-ffi/src/onion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ pub fn sign_ms(seed: String, time: String) -> Result<String> {
Ok(hex::encode(sig))
}

pub fn pubkey_from_seed(seed: String, time: String) -> Result<String> {
let km = make_keys_manager(&seed, &time)?;
let secp_ctx = sphinx::Secp256k1::new();
let pubkey = PublicKey::from_secret_key(&secp_ctx, &km.get_node_secret_key());
Ok(hex::encode(pubkey.serialize()))
}

pub fn create_onion(seed: String, time: String, hops: String, payload: Vec<u8>) -> Result<Vec<u8>> {
let km = make_keys_manager(&seed, &time)?;
let hops = parse_hops(&hops)?;
Expand Down
13 changes: 13 additions & 0 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,16 @@ public func `signMs`(`seed`: String, `time`: String) throws -> String {
)
}

public func `pubkeyFromSeed`(`seed`: String, `time`: String) throws -> String {
return try FfiConverterString.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_pubkey_from_seed(
FfiConverterString.lower(`seed`),
FfiConverterString.lower(`time`),$0)
}
)
}

private enum InitializationResult {
case ok
case contractVersionMismatch
Expand Down Expand Up @@ -1014,6 +1024,9 @@ private var initializationResult: InitializationResult {
if (uniffi_sphinxrs_checksum_func_sign_ms() != 65056) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_pubkey_from_seed() != 40652) {
return InitializationResult.apiChecksumMismatch
}

return InitializationResult.ok
}
Expand Down
2 changes: 2 additions & 0 deletions sphinx-ffi/src/sphinxrs.udl
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ namespace sphinxrs {
bytes peel_payment(string seed, string time, bytes payload, string preimage);
[Throws=SphinxError]
string sign_ms(string seed, string time);
[Throws=SphinxError]
string pubkey_from_seed(string seed, string time);
};
5 changes: 5 additions & 0 deletions sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ RustBuffer uniffi_sphinxrs_fn_func_peel_payment(RustBuffer seed, RustBuffer time
);
RustBuffer uniffi_sphinxrs_fn_func_sign_ms(RustBuffer seed, RustBuffer time, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_pubkey_from_seed(RustBuffer seed, RustBuffer time, RustCallStatus *_Nonnull out_status
);
RustBuffer ffi_sphinxrs_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
);
RustBuffer ffi_sphinxrs_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status
Expand Down Expand Up @@ -165,6 +167,9 @@ uint16_t uniffi_sphinxrs_checksum_func_peel_payment(void
);
uint16_t uniffi_sphinxrs_checksum_func_sign_ms(void

);
uint16_t uniffi_sphinxrs_checksum_func_pubkey_from_seed(void

);
uint32_t ffi_sphinxrs_uniffi_contract_version(void

Expand Down

0 comments on commit b5ca72b

Please sign in to comment.