Skip to content

Commit

Permalink
Merge pull request #4583 from iron-fish/staging
Browse files Browse the repository at this point in the history
Staging -> Master
  • Loading branch information
danield9tqh authored Jan 23, 2024
2 parents ad4cbcb + 5222867 commit ed05969
Show file tree
Hide file tree
Showing 138 changed files with 2,868 additions and 956 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ testdbs
.env.production.local
*/**/yarn.lock
.idea
.vscode

# logs
npm-debug.log*
Expand Down
1 change: 1 addition & 0 deletions config/eslint-config-ironfish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = {
// the matchers to unknown, or defining a custom matcher, which seems
// like too much friction for test-writing.
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
// It's common to want to mock unbound methods.
'@typescript-eslint/unbound-method': 'off',
// Using try catch with expect.assertions(n) is the recommended way to
Expand Down
6 changes: 3 additions & 3 deletions config/eslint-config-ironfish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
".prettierrc"
],
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "4.28.1",
"@typescript-eslint/parser": "4.28.1",
"eslint": "7.29.0",
"@typescript-eslint/eslint-plugin": "6.19.0",
"@typescript-eslint/parser": "6.19.0",
"eslint": "8.56.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-ironfish": "*",
"eslint-plugin-jest": "27.1.6",
Expand Down
2 changes: 1 addition & 1 deletion config/eslint-plugin-ironfish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"index.js"
],
"peerDependencies": {
"eslint": "7.29.0"
"eslint": "8.56.0"
},
"scripts": {
"test": "node index.test.js"
Expand Down
6 changes: 3 additions & 3 deletions ironfish-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ironfish",
"version": "1.16.0",
"version": "1.17.0",
"description": "CLI for running and interacting with an Iron Fish node",
"author": "Iron Fish <[email protected]> (https://ironfish.network)",
"main": "build/src/index.js",
Expand Down Expand Up @@ -62,8 +62,8 @@
"@aws-sdk/client-s3": "3",
"@aws-sdk/client-secrets-manager": "3",
"@aws-sdk/s3-request-presigner": "3",
"@ironfish/rust-nodejs": "1.13.0",
"@ironfish/sdk": "1.16.0",
"@ironfish/rust-nodejs": "1.14.0",
"@ironfish/sdk": "1.17.0",
"@oclif/core": "1.23.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
Expand Down
4 changes: 2 additions & 2 deletions ironfish-cli/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export abstract class IronfishCommand extends Command {
async init(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
const commandClass = this.constructor as any
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const { flags } = await this.parse(commandClass)

// Get the flags from the flag object which is unknown
Expand Down Expand Up @@ -218,7 +218,7 @@ export abstract class IronfishCommand extends Command {
}
}

function getFlag(flags: unknown, flag: FLAGS): unknown | null {
function getFlag(flags: unknown, flag: FLAGS): unknown {
return typeof flags === 'object' && flags !== null && flag in flags
? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
(flags as any)[flag]
Expand Down
2 changes: 1 addition & 1 deletion ironfish-cli/src/commands/chain/genesisadd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class GenesisAddCommand extends IronfishCommand {
}

CliUx.ux.table(allocations, columns, {
printLine: (line) => this.log(line),
printLine: this.log.bind(this),
})

// Display duplicates if they exist
Expand Down
2 changes: 1 addition & 1 deletion ironfish-cli/src/commands/chain/genesisblock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default class GenesisBlockCommand extends IronfishCommand {
}

CliUx.ux.table(info.allocations, columns, {
printLine: (line) => this.log(line),
printLine: this.log.bind(this),
})

// Display duplicates if they exist
Expand Down
8 changes: 1 addition & 7 deletions ironfish-cli/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export default class Start extends IronfishCommand {
await this.sdk.internal.save()
}

const node = await this.sdk.node({ privateIdentity: this.sdk.getPrivateIdentity() })
const node = await this.sdk.node()

const nodeName = this.sdk.config.get('nodeName').trim() || null
const blockGraffiti = this.sdk.config.get('blockGraffiti').trim() || null
Expand Down Expand Up @@ -254,12 +254,6 @@ export default class Start extends IronfishCommand {
this.exit(1)
}

const newSecretKey = Buffer.from(
node.peerNetwork.localPeer.privateIdentity.secretKey,
).toString('hex')
node.internal.set('networkIdentity', newSecretKey)
await node.internal.save()

if (node.internal.get('isFirstRun')) {
await this.firstRun(node)
}
Expand Down
2 changes: 1 addition & 1 deletion ironfish-cli/src/typedefs/blru.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ declare module 'blru' {
constructor(
capacity: number,
getSize?: GetSizeFunction<TKey, TValue> | null,
CustomMap?: typeof Map | unknown | null,
CustomMap?: unknown,
)

map: Map<TKey, LRUItem<TKey, TValue>>
Expand Down
7 changes: 5 additions & 2 deletions ironfish-cli/src/utils/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
Assert,
CreateTransactionRequest,
CurrencyUtils,
ERROR_CODES,
Logger,
RawTransaction,
RawTransactionSerde,
RPC_ERROR_CODES,
RpcClient,
RpcRequestError,
} from '@ironfish/sdk'
Expand Down Expand Up @@ -109,7 +109,10 @@ async function getTxWithFee(
})

const response = await promise.catch((e) => {
if (e instanceof RpcRequestError && e.code === ERROR_CODES.INSUFFICIENT_BALANCE) {
if (
e instanceof RpcRequestError &&
e.code === RPC_ERROR_CODES.INSUFFICIENT_BALANCE.valueOf()
) {
return null
} else {
throw e
Expand Down
2 changes: 1 addition & 1 deletion ironfish-cli/src/utils/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const MAX_MULTIPART_NUM = 10000

class UploadToBucketError extends Error {
name = this.constructor.name
error: unknown | undefined
error: unknown

constructor(message?: string, error?: unknown) {
super(message)
Expand Down
3 changes: 2 additions & 1 deletion ironfish-cli/src/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export async function watchTransaction(options: {

const startTime = lastTime

let prevStatus = last?.content.transaction?.status ?? 'not found'
let prevStatus: TransactionStatus | 'not found' =
last?.content.transaction?.status ?? 'not found'
let currentStatus = prevStatus

// If the transaction is already in the desired state, return
Expand Down
14 changes: 14 additions & 0 deletions ironfish-rust-nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

/* auto-generated by NAPI-RS */

export interface RoundOneSigningData {
nonceHiding: string
nonceBinding: string
commitmentHiding: string
commitmentBinding: string
}
export function roundOne(keyPackage: string, seed: number): RoundOneSigningData
export function contribute(inputPath: string, outputPath: string, seed?: string | undefined | null): Promise<string>
export function verifyTransform(paramsPath: string, newParamsPath: string): Promise<string>
export const KEY_LENGTH: number
Expand Down Expand Up @@ -75,6 +82,7 @@ export interface Key {
incomingViewKey: string
outgoingViewKey: string
publicAddress: string
proofGenerationKey: string
}
export function generateKey(): Key
export function spendingKeyToWords(privateKey: string, languageCode: LanguageCode): string
Expand Down Expand Up @@ -215,8 +223,14 @@ export class Transaction {
* aka: self.value_balance - intended_transaction_fee - change = 0
*/
post(spenderHexKey: string, changeGoesTo: string | undefined | null, intendedTransactionFee: bigint): Buffer
build(proofGenerationKeyStr: string, viewKeyStr: string, outgoingViewKeyStr: string, publicAddressStr: string, intendedTransactionFee: bigint, changeGoesTo?: string | undefined | null): Buffer
setExpiration(sequence: number): void
}
export type NativeUnsignedTransaction = UnsignedTransaction
export class UnsignedTransaction {
constructor(jsBytes: Buffer)
serialize(): Buffer
}
export class FoundBlockResult {
randomness: string
miningRequestId: number
Expand Down
4 changes: 3 additions & 1 deletion ironfish-rust-nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,10 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { FishHashContext, contribute, verifyTransform, KEY_LENGTH, NONCE_LENGTH, BoxKeyPair, randomBytes, boxMessage, unboxMessage, RollingFilter, initSignalHandler, triggerSegfault, ASSET_ID_LENGTH, ASSET_METADATA_LENGTH, ASSET_NAME_LENGTH, ASSET_LENGTH, Asset, NOTE_ENCRYPTION_KEY_LENGTH, MAC_LENGTH, ENCRYPTED_NOTE_PLAINTEXT_LENGTH, ENCRYPTED_NOTE_LENGTH, NoteEncrypted, PUBLIC_ADDRESS_LENGTH, RANDOMNESS_LENGTH, MEMO_LENGTH, AMOUNT_VALUE_LENGTH, DECRYPTED_NOTE_LENGTH, Note, PROOF_LENGTH, TRANSACTION_SIGNATURE_LENGTH, TRANSACTION_PUBLIC_KEY_RANDOMNESS_LENGTH, TRANSACTION_EXPIRATION_LENGTH, TRANSACTION_FEE_LENGTH, LATEST_TRANSACTION_VERSION, TransactionPosted, Transaction, verifyTransactions, LanguageCode, generateKey, spendingKeyToWords, wordsToSpendingKey, generateKeyFromPrivateKey, initializeSapling, FoundBlockResult, ThreadPoolHandler, isValidPublicAddress } = nativeBinding
const { FishHashContext, roundOne, contribute, verifyTransform, KEY_LENGTH, NONCE_LENGTH, BoxKeyPair, randomBytes, boxMessage, unboxMessage, RollingFilter, initSignalHandler, triggerSegfault, ASSET_ID_LENGTH, ASSET_METADATA_LENGTH, ASSET_NAME_LENGTH, ASSET_LENGTH, Asset, NOTE_ENCRYPTION_KEY_LENGTH, MAC_LENGTH, ENCRYPTED_NOTE_PLAINTEXT_LENGTH, ENCRYPTED_NOTE_LENGTH, NoteEncrypted, PUBLIC_ADDRESS_LENGTH, RANDOMNESS_LENGTH, MEMO_LENGTH, AMOUNT_VALUE_LENGTH, DECRYPTED_NOTE_LENGTH, Note, PROOF_LENGTH, TRANSACTION_SIGNATURE_LENGTH, TRANSACTION_PUBLIC_KEY_RANDOMNESS_LENGTH, TRANSACTION_EXPIRATION_LENGTH, TRANSACTION_FEE_LENGTH, LATEST_TRANSACTION_VERSION, TransactionPosted, Transaction, verifyTransactions, UnsignedTransaction, LanguageCode, generateKey, spendingKeyToWords, wordsToSpendingKey, generateKeyFromPrivateKey, initializeSapling, FoundBlockResult, ThreadPoolHandler, isValidPublicAddress } = nativeBinding

module.exports.FishHashContext = FishHashContext
module.exports.roundOne = roundOne
module.exports.contribute = contribute
module.exports.verifyTransform = verifyTransform
module.exports.KEY_LENGTH = KEY_LENGTH
Expand Down Expand Up @@ -291,6 +292,7 @@ module.exports.LATEST_TRANSACTION_VERSION = LATEST_TRANSACTION_VERSION
module.exports.TransactionPosted = TransactionPosted
module.exports.Transaction = Transaction
module.exports.verifyTransactions = verifyTransactions
module.exports.UnsignedTransaction = UnsignedTransaction
module.exports.LanguageCode = LanguageCode
module.exports.generateKey = generateKey
module.exports.spendingKeyToWords = spendingKeyToWords
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-darwin-arm64",
"version": "1.13.0",
"version": "1.14.0",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-darwin-x64",
"version": "1.13.0",
"version": "1.14.0",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-linux-arm64-gnu",
"version": "1.13.0",
"version": "1.14.0",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-linux-arm64-musl",
"version": "1.13.0",
"version": "1.14.0",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-linux-x64-gnu",
"version": "1.13.0",
"version": "1.14.0",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-linux-x64-musl",
"version": "1.13.0",
"version": "1.14.0",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-win32-x64-msvc",
"version": "1.13.0",
"version": "1.14.0",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs",
"version": "1.13.0",
"version": "1.14.0",
"description": "Node.js bindings for Rust code required by the Iron Fish SDK",
"main": "index.js",
"types": "index.d.ts",
Expand Down
57 changes: 57 additions & 0 deletions ironfish-rust-nodejs/src/frost.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use ironfish::{
frost::{
keys::KeyPackage,
round2::{Randomizer, SignatureShare},
SigningPackage,
},
frost_utils::{round_one::round_one as round_one_rust, round_two::round_two as round_two_rust},
serializing::{bytes_to_hex, hex_to_bytes, hex_to_vec_bytes},
};
use napi::bindgen_prelude::*;
use napi_derive::napi;

use crate::to_napi_err;

#[napi(object)]
pub struct RoundOneSigningData {
pub nonce_hiding: String,
pub nonce_binding: String,
pub commitment_hiding: String,
pub commitment_binding: String,
}

#[napi]
pub fn round_one(key_package: String, seed: u32) -> Result<RoundOneSigningData> {
let key_package =
KeyPackage::deserialize(&hex_to_vec_bytes(&key_package).map_err(to_napi_err)?)
.map_err(to_napi_err)?;
let (nonce, commitment) = round_one_rust(&key_package, seed as u64);
Ok(RoundOneSigningData {
nonce_hiding: bytes_to_hex(&nonce.hiding().serialize()),
nonce_binding: bytes_to_hex(&nonce.binding().serialize()),
commitment_hiding: bytes_to_hex(&commitment.hiding().serialize()),
commitment_binding: bytes_to_hex(&commitment.binding().serialize()),
})
}

pub fn round_two(
signing_package: String,
key_package: String,
public_key_randomness: String,
seed: u64,
) -> Result<SignatureShare> {
let key_package =
KeyPackage::deserialize(&hex_to_vec_bytes(&key_package).map_err(to_napi_err)?[..])
.map_err(to_napi_err)?;
let signing_package =
SigningPackage::deserialize(&hex_to_vec_bytes(&signing_package).map_err(to_napi_err)?[..])
.map_err(to_napi_err)?;
let randomizer =
Randomizer::deserialize(&hex_to_bytes(&public_key_randomness).map_err(to_napi_err)?)
.map_err(to_napi_err)?;
round_two_rust(signing_package, key_package, randomizer, seed).map_err(to_napi_err)
}
6 changes: 6 additions & 0 deletions ironfish-rust-nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
use std::fmt::Display;

use ironfish::keys::Language;
use ironfish::keys::ProofGenerationKeySerializable;
use ironfish::PublicAddress;
use ironfish::SaplingKey;

use napi::bindgen_prelude::*;
use napi_derive::napi;

use ironfish::mining;
use ironfish::sapling_bls12;

pub mod fish_hash;
pub mod frost;
pub mod mpc;
pub mod nacl;
pub mod rolling_filter;
Expand Down Expand Up @@ -62,6 +65,7 @@ pub struct Key {
pub incoming_view_key: String,
pub outgoing_view_key: String,
pub public_address: String,
pub proof_generation_key: String,
}

#[napi]
Expand All @@ -74,6 +78,7 @@ pub fn generate_key() -> Key {
incoming_view_key: sapling_key.incoming_view_key().hex_key(),
outgoing_view_key: sapling_key.outgoing_view_key().hex_key(),
public_address: sapling_key.public_address().hex_public_address(),
proof_generation_key: sapling_key.sapling_proof_generation_key().hex_key(),
}
}

Expand All @@ -100,6 +105,7 @@ pub fn generate_key_from_private_key(private_key: String) -> Result<Key> {
incoming_view_key: sapling_key.incoming_view_key().hex_key(),
outgoing_view_key: sapling_key.outgoing_view_key().hex_key(),
public_address: sapling_key.public_address().hex_public_address(),
proof_generation_key: sapling_key.sapling_proof_generation_key().hex_key(),
})
}

Expand Down
Loading

0 comments on commit ed05969

Please sign in to comment.