Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for lwk 0.8.2-1 #4

Merged
merged 4 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-android:0.75.2'
implementation 'com.facebook.react:hermes-android:0.75.2'
implementation 'com.blockstream:lwk_bindings:test'
implementation 'com.blockstream:lwk_bindings:0.8.2'
}
89 changes: 89 additions & 0 deletions android/src/main/java/io/lwkrn/LwkRnModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class LwkRnModule(reactContext: ReactApplicationContext) :
private var _signers = mutableMapOf<String, Signer>()
private var _txBuilders = mutableMapOf<String, TxBuilder>()
private var _contracts = mutableMapOf<String, Contract>()
private var _bips = mutableMapOf<String, Bip>()

/* Descriptor */

Expand All @@ -61,6 +62,47 @@ class LwkRnModule(reactContext: ReactApplicationContext) :
result.resolve(_descriptors[keyId]!!.toString())
}

/* Bip */

@ReactMethod
fun newBip49(
result: Promise
) {
try {
val id = randomId()
_bips[id] = Bip.newBip49()
result.resolve(id)
} catch (error: Throwable) {
result.reject("Bip newBip49 error", error.localizedMessage, error)
}
}

@ReactMethod
fun newBip84(
result: Promise
) {
try {
val id = randomId()
_bips[id] = Bip.newBip84()
result.resolve(id)
} catch (error: Throwable) {
result.reject("Bip newBip84 error", error.localizedMessage, error)
}
}

@ReactMethod
fun newBip87(
result: Promise
) {
try {
val id = randomId()
_bips[id] = Bip.newBip87()
result.resolve(id)
} catch (error: Throwable) {
result.reject("Bip newBip87 error", error.localizedMessage, error)
}
}

/* Signer */

@ReactMethod
Expand Down Expand Up @@ -112,6 +154,53 @@ class LwkRnModule(reactContext: ReactApplicationContext) :
}
}

@ReactMethod
fun keyoriginXpub(
signerId: String,
bipId: String,
result: Promise
) {
try {
val id = randomId()
val signer = _signers[signerId]
val bip = _bips[bipId]
val res = signer!!.keyoriginXpub(bip!!)
result.resolve(res)
} catch (error: Throwable) {
result.reject("Signer keyoriginXpub error", error.localizedMessage, error)
}
}

@ReactMethod
fun mnemonic(
signerId: String,
result: Promise
) {
try {
val id = randomId()
val signer = _signers[signerId]
val res = signer!!.mnemonic()
result.resolve(res)
} catch (error: Throwable) {
result.reject("Signer mnemonic error", error.localizedMessage, error)
}
}

@ReactMethod
fun createRandomSigner(
network: String,
result: Promise
) {
try {
val id = randomId()
val networkObj = setNetwork(network)
_signers[id] = Signer.random(networkObj)
result.resolve(id)
} catch (error: Throwable) {
result.reject("Signer createRandomSigner error", error.localizedMessage, error)
}
}

/* Electrum client */

@ReactMethod
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lwk-rn-example",
"version": "0.8.2",
"version": "0.8.2-1",
"private": true,
"scripts": {
"android": "react-native run-android",
Expand Down
30 changes: 30 additions & 0 deletions ios/LwkRnModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@

@interface RCT_EXTERN_MODULE(LwkRnModule, NSObject)

/** Bip Methods */
RCT_EXTERN_METHOD(
newBip49: (RCTPromiseResolveBlock)resolve
reject: (RCTPromiseRejectBlock)reject
)
RCT_EXTERN_METHOD(
newBip84: (RCTPromiseResolveBlock)resolve
reject: (RCTPromiseRejectBlock)reject
)
RCT_EXTERN_METHOD(
newBip87: (RCTPromiseResolveBlock)resolve
reject: (RCTPromiseRejectBlock)reject
)

/** Signers Methods */
RCT_EXTERN_METHOD(
createSigner: (nonnull NSString)mnemonic
Expand All @@ -21,6 +35,22 @@ @interface RCT_EXTERN_MODULE(LwkRnModule, NSObject)
resolve: (RCTPromiseResolveBlock)resolve
reject: (RCTPromiseRejectBlock)reject
)
RCT_EXTERN_METHOD(
keyoriginXpub: (nonnull NSString)signerId
bipId: (nonnull NSString)bipId
resolve: (RCTPromiseResolveBlock)resolve
reject: (RCTPromiseRejectBlock)reject
)
RCT_EXTERN_METHOD(
mnemonic: (nonnull NSString)signerId
resolve: (RCTPromiseResolveBlock)resolve
reject: (RCTPromiseRejectBlock)reject
)
RCT_EXTERN_METHOD(
createRandomSigner: (nonnull NSString)network
resolve: (RCTPromiseResolveBlock)resolve
reject: (RCTPromiseRejectBlock)reject
)

/** Descriptors Methods */

Expand Down
90 changes: 90 additions & 0 deletions ios/LwkRnModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
var _psets: [String: Pset] = [:]
var _txBuilders: [String: TxBuilder] = [:]
var _contracts: [String: Contract] = [:]
var _bips: [String: Bip] = [:]

/* WolletDescriptor */
@objc
Expand All @@ -40,7 +41,48 @@
resolve(_descriptors[keyId]!.description)
}

