Skip to content

Commit

Permalink
NNS1-2886: Remove hardware wallet specific code paths from ledger-icp
Browse files Browse the repository at this point in the history
  • Loading branch information
dskloetd committed Mar 27, 2024
1 parent 2fa812a commit 832e344
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 505 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- ICP transactions, as provided by the Index canister, have been extended to include their block timestamp information.
- When no fee is specified when making an ICP transaction, use the mandatory fee
of 10000 e8s (0.0001 ICP) instead of fetching the fee from the network.
- Remove hardware wallet specific code paths from `@dfinity/ledger-icp`.

# 2024.03.25-1430Z

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { ICPTs, Subaccount } from "@dfinity/nns-proto";
import { arrayOfNumberToUint8Array, toNullable } from "@dfinity/utils";
import type {
TransferArg as Icrc1TransferRawRequest,
Expand All @@ -10,24 +9,6 @@ import type {
Icrc1TransferRequest,
TransferRequest,
} from "../../types/ledger_converters";
import { importNnsProto } from "../../utils/proto.utils";

export const subAccountNumbersToSubaccount = async (
subAccountNumbers: number[],
): Promise<Subaccount> => {
const bytes = new Uint8Array(subAccountNumbers).buffer;
const { Subaccount: SubaccountConstructor } = await importNnsProto();
const subaccount: Subaccount = new SubaccountConstructor();
subaccount.setSubAccount(new Uint8Array(bytes));
return subaccount;
};

export const toICPTs = async (amount: bigint): Promise<ICPTs> => {
const { ICPTs: ICPTsConstructor } = await importNnsProto();
const result = new ICPTsConstructor();
result.setE8s(amount.toString(10));
return result;
};

const e8sToTokens = (e8s: bigint): Tokens => ({ e8s });

Expand Down
48 changes: 0 additions & 48 deletions packages/ledger-icp/src/errors/ledger.errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { convertStringToE8s } from "@dfinity/utils";
import type {
Icrc1TransferError as RawIcrc1TransferError,
TransferError as RawTransferError,
Expand Down Expand Up @@ -90,50 +89,3 @@ export const mapIcrc1TransferError = (
`Unknown error type ${JSON.stringify(rawTransferError)}`,
);
};

export const mapTransferProtoError = (responseBytes: Error): TransferError => {
const { message } = responseBytes;

if (message.includes("Reject code: 5")) {
// Match against the different error types.
// This string matching is fragile. It's a stop-gap solution until
// we migrate to the candid interface.

if (message.match(/Sending from (.*) is not allowed/)) {
return new InvalidSenderError();
}

{
const m = message.match(/transaction.*duplicate.* in block (\d+)/);
if (m && m.length > 1) {
return new TxDuplicateError(BigInt(m[1]));
}
}

{
const m = message.match(
/debit account.*, current balance: (\d*(\.\d*)?)/,
);
if (m && m.length > 1) {
const balance = convertStringToE8s(m[1]);
if (typeof balance === "bigint") {
return new InsufficientFundsError(balance);
}
}
}

if (message.includes("is in future")) {
return new TxCreatedInFutureError();
}

{
const m = message.match(/older than (\d+)/);
if (m && m.length > 1) {
return new TxTooOldError(Number.parseInt(m[1]));
}
}
}

// Unknown error. Throw as-is.
throw responseBytes;
};
Loading

0 comments on commit 832e344

Please sign in to comment.