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

Support Near family #130

Merged
merged 1 commit into from
Mar 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-buttons-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/wallet-api-core": minor
---

Support Near family
Copy link
Contributor

Choose a reason for hiding this comment

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

Think we can remove this file as seems there are no other files in this folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cksanders Not sure what you mean. Can you elaborate on this?

1 change: 1 addition & 0 deletions packages/core/src/families/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const FAMILIES = [
"polkadot",
"stellar",
"tron",
"near",
] as const;

export const schemaFamilies = z.enum(FAMILIES);
1 change: 1 addition & 0 deletions packages/core/src/families/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from "./crypto_org/types";
export * from "./ethereum/types";
export * from "./hedera/types";
export * from "./filecoin/types";
export * from "./near/types";
export * from "./polkadot/types";
export * from "./ripple/types";
export * from "./stellar/types";
Expand Down
34 changes: 34 additions & 0 deletions packages/core/src/families/near/serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import BigNumber from "bignumber.js";
import type { RawNearTransaction, NearTransaction } from "./types";

export function serialize({
amount,
recipient,
family,
mode,
fees,
}: NearTransaction): RawNearTransaction {
return {
amount: amount.toString(),
recipient,
family,
mode,
fees: fees?.toString(),
};
}

export function deserialize({
amount,
recipient,
family,
mode,
fees,
}: RawNearTransaction): NearTransaction {
return {
amount: new BigNumber(amount),
recipient,
family,
mode,
fees: fees ? new BigNumber(fees) : undefined,
};
}
12 changes: 12 additions & 0 deletions packages/core/src/families/near/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type BigNumber from "bignumber.js";
import type { z } from "zod";
import type { TransactionCommon } from "../index";
import type { schemaRawNearTransaction } from "./validation";

export interface NearTransaction extends TransactionCommon {
readonly family: RawNearTransaction["family"];
mode: string;
fees?: BigNumber;
}

export type RawNearTransaction = z.infer<typeof schemaRawNearTransaction>;
8 changes: 8 additions & 0 deletions packages/core/src/families/near/validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { z } from "zod";
import { schemaFamilies, schemaTransactionCommon } from "../common";