/* Bip */
@objc
func newBip49(
_ resolve: RCTPromiseResolveBlock,
reject: RCTPromiseRejectBlock
) -> Void {
do {
let id = randomId()
_bips[id] = try Bip.newBip49()

Check warning on line 52 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

no calls to throwing functions occur within 'try' expression

Check warning on line 52 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

no calls to throwing functions occur within 'try' expression

Check warning on line 52 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

no calls to throwing functions occur within 'try' expression
resolve(id)
} catch {

Check warning on line 54 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

'catch' block is unreachable because no errors are thrown in 'do' block

Check warning on line 54 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

'catch' block is unreachable because no errors are thrown in 'do' block

Check warning on line 54 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

'catch' block is unreachable because no errors are thrown in 'do' block
reject("Bip newBip49 error", error.localizedDescription, error)
}
}

@objc
func newBip84(
_ resolve: RCTPromiseResolveBlock,
reject: RCTPromiseRejectBlock
) -> Void {
do {
let id = randomId()
_bips[id] = try Bip.newBip84()

Check warning on line 66 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

no calls to throwing functions occur within 'try' expression

Check warning on line 66 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

no calls to throwing functions occur within 'try' expression
resolve(id)
} catch {

Check warning on line 68 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

'catch' block is unreachable because no errors are thrown in 'do' block

Check warning on line 68 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

'catch' block is unreachable because no errors are thrown in 'do' block
reject("Bip newBip84 error", error.localizedDescription, error)
}
}

@objc
func newBip87(
_ resolve: RCTPromiseResolveBlock,
reject: RCTPromiseRejectBlock
) -> Void {
do {
let id = randomId()
_bips[id] = try Bip.newBip87()

Check warning on line 80 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

no

Check warning on line 80 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

no calls to throwing functions occur within 'try' expression
resolve(id)
} catch {

Check warning on line 82 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

'catch' block is unreachable because no errors are thrown in 'do' block

Check warning on line 82 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

'catch' block is unreachable because no errors are thrown in 'do' block
reject("Bip newBip87 error", error.localizedDescription, error)
}
}

/* Signer */
@objc
Expand Down Expand Up @@ -94,6 +136,54 @@
reject("Signer wpkhSlip77Descriptor error", error.localizedDescription, error)
}
}

@objc
func keyoriginXpub(
_ signerId: String,
bipId: String,
resolve: RCTPromiseResolveBlock,
reject: RCTPromiseRejectBlock
) -> Void {
do {
let signer = _signers[signerId]
let bip = _bips[bipId]
let res = try signer?.keyoriginXpub(bip)

Check failure on line 150 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

missing argument label 'bip:' in call

Check failure on line 150 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

value of optional type 'Bip?' must be unwrapped to a value of type 'Bip'

Check failure on line 150 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

missing argument label 'bip:' in call

Check failure on line 150 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

value of optional type 'Bip?' must be unwrapped to a value of type 'Bip'

Check failure on line 150 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

missing argument label 'bip:' in call

Check failure on line 150 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

value of optional type 'Bip?' must be unwrapped to a value of type 'Bip'
resolve(res)
} catch {
reject("Signer keyoriginXpub error", error.localizedDescription, error)
}
}

@objc
func mnemonic(
_ signerId: String,
resolve: RCTPromiseResolveBlock,
reject: RCTPromiseRejectBlock
) -> Void {
do {
let signer = _signers[signerId]
let res = try signer?.mnemonic()
resolve(res)
} catch {
reject("Signer mnemonic error", error.localizedDescription, error)
}
}

@objc
func createRandomSigner(
_ network: String,
resolve: RCTPromiseResolveBlock,
reject: RCTPromiseRejectBlock
) -> Void {
do {
let id = randomId()
let network = setNetwork(networkStr: network)
_signers[id] = try Signer.random(network: network)
resolve(id)
} catch {
reject("Signer createRandomSigner error", error.localizedDescription, error)
}
}

