Skip to content

Commit

Permalink
Add utility
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Feb 19, 2024
1 parent a370488 commit 9585b76
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface Coin {
puzzleHash: Uint8Array
amount: number
}
export function toCoinId(coin: Coin): Uint8Array
export function bytesEqual(a: Uint8Array, b: Uint8Array): boolean
export class Tls {
constructor(certPath: string, keyPath: string)
}
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,10 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { Tls, Peer, Wallet } = nativeBinding
const { Tls, Peer, Wallet, toCoinId, bytesEqual } = nativeBinding

module.exports.Tls = Tls
module.exports.Peer = Peer
module.exports.Wallet = Wallet
module.exports.toCoinId = toCoinId
module.exports.bytesEqual = bytesEqual
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ pub struct Coin {
pub amount: f64,
}

#[napi]
pub fn to_coin_id(coin: Coin) -> Result<Uint8Array> {
Ok(RustCoin::try_from(coin)?.coin_id().into())
}

#[napi]
pub fn bytes_equal(a: Uint8Array, b: Uint8Array) -> bool {
a.to_vec() == b.to_vec()
}

impl From<RustCoin> for Coin {
fn from(value: RustCoin) -> Self {
Self {
Expand Down

0 comments on commit 9585b76

Please sign in to comment.