Skip to content

Commit 11b60bb

Browse files
authored
Update ironfish SDK to 2.10.0 (#134)
1 parent 51f35b0 commit 11b60bb

File tree

13 files changed

+677
-93
lines changed

13 files changed

+677
-93
lines changed

package-lock.json

Lines changed: 584 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ironfish-native-module/android/src/main/java/expo/modules/ironfishnativemodule/IronfishNativeModule.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ class IronfishNativeModule : Module() {
110110
)
111111
}
112112

113+
Function("generatePublicAddressFromIncomingViewKey") { incomingViewKey: String ->
114+
uniffi.rust_lib.generatePublicAddressFromIncomingViewKey(incomingViewKey)
115+
}
116+
113117
Function("isValidPublicAddress") { hexAddress: String ->
114118
uniffi.rust_lib.isValidPublicAddress(hexAddress)
115119
}

packages/ironfish-native-module/ios/IronfishNativeModule.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ public class IronfishNativeModule: Module {
111111
)
112112
}
113113

114+
Function("generatePublicAddressFromIncomingViewKey") { (incomingViewKey: String) throws -> String? in
115+
guard let k = try? generatePublicAddressFromIncomingViewKey(incomingViewKey: incomingViewKey) else {
116+
return nil
117+
}
118+
119+
return k
120+
}
121+
114122
Function("isValidPublicAddress") { (hexAddress: String) -> Bool in
115123
return isValidPublicAddress(hexAddress: hexAddress)
116124
}

packages/ironfish-native-module/rust_lib/src/lib.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ use tokio_rayon::rayon::iter::{
1313
use zune_inflate::DeflateDecoder;
1414

1515
use crate::num::FromPrimitive;
16-
use ironfish::sapling_bls12::Scalar;
1716
use ironfish::{
18-
assets::asset::ID_LENGTH, keys::Language, note::MEMO_SIZE, serializing::bytes_to_hex,
19-
MerkleNoteHash, Note, PublicAddress, SaplingKey,
17+
assets::asset::ID_LENGTH, keys::Language, note::MEMO_SIZE, sapling_bls12::Scalar,
18+
serializing::bytes_to_hex, IncomingViewKey, MerkleNoteHash, Note, PublicAddress, SaplingKey,
2019
};
2120

2221
uniffi::setup_scaffolding!();
@@ -155,6 +154,16 @@ fn generate_key_from_private_key(private_key: String) -> Result<Key, EnumError>
155154
})
156155
}
157156

157+
#[uniffi::export]
158+
fn generate_public_address_from_incoming_view_key(
159+
incoming_view_key: String,
160+
) -> Result<String, EnumError> {
161+
let ivk = IncomingViewKey::from_hex(&incoming_view_key)
162+
.map_err(|e| EnumError::Error { msg: e.to_string() })?;
163+
let address = PublicAddress::from_view_key(&ivk);
164+
Ok(address.hex_public_address())
165+
}
166+
158167
#[uniffi::export]
159168
pub fn is_valid_public_address(hex_address: String) -> bool {
160169
PublicAddress::from_hex(&hex_address).is_ok()
@@ -413,8 +422,6 @@ pub fn create_transaction(
413422
}
414423

415424
#[uniffi::export]
416-
pub fn hash_transaction(
417-
transaction: Vec<u8>,
418-
) -> Vec<u8> {
425+
pub fn hash_transaction(transaction: Vec<u8>) -> Vec<u8> {
419426
blake3::hash(&transaction).as_bytes().to_vec()
420427
}

packages/ironfish-native-module/src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ export function generateKeyFromPrivateKey(privateKey: string): Key {
4747
}
4848
}
4949

50+
export function generatePublicAddressFromIncomingViewKey(
51+
incomingViewKey: string,
52+
): Key {
53+
const result =
54+
IronfishNativeModule.generatePublicAddressFromIncomingViewKey(
55+
incomingViewKey,
56+
);
57+
58+
// Throwing exceptions from expo modules directly logs to the console, even
59+
// if the warning is caught.
60+
if (result) {
61+
return result;
62+
} else {
63+
throw new Error("Failed to generate public address from incoming view key");
64+
}
65+
}
66+
5067
export function isValidPublicAddress(hexAddress: string): boolean {
5168
return IronfishNativeModule.isValidPublicAddress(hexAddress);
5269
}

packages/mobile-app/app/(drawer)/app-settings/debug/oreowallet.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { OreowalletServerApi } from "@/data/oreowalletServerApi/oreowalletServer
55
import { useFacade } from "@/data/facades";
66
import {
77
AccountFormat,
8-
decodeAccount,
8+
decodeAccountImport,
99
RawTransactionSerde,
1010
} from "@ironfish/sdk";
1111

@@ -22,7 +22,7 @@ export default function MenuDebugOreowallet() {
2222
viewOnly: true,
2323
});
2424