export const schemaRawNearTransaction = schemaTransactionCommon.extend({
family: z.literal(schemaFamilies.enum.near),
mode: z.string(),
fees: z.string().optional(),
});
5 changes: 5 additions & 0 deletions packages/core/src/families/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
deserializeEthereumTransaction,
serializeEthereumTransaction,
} from "./ethereum/serializer";
import * as near from "./near/serializer";
import {
deserializeHederaTransaction,
serializeHederaTransaction,
Expand Down Expand Up @@ -88,6 +89,8 @@ export function serializeTransaction(transaction: Transaction): RawTransaction {
return serializeStellarTransaction(transaction);
case "tron":
return serializeTronTransaction(transaction);
case "near":
return near.serialize(transaction);
default: {
const exhaustiveCheck: never = transaction; // https://www.typescriptlang.org/docs/handbook/2/narrowing.html#exhaustiveness-checking
return exhaustiveCheck;
Expand Down Expand Up @@ -133,6 +136,8 @@ export function deserializeTransaction(
return deserializeStellarTransaction(rawTransaction);
case "tron":
return deserializeTronTransaction(rawTransaction);
case "near":
return near.deserialize(rawTransaction);
default: {
const exhaustiveCheck: never = rawTransaction; // https://www.typescriptlang.org/docs/handbook/2/narrowing.html#exhaustiveness-checking
return exhaustiveCheck;
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/families/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { CryptoOrgTransaction } from "./crypto_org/types";
import type { EthereumTransaction } from "./ethereum/types";
import type { HederaTransaction } from "./hedera/types";
import type { FilecoinTransaction } from "./filecoin/types";
import type { NearTransaction } from "./near/types";
import type { PolkadotTransaction } from "./polkadot/types";
import type { RippleTransaction } from "./ripple/types";
import type { StellarTransaction } from "./stellar/types";
Expand Down Expand Up @@ -69,4 +70,5 @@ export type Transaction =
| TezosTransaction
| PolkadotTransaction
| StellarTransaction
| TronTransaction;
| TronTransaction
| NearTransaction;
2 changes: 2 additions & 0 deletions packages/core/src/families/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { schemaRawCeloTransaction } from "./celo/validation";
import { schemaRawCosmosTransaction } from "./cosmos/validation";
import { schemaRawCryptoOrgTransaction } from "./crypto_org/validation";
import { schemaRawEthereumTransaction } from "./ethereum/validation";
import { schemaRawNearTransaction } from "./near/validation";
import { schemaRawPolkadotTransaction } from "./polkadot/validation";
import { schemaRawRippleTransaction } from "./ripple/validation";
import { schemaRawStellarTransaction } from "./stellar/validation";
Expand All @@ -22,6 +23,7 @@ export const schemaRawTransaction = z.discriminatedUnion("family", [
schemaRawEthereumTransaction,
schemaRawHederaTransaction,
schemaRawFilecoinTransaction,
schemaRawNearTransaction,
schemaRawPolkadotTransaction,
schemaRawRippleTransaction,
schemaRawStellarTransaction,
Expand Down
59 changes: 35 additions & 24 deletions website/docs/reference/api/client/index.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:40
packages/core/lib/families/types.d.ts:41

___

Expand Down Expand Up @@ -101,4 +101,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:44
packages/core/lib/families/types.d.ts:45
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:40
packages/core/lib/families/types.d.ts:41

___

Expand Down Expand Up @@ -81,4 +81,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:44
packages/core/lib/families/types.d.ts:45
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:40
packages/core/lib/families/types.d.ts:41

___

Expand Down Expand Up @@ -91,4 +91,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:44
packages/core/lib/families/types.d.ts:45
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:40
packages/core/lib/families/types.d.ts:41

___

Expand Down Expand Up @@ -101,4 +101,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:44
packages/core/lib/families/types.d.ts:45
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:40
packages/core/lib/families/types.d.ts:41

___

Expand Down Expand Up @@ -81,4 +81,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:44
packages/core/lib/families/types.d.ts:45
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:40
packages/core/lib/families/types.d.ts:41

___

Expand Down Expand Up @@ -101,4 +101,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:44
packages/core/lib/families/types.d.ts:45
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:40
packages/core/lib/families/types.d.ts:41

___

Expand Down Expand Up @@ -131,7 +131,7 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:44
packages/core/lib/families/types.d.ts:45

___

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:40
packages/core/lib/families/types.d.ts:41

___

Expand Down Expand Up @@ -71,4 +71,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:44
packages/core/lib/families/types.d.ts:45
84 changes: 84 additions & 0 deletions website/docs/reference/api/client/interfaces/NearTransaction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
id: "NearTransaction"
title: "Interface: NearTransaction"
sidebar_label: "NearTransaction"
sidebar_position: 0
custom_edit_url: null
---

Common fields for all cryptocurrency transactions

## Hierarchy

- [`TransactionCommon`](TransactionCommon.md)

↳ **`NearTransaction`**

## Properties

### amount

• **amount**: `BigNumber`

The amount of token to send in the transaction, denoted in the smallest cryptocurrency's magnitude
For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx corresponding to 0.00000001 BTC

#### Inherited from

[TransactionCommon](TransactionCommon.md).[amount](TransactionCommon.md#amount)

#### Defined in

packages/core/lib/families/types.d.ts:41

___

### family

• `Readonly` **family**: ``"near"``

The family of the transaction

#### Overrides

[TransactionCommon](TransactionCommon.md).[family](TransactionCommon.md#family)

#### Defined in

packages/core/lib/families/near/types.d.ts:6

___

### fees

• `Optional` **fees**: `BigNumber`

#### Defined in

packages/core/lib/families/near/types.d.ts:8

___

### mode

• **mode**: `string`

#### Defined in

packages/core/lib/families/near/types.d.ts:7

___

### recipient

• **recipient**: `string`

The address of the transaction's recipient

#### Inherited from

[TransactionCommon](TransactionCommon.md).[recipient](TransactionCommon.md#recipient)

#### Defined in

packages/core/lib/families/types.d.ts:45
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:40
packages/core/lib/families/types.d.ts:41

___

Expand Down Expand Up @@ -91,4 +91,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:44
packages/core/lib/families/types.d.ts:45
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:40
packages/core/lib/families/types.d.ts:41

___

Expand Down Expand Up @@ -71,7 +71,7 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:44
packages/core/lib/families/types.d.ts:45

___

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:40
packages/core/lib/families/types.d.ts:41

___

Expand Down Expand Up @@ -91,4 +91,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:44
packages/core/lib/families/types.d.ts:45