@bubolabs/wallet-rn-sdk 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BuboWalletRnSdk.podspec +29 -0
- package/README.md +71 -0
- package/android/build.gradle +46 -0
- package/android/consumer-rules.pro +1 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/bubo/wallet/BuboWalletSmokeModule.kt +65 -0
- package/android/src/main/java/com/bubo/wallet/BuboWalletSmokePackage.kt +18 -0
- package/android/src/main/java/uniffi/bubo_wallet_ffi/WalletLibSmoke.kt +92 -0
- package/android/src/main/java/uniffi/bubo_wallet_ffi/bubo_wallet_ffi.kt +1664 -0
- package/android/src/main/jniLibs/arm64-v8a/libbubo_wallet_ffi.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libuniffi_bubo_wallet_ffi.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libbubo_wallet_ffi.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libuniffi_bubo_wallet_ffi.so +0 -0
- package/android/src/main/jniLibs/x86/libbubo_wallet_ffi.so +0 -0
- package/android/src/main/jniLibs/x86/libuniffi_bubo_wallet_ffi.so +0 -0
- package/android/src/main/jniLibs/x86_64/libbubo_wallet_ffi.so +0 -0
- package/android/src/main/jniLibs/x86_64/libuniffi_bubo_wallet_ffi.so +0 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/native.d.ts +18 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +37 -0
- package/dist/smoke.d.ts +4 -0
- package/dist/smoke.d.ts.map +1 -0
- package/dist/smoke.js +82 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/ios/BuboWalletSmoke.swift +110 -0
- package/ios/BuboWalletSmokeModule.m +11 -0
- package/ios/BuboWalletSmokeModule.swift +51 -0
- package/ios/bubo_wallet_ffi.swift +905 -0
- package/ios/bubo_wallet_ffiFFI.h +606 -0
- package/ios/bubo_wallet_ffiFFI.modulemap +7 -0
- package/ios/lib/BuboWalletFFI.xcframework/Info.plist +48 -0
- package/ios/lib/BuboWalletFFI.xcframework/ios-arm64/Headers/bubo_wallet_ffiFFI.h +606 -0
- package/ios/lib/BuboWalletFFI.xcframework/ios-arm64/Headers/module.modulemap +7 -0
- package/ios/lib/BuboWalletFFI.xcframework/ios-arm64/libbubo_wallet_ffi.a +0 -0
- package/ios/lib/BuboWalletFFI.xcframework/ios-arm64_x86_64-simulator/Headers/bubo_wallet_ffiFFI.h +606 -0
- package/ios/lib/BuboWalletFFI.xcframework/ios-arm64_x86_64-simulator/Headers/module.modulemap +7 -0
- package/ios/lib/BuboWalletFFI.xcframework/ios-arm64_x86_64-simulator/libbubo_wallet_ffi.a +0 -0
- package/package.json +47 -0
- package/react-native.config.js +12 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAChD,YAAY,EACV,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WalletSmokeError = exports.runSmoke = exports.runBtcSmoke = void 0;
|
|
4
|
+
var smoke_1 = require("./smoke");
|
|
5
|
+
Object.defineProperty(exports, "runBtcSmoke", { enumerable: true, get: function () { return smoke_1.runBtcSmoke; } });
|
|
6
|
+
Object.defineProperty(exports, "runSmoke", { enumerable: true, get: function () { return smoke_1.runSmoke; } });
|
|
7
|
+
var types_1 = require("./types");
|
|
8
|
+
Object.defineProperty(exports, "WalletSmokeError", { enumerable: true, get: function () { return types_1.WalletSmokeError; } });
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type NativeSupportedChainInfo = {
|
|
2
|
+
chainId: string;
|
|
3
|
+
capabilities: string[];
|
|
4
|
+
};
|
|
5
|
+
export type NativeWalletSmokeResult = {
|
|
6
|
+
supportedChains: NativeSupportedChainInfo[];
|
|
7
|
+
deriveChainId: string;
|
|
8
|
+
derivedAddress: string;
|
|
9
|
+
signChainId: string | null;
|
|
10
|
+
signedTxHex: string | null;
|
|
11
|
+
};
|
|
12
|
+
type BuboWalletSmokeModule = {
|
|
13
|
+
runSmoke(): Promise<NativeWalletSmokeResult>;
|
|
14
|
+
runBtcSmoke(): Promise<NativeWalletSmokeResult>;
|
|
15
|
+
};
|
|
16
|
+
export declare function getBuboWalletSmokeModule(): BuboWalletSmokeModule;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,eAAe,EAAE,wBAAwB,EAAE,CAAC;IAC5C,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAC7C,WAAW,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC;CACjD,CAAC;AA+BF,wBAAgB,wBAAwB,IAAI,qBAAqB,CAMhE"}
|
package/dist/native.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getBuboWalletSmokeModule = getBuboWalletSmokeModule;
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const ReactNativeRuntime = require("react-native");
|
|
7
|
+
const NativeModules = (_a = ReactNativeRuntime.NativeModules) !== null && _a !== void 0 ? _a : {};
|
|
8
|
+
const TurboModuleRegistry = (_b = ReactNativeRuntime.TurboModuleRegistry) !== null && _b !== void 0 ? _b : null;
|
|
9
|
+
const MODULE_NAME = "BuboWalletSmoke";
|
|
10
|
+
function resolveNativeModule() {
|
|
11
|
+
const turboGet = typeof (TurboModuleRegistry === null || TurboModuleRegistry === void 0 ? void 0 : TurboModuleRegistry.get) === "function"
|
|
12
|
+
? TurboModuleRegistry.get
|
|
13
|
+
: null;
|
|
14
|
+
const turboModule = turboGet
|
|
15
|
+
? turboGet(MODULE_NAME)
|
|
16
|
+
: null;
|
|
17
|
+
if (turboModule) {
|
|
18
|
+
return turboModule;
|
|
19
|
+
}
|
|
20
|
+
const legacyModule = NativeModules[MODULE_NAME];
|
|
21
|
+
return legacyModule !== null && legacyModule !== void 0 ? legacyModule : null;
|
|
22
|
+
}
|
|
23
|
+
function missingModuleHint() {
|
|
24
|
+
return [
|
|
25
|
+
`Native module "${MODULE_NAME}" is not linked.`,
|
|
26
|
+
"Expected iOS podspec: node_modules/@bubolabs/wallet-rn-sdk/BuboWalletRnSdk.podspec",
|
|
27
|
+
"Expected Android package: com.bubo.wallet.BuboWalletSmokePackage",
|
|
28
|
+
"If you are on iOS, run pod install and rebuild the app.",
|
|
29
|
+
].join(" ");
|
|
30
|
+
}
|
|
31
|
+
function getBuboWalletSmokeModule() {
|
|
32
|
+
const mod = resolveNativeModule();
|
|
33
|
+
if (!mod) {
|
|
34
|
+
throw new types_1.WalletSmokeError("MODULE_NOT_LINKED", missingModuleHint());
|
|
35
|
+
}
|
|
36
|
+
return mod;
|
|
37
|
+
}
|
package/dist/smoke.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smoke.d.ts","sourceRoot":"","sources":["../src/smoke.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAqGjB,wBAAsB,QAAQ,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAO3D;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAO9D"}
|
package/dist/smoke.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runSmoke = runSmoke;
|
|
4
|
+
exports.runBtcSmoke = runBtcSmoke;
|
|
5
|
+
const native_1 = require("./native");
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
function isObject(value) {
|
|
8
|
+
return typeof value === "object" && value !== null;
|
|
9
|
+
}
|
|
10
|
+
function toSupportedChainInfo(value, index) {
|
|
11
|
+
if (!isObject(value)) {
|
|
12
|
+
throw new types_1.WalletSmokeError("INVALID_RESULT", `supportedChains[${index}] is not an object`, value);
|
|
13
|
+
}
|
|
14
|
+
const chainId = value.chainId;
|
|
15
|
+
const capabilities = value.capabilities;
|
|
16
|
+
if (typeof chainId !== "string") {
|
|
17
|
+
throw new types_1.WalletSmokeError("INVALID_RESULT", `supportedChains[${index}].chainId must be a string`, value);
|
|
18
|
+
}
|
|
19
|
+
if (!Array.isArray(capabilities) || !capabilities.every((c) => typeof c === "string")) {
|
|
20
|
+
throw new types_1.WalletSmokeError("INVALID_RESULT", `supportedChains[${index}].capabilities must be string[]`, value);
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
chainId,
|
|
24
|
+
capabilities,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function normalizeSmokeResult(raw) {
|
|
28
|
+
if (!isObject(raw)) {
|
|
29
|
+
throw new types_1.WalletSmokeError("INVALID_RESULT", "native result is not an object", raw);
|
|
30
|
+
}
|
|
31
|
+
if (!Array.isArray(raw.supportedChains)) {
|
|
32
|
+
throw new types_1.WalletSmokeError("INVALID_RESULT", "native result.supportedChains must be an array", raw);
|
|
33
|
+
}
|
|
34
|
+
const supportedChains = raw.supportedChains.map(toSupportedChainInfo);
|
|
35
|
+
if (typeof raw.deriveChainId !== "string" || raw.deriveChainId.length === 0) {
|
|
36
|
+
throw new types_1.WalletSmokeError("INVALID_RESULT", "native result.deriveChainId must be a non-empty string", raw);
|
|
37
|
+
}
|
|
38
|
+
if (typeof raw.derivedAddress !== "string" || raw.derivedAddress.length === 0) {
|
|
39
|
+
throw new types_1.WalletSmokeError("INVALID_RESULT", "native result.derivedAddress must be a non-empty string", raw);
|
|
40
|
+
}
|
|
41
|
+
if (raw.signChainId !== null && typeof raw.signChainId !== "string") {
|
|
42
|
+
throw new types_1.WalletSmokeError("INVALID_RESULT", "native result.signChainId must be string | null", raw);
|
|
43
|
+
}
|
|
44
|
+
if (raw.signedTxHex !== null && typeof raw.signedTxHex !== "string") {
|
|
45
|
+
throw new types_1.WalletSmokeError("INVALID_RESULT", "native result.signedTxHex must be string | null", raw);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
supportedChains,
|
|
49
|
+
deriveChainId: raw.deriveChainId,
|
|
50
|
+
derivedAddress: raw.derivedAddress,
|
|
51
|
+
signChainId: raw.signChainId,
|
|
52
|
+
signedTxHex: raw.signedTxHex,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function mapNativeError(error) {
|
|
56
|
+
if (error instanceof types_1.WalletSmokeError) {
|
|
57
|
+
return error;
|
|
58
|
+
}
|
|
59
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
60
|
+
if (message.includes("btc buildAndSign not available")) {
|
|
61
|
+
return new types_1.WalletSmokeError("BTC_SIGN_UNAVAILABLE", message, error);
|
|
62
|
+
}
|
|
63
|
+
return new types_1.WalletSmokeError("NATIVE_ERROR", message, error);
|
|
64
|
+
}
|
|
65
|
+
async function runSmoke() {
|
|
66
|
+
try {
|
|
67
|
+
const result = await (0, native_1.getBuboWalletSmokeModule)().runSmoke();
|
|
68
|
+
return normalizeSmokeResult(result);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw mapNativeError(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function runBtcSmoke() {
|
|
75
|
+
try {
|
|
76
|
+
const result = await (0, native_1.getBuboWalletSmokeModule)().runBtcSmoke();
|
|
77
|
+
return normalizeSmokeResult(result);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
throw mapNativeError(error);
|
|
81
|
+
}
|
|
82
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type SupportedChainInfo = {
|
|
2
|
+
chainId: string;
|
|
3
|
+
capabilities: string[];
|
|
4
|
+
};
|
|
5
|
+
export type WalletSmokeResult = {
|
|
6
|
+
supportedChains: SupportedChainInfo[];
|
|
7
|
+
deriveChainId: string;
|
|
8
|
+
derivedAddress: string;
|
|
9
|
+
signChainId: string | null;
|
|
10
|
+
signedTxHex: string | null;
|
|
11
|
+
};
|
|
12
|
+
export type WalletSmokeErrorCode = "MODULE_NOT_LINKED" | "NATIVE_ERROR" | "INVALID_RESULT" | "BTC_SIGN_UNAVAILABLE";
|
|
13
|
+
export declare class WalletSmokeError extends Error {
|
|
14
|
+
readonly code: WalletSmokeErrorCode;
|
|
15
|
+
readonly causeValue?: unknown;
|
|
16
|
+
constructor(code: WalletSmokeErrorCode, message: string, causeValue?: unknown);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAC5B,mBAAmB,GACnB,cAAc,GACd,gBAAgB,GAChB,sBAAsB,CAAC;AAE3B,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,SAAgB,IAAI,EAAE,oBAAoB,CAAC;IAC3C,SAAgB,UAAU,CAAC,EAAE,OAAO,CAAC;gBAGnC,IAAI,EAAE,oBAAoB,EAC1B,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,OAAO;CAOvB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WalletSmokeError = void 0;
|
|
4
|
+
class WalletSmokeError extends Error {
|
|
5
|
+
constructor(code, message, causeValue) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "WalletSmokeError";
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.causeValue = causeValue;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.WalletSmokeError = WalletSmokeError;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
public struct WalletSmokeResult {
|
|
4
|
+
public let supportedChains: [SupportedChainInfo]
|
|
5
|
+
public let deriveChainId: String
|
|
6
|
+
public let derivedAddress: String
|
|
7
|
+
public let signChainId: String?
|
|
8
|
+
public let signedTxHex: String?
|
|
9
|
+
|
|
10
|
+
public init(
|
|
11
|
+
supportedChains: [SupportedChainInfo],
|
|
12
|
+
deriveChainId: String,
|
|
13
|
+
derivedAddress: String,
|
|
14
|
+
signChainId: String?,
|
|
15
|
+
signedTxHex: String?
|
|
16
|
+
) {
|
|
17
|
+
self.supportedChains = supportedChains
|
|
18
|
+
self.deriveChainId = deriveChainId
|
|
19
|
+
self.derivedAddress = derivedAddress
|
|
20
|
+
self.signChainId = signChainId
|
|
21
|
+
self.signedTxHex = signedTxHex
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public enum WalletSmokeError: Error {
|
|
26
|
+
case noSupportedChains
|
|
27
|
+
case noDeriveCapability
|
|
28
|
+
case btcSignUnavailable
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public enum WalletLibSmoke {
|
|
32
|
+
private static let sampleMnemonic =
|
|
33
|
+
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
|
34
|
+
|
|
35
|
+
private static let btcSmokePayload = """
|
|
36
|
+
{
|
|
37
|
+
"account": 0,
|
|
38
|
+
"address_index": 0,
|
|
39
|
+
"change_index": 0,
|
|
40
|
+
"network": "mainnet",
|
|
41
|
+
"prev_txid": "0000000000000000000000000000000000000000000000000000000000000001",
|
|
42
|
+
"prev_vout": 0,
|
|
43
|
+
"prev_script_pubkey_hex": "76a914d986ed01b7a22225a70edbf2ba7cfb63a15cb3aa88ac",
|
|
44
|
+
"prev_value_sat": 100000,
|
|
45
|
+
"to_address": "1BoatSLRHtKNngkdXEeobR76b53LETtpyT",
|
|
46
|
+
"amount_sat": 10000,
|
|
47
|
+
"fee_sat": 1000,
|
|
48
|
+
"lock_time": 0,
|
|
49
|
+
"sequence": 4294967295
|
|
50
|
+
}
|
|
51
|
+
""".data(using: .utf8)!
|
|
52
|
+
|
|
53
|
+
public static func runSmoke() throws -> WalletSmokeResult {
|
|
54
|
+
let lib = WalletLib()
|
|
55
|
+
try lib.`init`()
|
|
56
|
+
|
|
57
|
+
let chains = try lib.listSupportedChains()
|
|
58
|
+
guard !chains.isEmpty else {
|
|
59
|
+
throw WalletSmokeError.noSupportedChains
|
|
60
|
+
}
|
|
61
|
+
guard let deriveChain = chains.first(where: { $0.capabilities.contains("deriveAddress") }) else {
|
|
62
|
+
throw WalletSmokeError.noDeriveCapability
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let address = try lib.deriveAddress(
|
|
66
|
+
chainId: deriveChain.chainId,
|
|
67
|
+
mnemonic: sampleMnemonic,
|
|
68
|
+
account: 0,
|
|
69
|
+
index: 0,
|
|
70
|
+
passphrase: nil
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
guard chains.contains(where: { $0.chainId == "btc" && $0.capabilities.contains("buildAndSign") }) else {
|
|
74
|
+
return WalletSmokeResult(
|
|
75
|
+
supportedChains: chains,
|
|
76
|
+
deriveChainId: deriveChain.chainId,
|
|
77
|
+
derivedAddress: address,
|
|
78
|
+
signChainId: nil,
|
|
79
|
+
signedTxHex: nil
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let signed = try lib.buildAndSign(
|
|
84
|
+
chainId: "btc",
|
|
85
|
+
mnemonic: sampleMnemonic,
|
|
86
|
+
txPayload: btcSmokePayload
|
|
87
|
+
)
|
|
88
|
+
return WalletSmokeResult(
|
|
89
|
+
supportedChains: chains,
|
|
90
|
+
deriveChainId: deriveChain.chainId,
|
|
91
|
+
derivedAddress: address,
|
|
92
|
+
signChainId: "btc",
|
|
93
|
+
signedTxHex: signed.hexEncodedString()
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public static func runBtcSmoke() throws -> WalletSmokeResult {
|
|
98
|
+
let result = try runSmoke()
|
|
99
|
+
guard result.signChainId == "btc", result.signedTxHex != nil else {
|
|
100
|
+
throw WalletSmokeError.btcSignUnavailable
|
|
101
|
+
}
|
|
102
|
+
return result
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private extension Data {
|
|
107
|
+
func hexEncodedString() -> String {
|
|
108
|
+
map { String(format: "%02x", $0) }.joined()
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
|
|
3
|
+
@interface RCT_EXTERN_MODULE(BuboWalletSmoke, NSObject)
|
|
4
|
+
|
|
5
|
+
RCT_EXTERN_METHOD(runSmoke:(RCTPromiseResolveBlock)resolve
|
|
6
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
7
|
+
|
|
8
|
+
RCT_EXTERN_METHOD(runBtcSmoke:(RCTPromiseResolveBlock)resolve
|
|
9
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
10
|
+
|
|
11
|
+
@end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import React
|
|
3
|
+
|
|
4
|
+
@objc(BuboWalletSmoke)
|
|
5
|
+
public final class BuboWalletSmoke: NSObject {
|
|
6
|
+
@objc
|
|
7
|
+
public static func requiresMainQueueSetup() -> Bool {
|
|
8
|
+
false
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@objc(runSmoke:rejecter:)
|
|
12
|
+
public func runSmoke(
|
|
13
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
14
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
15
|
+
) {
|
|
16
|
+
do {
|
|
17
|
+
let result = try WalletLibSmoke.runSmoke()
|
|
18
|
+
resolve(Self.serialize(result))
|
|
19
|
+
} catch {
|
|
20
|
+
reject("BUBO_WALLET_SMOKE", String(describing: error), error)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@objc(runBtcSmoke:rejecter:)
|
|
25
|
+
public func runBtcSmoke(
|
|
26
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
27
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
28
|
+
) {
|
|
29
|
+
do {
|
|
30
|
+
let result = try WalletLibSmoke.runBtcSmoke()
|
|
31
|
+
resolve(Self.serialize(result))
|
|
32
|
+
} catch {
|
|
33
|
+
reject("BUBO_WALLET_SMOKE", String(describing: error), error)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private static func serialize(_ result: WalletSmokeResult) -> [String: Any] {
|
|
38
|
+
return [
|
|
39
|
+
"supportedChains": result.supportedChains.map {
|
|
40
|
+
[
|
|
41
|
+
"chainId": $0.chainId,
|
|
42
|
+
"capabilities": $0.capabilities,
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
"deriveChainId": result.deriveChainId,
|
|
46
|
+
"derivedAddress": result.derivedAddress,
|
|
47
|
+
"signChainId": result.signChainId as Any,
|
|
48
|
+
"signedTxHex": result.signedTxHex as Any,
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
}
|