25-
const acc = decodeAccount(es);
25+
const acc = decodeAccountImport(es);
2626

2727
return { publicAddress: acc.publicAddress, viewKey: acc.viewKey };
2828
};
@@ -42,7 +42,7 @@ export default function MenuDebugOreowallet() {
4242
format: AccountFormat.JSON,
4343
viewOnly: true,
4444
});
45-
const decoded = decodeAccount(exported);
45+
const decoded = decodeAccountImport(exported);
4646

4747
const result = await OreowalletServerApi.importAccount(
4848
Network.MAINNET,

packages/mobile-app/data/debug/reverseScan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { decodeAccount } from "@ironfish/sdk";
1+
import { decodeAccountImport } from "@ironfish/sdk";
22
import { Network } from "../constants";
33
import { Wallet } from "../wallet/wallet";
44
import { WriteQueue } from "../wallet/writeQueue";
@@ -38,7 +38,7 @@ export async function reverseScan(
3838
for (const dbAccount of dbAccounts) {
3939
accounts.push({
4040
...dbAccount,
41-
decodedAccount: decodeAccount(dbAccount.viewOnlyAccount, {
41+
decodedAccount: decodeAccountImport(dbAccount.viewOnlyAccount, {
4242
name: dbAccount.name,
4343
}),
4444
});

packages/mobile-app/data/facades/wallet/oreowalletHandlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { SettingsKey } from "@/data/settings/db";
1616

1717
import {
1818
AccountFormat,
19-
decodeAccount,
19+
decodeAccountImport,
2020
LanguageKey,
2121
LanguageUtils,
2222
TransactionStatus,
@@ -322,7 +322,7 @@ export const walletHandlers = f.facade<WalletHandlers>({
322322
},
323323
);
324324

325-
const decodedAccount = decodeAccount(exportedAcc);
325+
const decodedAccount = decodeAccountImport(exportedAcc);
326326

327327
const response = await OreowalletServerApi.getLatestBlock(network, {
328328
publicAddress: decodedAccount.publicAddress,

packages/mobile-app/data/wallet/db.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { AccountImport } from "@ironfish/sdk/build/src/wallet/walletdb/accountValue";
21
import { Kysely, Generated, Migrator, sql, Selectable } from "kysely";
32
import { ExpoDialect, ExpoMigrationProvider, SQLiteType } from "kysely-expo";
43
import * as SecureStore from "expo-secure-store";
54
import * as FileSystem from "expo-file-system";
6-
import { AccountFormat, encodeAccount, Note } from "@ironfish/sdk";
5+
import {
6+
AccountFormat,
7+
encodeAccountImport,
8+
Note,
9+
AccountImport,
10+
} from "@ironfish/sdk";
711
import { Network } from "../constants";
812
import * as Uint8ArrayUtils from "../../utils/uint8Array";
913
import { TransactionType } from "../facades/wallet/types";
@@ -477,7 +481,7 @@ export class WalletDb {
477481
* Returns the existing account if one already exists with the same public address.
478482
*/
479483
async createAccount(account: AccountImport): Promise<DBAccount> {
480-
const viewOnlyAccount = encodeAccount(
484+
const viewOnlyAccount = encodeAccountImport(
481485
{ ...account, spendingKey: null },
482486
AccountFormat.Base64Json,
483487
);

packages/mobile-app/data/wallet/oreowalletWallet.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
LanguageKey,
66
RawTransaction,
77
RawTransactionSerde,
8-
decodeAccount,
9-
encodeAccount,
8+
decodeAccountImport,
9+
encodeAccountImport,
1010
} from "@ironfish/sdk";
1111
import { CONFIRMATIONS, IRON_ASSET_ID_HEX, Network } from "../constants";
1212
import * as Uint8ArrayUtils from "../../utils/uint8Array";
@@ -96,7 +96,7 @@ export class Wallet {
9696

9797
if (!account) return;
9898

99-
const decodedAccount = decodeAccount(account.viewOnlyAccount, {
99+
const decodedAccount = decodeAccountImport(account.viewOnlyAccount, {
100100
name: account.name,
101101
});
102102

@@ -128,7 +128,7 @@ export class Wallet {
128128
accounts.map(async (a) => {
129129
const balances = await this.getBalances(a.id, network);
130130

131-
const decodedAccount = decodeAccount(a.viewOnlyAccount, {
131+
const decodedAccount = decodeAccountImport(a.viewOnlyAccount, {
132132
name: a.name,
133133
});
134134

@@ -163,7 +163,7 @@ export class Wallet {
163163

164164
if (!account) return;
165165

166-
const decodedAccount = decodeAccount(account.viewOnlyAccount, {
166+
const decodedAccount = decodeAccountImport(account.viewOnlyAccount, {
167167
name: account.name,
168168
});
169169

@@ -208,7 +208,7 @@ export class Wallet {
208208
const account = await this.state.db.getAccountById(accountId);
209209
if (!account) return [];
210210

211-
const decodedAccount = decodeAccount(account.viewOnlyAccount, {
211+
const decodedAccount = decodeAccountImport(account.viewOnlyAccount, {
212212
name: account.name,
213213
});
214214

@@ -236,7 +236,7 @@ export class Wallet {
236236
throw new Error(`No account found with name ${name}`);
237237
}
238238

239-
const decodedAccount = decodeAccount(account.viewOnlyAccount, {
239+
const decodedAccount = decodeAccountImport(account.viewOnlyAccount, {
240240
name,
241241
});
242242

@@ -246,15 +246,15 @@ export class Wallet {
246246
);
247247
}
248248

249-
return encodeAccount(decodedAccount, format, {
249+
return encodeAccountImport(decodedAccount, format, {
250250
language: options?.language,
251251
});
252252
}
253253

254254
async importAccount(network: Network, account: string, name?: string) {
255255
assertStarted(this.state);
256256

257-
const decodedAccount = decodeAccount(account, {
257+
const decodedAccount = decodeAccountImport(account, {
258258
name,
259259
});
260260

@@ -310,7 +310,7 @@ export class Wallet {
310310
throw new Error(`No account found with name ${accountName}`);
311311
}
312312

313-
const decodedAccount = decodeAccount(account.viewOnlyAccount, {
313+
const decodedAccount = decodeAccountImport(account.viewOnlyAccount, {
314314
name: account.name,
315315
});
316316

@@ -340,7 +340,7 @@ export class Wallet {
340340
throw new Error(`No account found with name ${accountName}`);
341341
}
342342

343-
const decodedAccount = decodeAccount(account.viewOnlyAccount, {
343+
const decodedAccount = decodeAccountImport(account.viewOnlyAccount, {
344344
name: account.name,
345345
});
346346

@@ -436,7 +436,7 @@ export class Wallet {
436436
throw new Error("Cannot send transactions from a view-only account");
437437
}
438438

439-
const decodedAccount = decodeAccount(account.viewOnlyAccount, {
439+
const decodedAccount = decodeAccountImport(account.viewOnlyAccount, {
440440
name: account.name,
441441
});
442442

@@ -477,7 +477,7 @@ export class Wallet {
477477
throw new Error("Cannot send transactions from a view-only account");
478478
}
479479

480-
const decodedAccount = decodeAccount(account.viewOnlyAccount, {
480+
const decodedAccount = decodeAccountImport(account.viewOnlyAccount, {
481481
name: account.name,
482482
});
483483

0 commit comments

Comments
 (0)