跳到主要内容

nemSignTransaction

NEM:签名交易

使用指定 BIP32 路径派生的私钥对交易进行签名。签名前,用户需要在 Ukey Wallet 上核对交易目标、金额和费用等关键信息。

const response = await HardwareSDK.nemSignTransaction(
connectId,
deviceId,
params,
);

参数

可选通用参数

  • path - 必需 string | Array<number>,字符串数组最小长度限制为 3更多信息
  • transaction - 必需 NEMTransaction 类型。

NEMTransaction 类型

type MosaicID = {
namespaceId: string;
name: string;
};

type MosaicDefinition = {
levy?: {
type?: number;
fee?: number;
recipient?: string;
mosaicId?: MosaicID;
};
id: MosaicID;
description: string;
properties?: Array<{
name: "divisibility" | "initialSupply" | "supplyMutable" | "transferable";
value: string;
}>;
};

export type NEMMosaic = {
mosaicId: MosaicID;
quantity: number;
};

type Modification = {
modificationType: number;
cosignatoryAccount: string;
};

type Message = {
payload?: string;
type?: number;
publicKey?: string;
};

type TransactionCommon = {
version: number;
timeStamp: number;
fee: number;
deadline?: number;
signer?: string;
};

export type NEMTransferTransaction = TransactionCommon & {
type: 0x0101;
recipient: string;
amount: number | string;
mosaics?: NEMMosaic[];
message?: Message;
};

export type NEMImportanceTransaction = TransactionCommon & {
type: 0x0801;
importanceTransfer: {
mode: number;
publicKey: string;
};
};

export type NEMAggregateModificationTransaction = TransactionCommon & {
type: 0x1001;
modifications?: Modification[];
minCosignatories: {
relativeChange: number;
};
};

export type NEMProvisionNamespaceTransaction = TransactionCommon & {
type: 0x2001;
newPart?: string;
parent?: string;
rentalFeeSink?: string;
rentalFee?: number;
};

export type NEMMosaicCreationTransaction = TransactionCommon & {
type: 0x4001;
mosaicDefinition: MosaicDefinition;
creationFeeSink?: string;
creationFee?: number;
};

export type NEMSupplyChangeTransaction = TransactionCommon & {
type: 0x4002;
mosaicId: MosaicID;
supplyType: number;
delta?: number;
};

type Transaction =
| NEMTransferTransaction
| NEMImportanceTransaction
| NEMAggregateModificationTransaction
| NEMProvisionNamespaceTransaction
| NEMMosaicCreationTransaction
| NEMSupplyChangeTransaction;

export type NEMMultisigTransaction = TransactionCommon & {
type: 0x0102 | 0x1002 | 0x1004;
otherTrans: Transaction;
};

export type NEMTransaction = Transaction | NEMMultisigTransaction;

示例

NEMTransferTransaction

HardwareSDK.nemSignTransaction(connectId, deviceId, {
path: "m/44'/43'/1'/0'/0",
transaction: {
type: 0x0101,
recipient: "TALICE2GMA34CXHD7XLJQ536NM5UNKQHTORNNT2J",
amount: 2500000,
timeStamp: 74651215,
fee: 2100000,
deadline: 74737615,
version: -1744830464,
},
});

返回结果

{
success: true,
payload: {
signature: string; // 签名结果
}
}

错误

{
success: false,
payload: {
error: string, // 错误消息
code: number // 错误码
}
}