@onekeyfe/cardano-coin-selection-asmjs 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.MD +25 -0
- package/README.md +183 -0
- package/lib/cjs/constants/index.d.ts +40 -0
- package/lib/cjs/constants/index.js +69 -0
- package/lib/cjs/index.d.ts +6 -0
- package/lib/cjs/index.js +101 -0
- package/lib/cjs/methods/largestFirst.d.ts +2 -0
- package/lib/cjs/methods/largestFirst.js +201 -0
- package/lib/cjs/methods/randomImprove.d.ts +2 -0
- package/lib/cjs/methods/randomImprove.js +187 -0
- package/lib/cjs/types/trezor.d.ts +45 -0
- package/lib/cjs/types/trezor.js +8 -0
- package/lib/cjs/types/types.d.ts +116 -0
- package/lib/cjs/types/types.js +17 -0
- package/lib/cjs/utils/common.d.ts +46 -0
- package/lib/cjs/utils/common.js +514 -0
- package/lib/cjs/utils/errors.d.ts +8 -0
- package/lib/cjs/utils/errors.js +13 -0
- package/lib/cjs/utils/logger.d.ts +5 -0
- package/lib/cjs/utils/logger.js +27 -0
- package/lib/cjs/utils/onekey/dapp.d.ts +14 -0
- package/lib/cjs/utils/onekey/dapp.js +247 -0
- package/lib/cjs/utils/onekey/error.d.ts +28 -0
- package/lib/cjs/utils/onekey/error.js +25 -0
- package/lib/cjs/utils/onekey/index.d.ts +48 -0
- package/lib/cjs/utils/onekey/index.js +15 -0
- package/lib/cjs/utils/onekey/signTx.d.ts +26 -0
- package/lib/cjs/utils/onekey/signTx.js +296 -0
- package/lib/cjs/utils/onekey/transaction.d.ts +5 -0
- package/lib/cjs/utils/onekey/transaction.js +49 -0
- package/lib/cjs/utils/onekey/txToOneKey.d.ts +67 -0
- package/lib/cjs/utils/onekey/txToOneKey.js +504 -0
- package/lib/cjs/utils/onekey/types.d.ts +79 -0
- package/lib/cjs/utils/onekey/types.js +16 -0
- package/lib/cjs/utils/trezor/index.d.ts +3 -0
- package/lib/cjs/utils/trezor/index.js +9 -0
- package/lib/cjs/utils/trezor/sign.d.ts +5 -0
- package/lib/cjs/utils/trezor/sign.js +69 -0
- package/lib/cjs/utils/trezor/transformations.d.ts +17 -0
- package/lib/cjs/utils/trezor/transformations.js +66 -0
- package/lib/esm/constants/index.d.ts +40 -0
- package/lib/esm/constants/index.js +43 -0
- package/lib/esm/index.d.ts +6 -0
- package/lib/esm/index.js +73 -0
- package/lib/esm/methods/largestFirst.d.ts +2 -0
- package/lib/esm/methods/largestFirst.js +174 -0
- package/lib/esm/methods/randomImprove.d.ts +2 -0
- package/lib/esm/methods/randomImprove.js +160 -0
- package/lib/esm/types/trezor.d.ts +45 -0
- package/lib/esm/types/trezor.js +5 -0
- package/lib/esm/types/types.d.ts +116 -0
- package/lib/esm/types/types.js +14 -0
- package/lib/esm/utils/common.d.ts +46 -0
- package/lib/esm/utils/common.js +460 -0
- package/lib/esm/utils/errors.d.ts +8 -0
- package/lib/esm/utils/errors.js +9 -0
- package/lib/esm/utils/logger.d.ts +5 -0
- package/lib/esm/utils/logger.js +23 -0
- package/lib/esm/utils/onekey/dapp.d.ts +14 -0
- package/lib/esm/utils/onekey/dapp.js +216 -0
- package/lib/esm/utils/onekey/error.d.ts +28 -0
- package/lib/esm/utils/onekey/error.js +22 -0
- package/lib/esm/utils/onekey/index.d.ts +48 -0
- package/lib/esm/utils/onekey/index.js +11 -0
- package/lib/esm/utils/onekey/signTx.d.ts +26 -0
- package/lib/esm/utils/onekey/signTx.js +266 -0
- package/lib/esm/utils/onekey/transaction.d.ts +5 -0
- package/lib/esm/utils/onekey/transaction.js +42 -0
- package/lib/esm/utils/onekey/txToOneKey.d.ts +67 -0
- package/lib/esm/utils/onekey/txToOneKey.js +477 -0
- package/lib/esm/utils/onekey/types.d.ts +79 -0
- package/lib/esm/utils/onekey/types.js +15 -0
- package/lib/esm/utils/trezor/index.d.ts +3 -0
- package/lib/esm/utils/trezor/index.js +3 -0
- package/lib/esm/utils/trezor/sign.d.ts +5 -0
- package/lib/esm/utils/trezor/sign.js +42 -0
- package/lib/esm/utils/trezor/transformations.d.ts +17 -0
- package/lib/esm/utils/trezor/transformations.js +60 -0
- package/package.json +61 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.dAppUtils = exports.extractKeyHash = exports.assetsToValue = void 0;
|
|
30
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
31
|
+
const CardanoWasm = __importStar(require("@emurgo/cardano-serialization-lib-asmjs"));
|
|
32
|
+
const CardanoMessage = __importStar(require("@emurgo/cardano-message-signing-asmjs/cardano_message_signing"));
|
|
33
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
34
|
+
const signTx_1 = require("./signTx");
|
|
35
|
+
const error_1 = require("./error");
|
|
36
|
+
const getBalance = async (balances) => {
|
|
37
|
+
const value = await (0, exports.assetsToValue)(balances);
|
|
38
|
+
return Buffer.from(value.to_bytes(), 'hex').toString('hex');
|
|
39
|
+
};
|
|
40
|
+
const assetsToValue = async (assets) => {
|
|
41
|
+
const multiAsset = CardanoWasm.MultiAsset.new();
|
|
42
|
+
const lovelace = assets.find(asset => asset.unit === 'lovelace');
|
|
43
|
+
const policies = [
|
|
44
|
+
...new Set(assets
|
|
45
|
+
.filter(asset => asset.unit !== 'lovelace')
|
|
46
|
+
.map(asset => asset.unit.slice(0, 56))),
|
|
47
|
+
];
|
|
48
|
+
policies.forEach(policy => {
|
|
49
|
+
const policyAssets = assets.filter(asset => asset.unit.slice(0, 56) === policy);
|
|
50
|
+
const assetsValue = CardanoWasm.Assets.new();
|
|
51
|
+
policyAssets.forEach(asset => {
|
|
52
|
+
assetsValue.insert(CardanoWasm.AssetName.new(Buffer.from(asset.unit.slice(56), 'hex')), CardanoWasm.BigNum.from_str(asset.quantity));
|
|
53
|
+
});
|
|
54
|
+
multiAsset.insert(CardanoWasm.ScriptHash.from_bytes(Buffer.from(policy, 'hex')), assetsValue);
|
|
55
|
+
});
|
|
56
|
+
const value = CardanoWasm.Value.new(CardanoWasm.BigNum.from_str(lovelace ? lovelace.quantity : '0'));
|
|
57
|
+
if (assets.length > 1 || !lovelace)
|
|
58
|
+
value.set_multiasset(multiAsset);
|
|
59
|
+
return value;
|
|
60
|
+
};
|
|
61
|
+
exports.assetsToValue = assetsToValue;
|
|
62
|
+
const getAddresses = async (addresses) => {
|
|
63
|
+
return addresses.map(address => {
|
|
64
|
+
const addr = Buffer.from(CardanoWasm.Address.from_bech32(address).to_bytes(), 'hex').toString('hex');
|
|
65
|
+
return addr;
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const getUtxos = async (address, utxos, amount) => {
|
|
69
|
+
let converted = await (0, signTx_1.getUtxos)(address, utxos);
|
|
70
|
+
// filter utxos
|
|
71
|
+
if (amount) {
|
|
72
|
+
let filterVaule;
|
|
73
|
+
try {
|
|
74
|
+
filterVaule = CardanoWasm.Value.from_bytes(Buffer.from(amount, 'hex'));
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
throw new Error('Invalid Request');
|
|
78
|
+
}
|
|
79
|
+
converted = converted === null || converted === void 0 ? void 0 : converted.filter(unspent => !unspent.output().amount().compare(filterVaule) ||
|
|
80
|
+
unspent.output().amount().compare(filterVaule) !== -1);
|
|
81
|
+
}
|
|
82
|
+
if (amount && Array.isArray(converted) && converted.length <= 0) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return converted === null || converted === void 0 ? void 0 : converted.map(utxo => Buffer.from(utxo.to_bytes(), 'hex').toString('hex'));
|
|
86
|
+
};
|
|
87
|
+
const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) => {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(txHex, 'hex'));
|
|
90
|
+
const body = tx.body();
|
|
91
|
+
// Fee
|
|
92
|
+
const fee = body.fee().to_str();
|
|
93
|
+
const totalFeeInNative = new bignumber_js_1.default(fee).shiftedBy(-1 * 6).toFixed();
|
|
94
|
+
// inputs txs
|
|
95
|
+
const encodeInputs = [];
|
|
96
|
+
const inputs = [];
|
|
97
|
+
const inputsLen = body.inputs().len();
|
|
98
|
+
for (let i = 0; i < inputsLen; i++) {
|
|
99
|
+
const input = body.inputs().get(i);
|
|
100
|
+
const txHash = Buffer.from(input.transaction_id().to_bytes(), 'utf8').toString('hex');
|
|
101
|
+
const index = input.index();
|
|
102
|
+
inputs.push({ tx_hash: txHash, tx_index: index });
|
|
103
|
+
const utxo = utxos.find(utxo => utxo.tx_hash === txHash && +utxo.tx_index === +index);
|
|
104
|
+
encodeInputs.push(utxo);
|
|
105
|
+
}
|
|
106
|
+
// outputs txs
|
|
107
|
+
const outputs = [];
|
|
108
|
+
const outputsLen = body.outputs().len();
|
|
109
|
+
for (let i = 0; i < outputsLen; i++) {
|
|
110
|
+
const output = body.outputs().get(i);
|
|
111
|
+
const address = output.address().to_bech32();
|
|
112
|
+
const amount = output.amount().coin().to_str();
|
|
113
|
+
// get the asset from output
|
|
114
|
+
const assetsArray = [];
|
|
115
|
+
const multiasset = output.amount().multiasset();
|
|
116
|
+
if (multiasset) {
|
|
117
|
+
const keys = multiasset.keys(); // policy Ids of thee multiasset
|
|
118
|
+
const N = keys.len();
|
|
119
|
+
// (`${N} Multiassets in the UTXO`)
|
|
120
|
+
for (let i = 0; i < N; i++) {
|
|
121
|
+
const policyId = keys.get(i);
|
|
122
|
+
const policyIdHex = Buffer.from(policyId.to_bytes(), 'utf8').toString('hex');
|
|
123
|
+
const assets = multiasset.get(policyId);
|
|
124
|
+
if (assets) {
|
|
125
|
+
const assetNames = assets.keys();
|
|
126
|
+
const K = assetNames.len();
|
|
127
|
+
for (let j = 0; j < K; j++) {
|
|
128
|
+
const assetName = assetNames.get(j);
|
|
129
|
+
const assetNameHex = Buffer.from(assetName.name(), 'utf8').toString('hex');
|
|
130
|
+
const multiassetAmt = multiasset.get_asset(policyId, assetName);
|
|
131
|
+
assetsArray.push({
|
|
132
|
+
unit: `${policyIdHex}${assetNameHex}`,
|
|
133
|
+
quantity: multiassetAmt.to_str(),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// isChange: outputs length > 0 && address === changeAddress.address
|
|
140
|
+
const isChange = i > 0 && address === changeAddress.address;
|
|
141
|
+
outputs.push({
|
|
142
|
+
amount: amount,
|
|
143
|
+
address: address,
|
|
144
|
+
assets: assetsArray,
|
|
145
|
+
isChange,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const totalSpent = bignumber_js_1.default.sum(...outputs.map(o => o.amount)).toFixed();
|
|
149
|
+
const token = (_b = (_a = outputs
|
|
150
|
+
.filter(o => !addresses.includes(o.address))
|
|
151
|
+
.find(o => o.assets.length > 0)) === null || _a === void 0 ? void 0 : _a.assets) === null || _b === void 0 ? void 0 : _b[0].unit;
|
|
152
|
+
const encodedTx = {
|
|
153
|
+
inputs: encodeInputs.map(input => (Object.assign(Object.assign({}, input), { txHash: input.tx_hash, outputIndex: input.tx_index }))),
|
|
154
|
+
outputs,
|
|
155
|
+
fee,
|
|
156
|
+
totalSpent,
|
|
157
|
+
totalFeeInNative,
|
|
158
|
+
transferInfo: {
|
|
159
|
+
from: encodeInputs[0].address,
|
|
160
|
+
to: outputs[0].address,
|
|
161
|
+
amount: totalSpent,
|
|
162
|
+
token,
|
|
163
|
+
},
|
|
164
|
+
tx: {
|
|
165
|
+
body: body.to_hex(),
|
|
166
|
+
hash: Buffer.from(CardanoWasm.hash_transaction(body).to_bytes(), 'utf8').toString('hex'),
|
|
167
|
+
size: 0,
|
|
168
|
+
rawTxHex: txHex,
|
|
169
|
+
},
|
|
170
|
+
signOnly: true,
|
|
171
|
+
};
|
|
172
|
+
console.log('Cardano DApp EncodedTx: ', encodedTx);
|
|
173
|
+
return encodedTx;
|
|
174
|
+
};
|
|
175
|
+
const signData = async (address, payload, xprv, accountIndex) => {
|
|
176
|
+
const keyHash = await (0, exports.extractKeyHash)(address);
|
|
177
|
+
if (!keyHash) {
|
|
178
|
+
throw error_1.DataSignError.InvalidFormat;
|
|
179
|
+
}
|
|
180
|
+
const prefix = keyHash.startsWith('addr_vkh') ? 'addr_vkh' : 'stake_vkh';
|
|
181
|
+
const { paymentKey, stakeKey } = await (0, signTx_1.requestAccountKey)(xprv, accountIndex);
|
|
182
|
+
const accountKey = prefix === 'addr_vkh' ? paymentKey : stakeKey;
|
|
183
|
+
const publicKey = accountKey.to_public();
|
|
184
|
+
if (keyHash !== publicKey.hash().to_bech32(prefix))
|
|
185
|
+
throw error_1.DataSignError.ProofGeneration;
|
|
186
|
+
const protectedHeaders = CardanoMessage.HeaderMap.new();
|
|
187
|
+
protectedHeaders.set_algorithm_id(CardanoMessage.Label.from_algorithm_id(CardanoMessage.AlgorithmId.EdDSA));
|
|
188
|
+
// protectedHeaders.set_key_id(publicKey.as_bytes()); // Removed to adhere to CIP-30
|
|
189
|
+
protectedHeaders.set_header(CardanoMessage.Label.new_text('address'), CardanoMessage.CBORValue.new_bytes(Buffer.from(address, 'hex')));
|
|
190
|
+
const protectedSerialized = CardanoMessage.ProtectedHeaderMap.new(protectedHeaders);
|
|
191
|
+
const unprotectedHeaders = CardanoMessage.HeaderMap.new();
|
|
192
|
+
const headers = CardanoMessage.Headers.new(protectedSerialized, unprotectedHeaders);
|
|
193
|
+
const builder = CardanoMessage.COSESign1Builder.new(headers, Buffer.from(payload, 'hex'), false);
|
|
194
|
+
const toSign = builder.make_data_to_sign().to_bytes();
|
|
195
|
+
const signedSigStruc = accountKey.sign(toSign).to_bytes();
|
|
196
|
+
const coseSign1 = builder.build(signedSigStruc);
|
|
197
|
+
stakeKey.free();
|
|
198
|
+
paymentKey.free();
|
|
199
|
+
const key = CardanoMessage.COSEKey.new(CardanoMessage.Label.from_key_type(CardanoMessage.KeyType.OKP));
|
|
200
|
+
key.set_algorithm_id(CardanoMessage.Label.from_algorithm_id(CardanoMessage.AlgorithmId.EdDSA));
|
|
201
|
+
key.set_header(CardanoMessage.Label.new_int(CardanoMessage.Int.new_negative(CardanoMessage.BigNum.from_str('1'))), CardanoMessage.CBORValue.new_int(CardanoMessage.Int.new_i32(6))); // crv (-1) set to Ed25519 (6)
|
|
202
|
+
key.set_header(CardanoMessage.Label.new_int(CardanoMessage.Int.new_negative(CardanoMessage.BigNum.from_str('2'))), CardanoMessage.CBORValue.new_bytes(publicKey.as_bytes())); // x (-2) set to public key
|
|
203
|
+
return {
|
|
204
|
+
signature: Buffer.from(coseSign1.to_bytes()).toString('hex'),
|
|
205
|
+
key: Buffer.from(key.to_bytes()).toString('hex'),
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
const extractKeyHash = async (address) => {
|
|
209
|
+
var _a;
|
|
210
|
+
try {
|
|
211
|
+
const addr = CardanoWasm.BaseAddress.from_address(CardanoWasm.Address.from_bytes(Buffer.from(address, 'hex')));
|
|
212
|
+
return (_a = addr.payment_cred()) === null || _a === void 0 ? void 0 : _a.to_keyhash().to_bech32('addr_vkh');
|
|
213
|
+
}
|
|
214
|
+
catch (e) {
|
|
215
|
+
// ignore
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
const addr = CardanoWasm.EnterpriseAddress.from_address(CardanoWasm.Address.from_bytes(Buffer.from(address, 'hex')));
|
|
219
|
+
return addr.payment_cred().to_keyhash().to_bech32('addr_vkh');
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
// ignore
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
const addr = CardanoWasm.PointerAddress.from_address(CardanoWasm.Address.from_bytes(Buffer.from(address, 'hex')));
|
|
226
|
+
return addr.payment_cred().to_keyhash().to_bech32('addr_vkh');
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
// ignore
|
|
230
|
+
}
|
|
231
|
+
try {
|
|
232
|
+
const addr = CardanoWasm.RewardAddress.from_address(CardanoWasm.Address.from_bytes(Buffer.from(address, 'hex')));
|
|
233
|
+
return addr.payment_cred().to_keyhash().to_bech32('stake_vkh');
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
// ignore
|
|
237
|
+
}
|
|
238
|
+
throw error_1.DataSignError.AddressNotPK;
|
|
239
|
+
};
|
|
240
|
+
exports.extractKeyHash = extractKeyHash;
|
|
241
|
+
exports.dAppUtils = {
|
|
242
|
+
getBalance,
|
|
243
|
+
getAddresses,
|
|
244
|
+
getUtxos,
|
|
245
|
+
convertCborTxToEncodeTx,
|
|
246
|
+
signData,
|
|
247
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const TxSignError: {
|
|
2
|
+
ProofGeneration: {
|
|
3
|
+
code: number;
|
|
4
|
+
info: string;
|
|
5
|
+
};
|
|
6
|
+
UserDeclined: {
|
|
7
|
+
code: number;
|
|
8
|
+
info: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const DataSignError: {
|
|
12
|
+
ProofGeneration: {
|
|
13
|
+
code: number;
|
|
14
|
+
info: string;
|
|
15
|
+
};
|
|
16
|
+
AddressNotPK: {
|
|
17
|
+
code: number;
|
|
18
|
+
info: string;
|
|
19
|
+
};
|
|
20
|
+
UserDeclined: {
|
|
21
|
+
code: number;
|
|
22
|
+
info: string;
|
|
23
|
+
};
|
|
24
|
+
InvalidFormat: {
|
|
25
|
+
code: number;
|
|
26
|
+
info: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataSignError = exports.TxSignError = void 0;
|
|
4
|
+
exports.TxSignError = {
|
|
5
|
+
ProofGeneration: {
|
|
6
|
+
code: 1,
|
|
7
|
+
info: 'User has accepted the transaction sign, but the wallet was unable to sign the transaction (e.g. not having some of the private keys).',
|
|
8
|
+
},
|
|
9
|
+
UserDeclined: { code: 2, info: 'User declined to sign the transaction.' },
|
|
10
|
+
};
|
|
11
|
+
exports.DataSignError = {
|
|
12
|
+
ProofGeneration: {
|
|
13
|
+
code: 1,
|
|
14
|
+
info: 'Wallet could not sign the data (e.g. does not have the secret key associated with the address).',
|
|
15
|
+
},
|
|
16
|
+
AddressNotPK: {
|
|
17
|
+
code: 2,
|
|
18
|
+
info: 'Address was not a P2PK address or Reward address and thus had no SK associated with it.',
|
|
19
|
+
},
|
|
20
|
+
UserDeclined: { code: 3, info: 'User declined to sign the data.' },
|
|
21
|
+
InvalidFormat: {
|
|
22
|
+
code: 4,
|
|
23
|
+
info: 'If a wallet enforces data format requirements, this error signifies that the data did not conform to valid formats.',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { dAppUtils } from './dapp';
|
|
2
|
+
declare const onekeyUtils: {
|
|
3
|
+
composeTxPlan: (transferInfo: import("./types").ITransferInfo, accountXpub: string, utxos: import("./types").IAdaUTXO[], changeAddress: string, outputs: import("./types").IOutput[], options?: {
|
|
4
|
+
debug: boolean;
|
|
5
|
+
} | undefined) => Promise<import("../../types/types").PrecomposedTransaction>;
|
|
6
|
+
signTransaction: (txBodyHex: string, address: string, accountIndex: number, utxos: import("./types").IAdaUTXO[], xprv: string, signOnly: boolean, partialSign?: boolean | undefined) => Promise<{
|
|
7
|
+
signedTx: string;
|
|
8
|
+
txid: string;
|
|
9
|
+
}>;
|
|
10
|
+
signTx: (keys: {
|
|
11
|
+
accountKey: import("@emurgo/cardano-serialization-lib-asmjs").Bip32PrivateKey;
|
|
12
|
+
paymentKey: import("@emurgo/cardano-serialization-lib-asmjs").PrivateKey;
|
|
13
|
+
stakeKey: import("@emurgo/cardano-serialization-lib-asmjs").PrivateKey;
|
|
14
|
+
}, tx: string, keyHashes: string[], partialSign?: boolean) => Promise<import("@emurgo/cardano-serialization-lib-asmjs").TransactionWitnessSet>;
|
|
15
|
+
txToOneKey: (rawTx: string, network: number, initKeys: {
|
|
16
|
+
payment: {
|
|
17
|
+
hash: string | null;
|
|
18
|
+
path: string | null;
|
|
19
|
+
};
|
|
20
|
+
stake: {
|
|
21
|
+
hash: string | null;
|
|
22
|
+
path: string | null;
|
|
23
|
+
};
|
|
24
|
+
}, xpub: string, changeAddress: import("./types").IChangeAddress) => Promise<{
|
|
25
|
+
signingMode: import("./txToOneKey").CardanoTxSigningMode.ORDINARY_TRANSACTION | import("./txToOneKey").CardanoTxSigningMode.POOL_REGISTRATION_AS_OWNER | import("./txToOneKey").CardanoTxSigningMode.PLUTUS_TRANSACTION;
|
|
26
|
+
outputs: never[];
|
|
27
|
+
fee: string;
|
|
28
|
+
ttl: string | null;
|
|
29
|
+
validityIntervalStart: any;
|
|
30
|
+
certificates: [] | null;
|
|
31
|
+
withdrawals: null;
|
|
32
|
+
auxiliaryData: {
|
|
33
|
+
hash: string;
|
|
34
|
+
} | null;
|
|
35
|
+
mint: null;
|
|
36
|
+
scriptDataHash: string | null;
|
|
37
|
+
collateralInputs: null;
|
|
38
|
+
requiredSigners: null;
|
|
39
|
+
protocolMagic: number;
|
|
40
|
+
networkId: number;
|
|
41
|
+
includeNetworkId: boolean;
|
|
42
|
+
additionalWitnessRequests: null;
|
|
43
|
+
collateralReturn: null;
|
|
44
|
+
totalCollateral: string | null;
|
|
45
|
+
referenceInputs: null;
|
|
46
|
+
}>;
|
|
47
|
+
};
|
|
48
|
+
export { onekeyUtils, dAppUtils };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dAppUtils = exports.onekeyUtils = void 0;
|
|
4
|
+
const transaction_1 = require("./transaction");
|
|
5
|
+
const signTx_1 = require("./signTx");
|
|
6
|
+
const dapp_1 = require("./dapp");
|
|
7
|
+
Object.defineProperty(exports, "dAppUtils", { enumerable: true, get: function () { return dapp_1.dAppUtils; } });
|
|
8
|
+
const txToOneKey_1 = require("./txToOneKey");
|
|
9
|
+
const onekeyUtils = {
|
|
10
|
+
composeTxPlan: transaction_1.composeTxPlan,
|
|
11
|
+
signTransaction: signTx_1.signTransaction,
|
|
12
|
+
signTx: signTx_1.signTx,
|
|
13
|
+
txToOneKey: txToOneKey_1.txToOneKey,
|
|
14
|
+
};
|
|
15
|
+
exports.onekeyUtils = onekeyUtils;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as CardanoWasm from '@emurgo/cardano-serialization-lib-asmjs';
|
|
2
|
+
import { IAdaUTXO } from './types';
|
|
3
|
+
declare type SignKeys = {
|
|
4
|
+
accountKey: CardanoWasm.Bip32PrivateKey;
|
|
5
|
+
paymentKey: CardanoWasm.PrivateKey;
|
|
6
|
+
stakeKey: CardanoWasm.PrivateKey;
|
|
7
|
+
};
|
|
8
|
+
export declare const signTransaction: (txBodyHex: string, address: string, accountIndex: number, utxos: IAdaUTXO[], xprv: string, signOnly: boolean, partialSign?: boolean) => Promise<{
|
|
9
|
+
signedTx: string;
|
|
10
|
+
txid: string;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {string} tx - cbor hex string
|
|
15
|
+
* @param {Array<string>} keyHashes
|
|
16
|
+
* @param {string} password
|
|
17
|
+
* @returns {string} witness set as hex string
|
|
18
|
+
*/
|
|
19
|
+
export declare const signTx: (keys: SignKeys, tx: string, keyHashes: string[], partialSign?: boolean) => Promise<CardanoWasm.TransactionWitnessSet>;
|
|
20
|
+
export declare const getUtxos: (address: string, utxos: IAdaUTXO[]) => Promise<CardanoWasm.TransactionUnspentOutput[] | null>;
|
|
21
|
+
export declare const requestAccountKey: (xprv: string, accountIndex: number) => Promise<{
|
|
22
|
+
accountKey: any;
|
|
23
|
+
paymentKey: any;
|
|
24
|
+
stakeKey: any;
|
|
25
|
+
}>;
|
|
26
|
+
export {};
|