/* Electrum client */

Expand Down Expand Up @@ -554,7 +644,7 @@
reject: RCTPromiseRejectBlock
) -> Void {
do {
let txBuilder = _txBuilders[id]

Check warning on line 647 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

initialization of immutable value 'txBuilder' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 647 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

initialization of immutable value 'txBuilder' was never used; consider replacing with assignment to '_' or removing it
let contract = contractId != nil ? _contracts[contractId!] : nil
let assetReceiver = assetReceiver != nil ? try Address(s: assetReceiver!) : nil
let tokenReceiver = tokenReceiver != nil ? try Address(s: tokenReceiver!) : nil
Expand All @@ -576,7 +666,7 @@
reject: RCTPromiseRejectBlock
) -> Void {
do {
let txBuilder = _txBuilders[id]

Check warning on line 669 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

initialization of immutable value 'txBuilder' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 669 in ios/LwkRnModule.swift

View workflow job for this annotation

GitHub Actions / build-ios

initialization of immutable value 'txBuilder' was never used; consider replacing with assignment to '_' or removing it
let assetReceiver = assetReceiver != nil ? try Address(s: assetReceiver!) : nil
let issuanceTx = issuanceTx != nil ? try Transaction(hex: issuanceTx!) : nil
try _txBuilders[id]?.reissueAsset(assetToReissue: assetToReissue, satoshiToReissue: satoshiToReissue.uint64Value, assetReceiver: assetReceiver, issuanceTx: issuanceTx)
Expand Down
4 changes: 2 additions & 2 deletions lwk-rn.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Pod::Spec.new do |s|

s.source_files = "ios/**/*.{h,m,mm,swift}"

s.dependency 'lwkFFI', '0.8.2'
s.dependency 'LiquidWalletKit', '0.8.2'
s.dependency 'lwkFFI', '0.8.2-1'
s.dependency 'LiquidWalletKit', '0.8.2-1'

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lwk-rn",
"version": "0.8.2",
"version": "0.8.2-1",
"description": "Liquid Wallet Kit react native module",
"source": "./src/index.tsx",
"main": "./lib/commonjs/index.js",
Expand Down
18 changes: 18 additions & 0 deletions src/classes/Bip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NativeLoader } from './NativeLoader';

export class Bip extends NativeLoader {
id: string = '';

async newBip49(): Promise<Bip> {
this.id = await this._lwk.newBip49();
return this;
}
async newBip84(): Promise<Bip> {
this.id = await this._lwk.newBip84();
return this;
}
async newBip87(): Promise<Bip> {
this.id = await this._lwk.newBip87();
return this;
}
}
8 changes: 8 additions & 0 deletions src/classes/NativeLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export interface NativeLwk {
createSigner(mnemonic: string, network: Network): string;
sign(signerId: string, psetId: string): string;
wpkhSlip77Descriptor(signerId: string): string;
keyoriginXpub(signerId: string, bipId: string): string;
createRandomSigner(network: Network): string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need random signer?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the reason why we need it. Create random signer can be created without the need of mnemonic.!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right! It could be usefull in test environment

mnemonic(signerId: string): string;

// Wollet
createWollet(
Expand Down Expand Up @@ -94,6 +97,11 @@ export interface NativeLwk {
version: number
): string;
contractAsString(id: string): string;

// Bip
newBip49(): string;
newBip84(): string;
newBip87(): string;
}

export class NativeLoader {
Expand Down
17 changes: 17 additions & 0 deletions src/classes/Signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NativeLoader } from './NativeLoader';
import { Pset } from './Pset';
import { Network } from '../lib/enums';
import { Descriptor } from './Descriptor';
import { Bip } from './Bip';

export class Signer extends NativeLoader {
id: string = '';
Expand All @@ -23,4 +24,20 @@ export class Signer extends NativeLoader {
let newId = await this._lwk.wpkhSlip77Descriptor(this.id);
return new Descriptor().from(newId);
}

async createRandomSigner(network: Network): Promise<Signer> {
if (!Object.values(Network).includes(network)) {
throw `Invalid network passed. Allowed values are ${Object.values(Network)}`;
}
this.id = await this._lwk.createRandomSigner(network);
return this;
}

async keyoriginXpub(bip: Bip): Promise<string> {
return await this._lwk.keyoriginXpub(this.id, bip.id);
}

async mnemonic(): Promise<string> {
return await this._lwk.mnemonic(this.id);
}
}
Loading