@onekeyfe/cardano-coin-selection-asmjs 1.1.10 → 1.1.11
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/lib/cjs/utils/onekey/index.d.ts +3 -0
- package/lib/cjs/utils/onekey/index.js +4 -0
- package/lib/cjs/utils/onekey/parseRawTx.d.ts +12 -0
- package/lib/cjs/utils/onekey/parseRawTx.js +87 -0
- package/lib/esm/utils/onekey/index.d.ts +3 -0
- package/lib/esm/utils/onekey/index.js +4 -0
- package/lib/esm/utils/onekey/parseRawTx.d.ts +12 -0
- package/lib/esm/utils/onekey/parseRawTx.js +58 -0
- package/package.json +1 -1
|
@@ -46,5 +46,8 @@ declare const onekeyUtils: {
|
|
|
46
46
|
tagCborSets: boolean;
|
|
47
47
|
}>;
|
|
48
48
|
hasSetTagWithBody: (txBodyHex: string) => Promise<boolean>;
|
|
49
|
+
parseRawTxInputs: (rawTxHex: string) => Promise<import("./parseRawTx").IParsedRawTxInput[]>;
|
|
50
|
+
parseRawTxBodyStakeInfo: (rawTxHex: string) => Promise<import("./parseRawTx").IParsedRawTxBodyStakeInfo>;
|
|
51
|
+
extractStakeKeyHashFromBaseAddress: (addr: string) => Promise<string | null>;
|
|
49
52
|
};
|
|
50
53
|
export { onekeyUtils, dAppUtils };
|
|
@@ -7,11 +7,15 @@ const dapp_1 = require("./dapp");
|
|
|
7
7
|
Object.defineProperty(exports, "dAppUtils", { enumerable: true, get: function () { return dapp_1.dAppUtils; } });
|
|
8
8
|
const txToOneKey_1 = require("./txToOneKey");
|
|
9
9
|
const hasSetTag_1 = require("./hasSetTag");
|
|
10
|
+
const parseRawTx_1 = require("./parseRawTx");
|
|
10
11
|
const onekeyUtils = {
|
|
11
12
|
composeTxPlan: transaction_1.composeTxPlan,
|
|
12
13
|
signTransaction: signTx_1.signTransaction,
|
|
13
14
|
signTx: signTx_1.signTx,
|
|
14
15
|
txToOneKey: txToOneKey_1.txToOneKey,
|
|
15
16
|
hasSetTagWithBody: hasSetTag_1.hasSetTagWithBody,
|
|
17
|
+
parseRawTxInputs: parseRawTx_1.parseRawTxInputs,
|
|
18
|
+
parseRawTxBodyStakeInfo: parseRawTx_1.parseRawTxBodyStakeInfo,
|
|
19
|
+
extractStakeKeyHashFromBaseAddress: parseRawTx_1.extractStakeKeyHashFromBaseAddress,
|
|
16
20
|
};
|
|
17
21
|
exports.onekeyUtils = onekeyUtils;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type IParsedRawTxInput = {
|
|
2
|
+
prev_hash: string;
|
|
3
|
+
prev_index: number;
|
|
4
|
+
};
|
|
5
|
+
export type IParsedRawTxBodyStakeInfo = {
|
|
6
|
+
hasCertificates: boolean;
|
|
7
|
+
hasWithdrawals: boolean;
|
|
8
|
+
requiredSignerHashes: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare const parseRawTxInputs: (rawTxHex: string) => Promise<IParsedRawTxInput[]>;
|
|
11
|
+
export declare const parseRawTxBodyStakeInfo: (rawTxHex: string) => Promise<IParsedRawTxBodyStakeInfo>;
|
|
12
|
+
export declare const extractStakeKeyHashFromBaseAddress: (addr: string) => Promise<string | null>;
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.extractStakeKeyHashFromBaseAddress = exports.parseRawTxBodyStakeInfo = exports.parseRawTxInputs = void 0;
|
|
27
|
+
const CardanoWasm = __importStar(require("@emurgo/cardano-serialization-lib-asmjs"));
|
|
28
|
+
const parseRawTxInputs = (rawTxHex) => {
|
|
29
|
+
const tx = CardanoWasm.Transaction.from_hex(rawTxHex);
|
|
30
|
+
const inputs = tx.body().inputs();
|
|
31
|
+
const out = [];
|
|
32
|
+
for (let i = 0; i < inputs.len(); i += 1) {
|
|
33
|
+
const input = inputs.get(i);
|
|
34
|
+
out.push({
|
|
35
|
+
prev_hash: input.transaction_id().to_hex(),
|
|
36
|
+
prev_index: input.index(),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return Promise.resolve(out);
|
|
40
|
+
};
|
|
41
|
+
exports.parseRawTxInputs = parseRawTxInputs;
|
|
42
|
+
const parseRawTxBodyStakeInfo = (rawTxHex) => {
|
|
43
|
+
const tx = CardanoWasm.Transaction.from_hex(rawTxHex);
|
|
44
|
+
const body = tx.body();
|
|
45
|
+
const certs = body.certs();
|
|
46
|
+
const hasCertificates = !!certs && certs.len() > 0;
|
|
47
|
+
const withdrawals = body.withdrawals();
|
|
48
|
+
const hasWithdrawals = !!withdrawals && withdrawals.keys().len() > 0;
|
|
49
|
+
const requiredSigners = body.required_signers();
|
|
50
|
+
const requiredSignerHashes = [];
|
|
51
|
+
if (requiredSigners) {
|
|
52
|
+
for (let i = 0; i < requiredSigners.len(); i += 1) {
|
|
53
|
+
requiredSignerHashes.push(requiredSigners.get(i).to_hex());
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return Promise.resolve({
|
|
57
|
+
hasCertificates,
|
|
58
|
+
hasWithdrawals,
|
|
59
|
+
requiredSignerHashes,
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
exports.parseRawTxBodyStakeInfo = parseRawTxBodyStakeInfo;
|
|
63
|
+
// Returns the hex stake key hash for key-credential base addresses (types 0
|
|
64
|
+
// and 1 in Cardano address layout); returns null for script-credential stakes
|
|
65
|
+
// or non-base addresses. Caller should treat null as "cannot safely filter
|
|
66
|
+
// stake witness".
|
|
67
|
+
const extractStakeKeyHashFromBaseAddress = (addr) => {
|
|
68
|
+
try {
|
|
69
|
+
const address = CardanoWasm.Address.from_bech32(addr);
|
|
70
|
+
const baseAddress = CardanoWasm.BaseAddress.from_address(address);
|
|
71
|
+
if (!baseAddress)
|
|
72
|
+
return Promise.resolve(null);
|
|
73
|
+
const stakeCred = baseAddress.stake_cred();
|
|
74
|
+
if (stakeCred.kind() !== CardanoWasm.CredKind.Key) {
|
|
75
|
+
return Promise.resolve(null);
|
|
76
|
+
}
|
|
77
|
+
// spell-checker:disable-next-line
|
|
78
|
+
const stakeKey = stakeCred.to_keyhash();
|
|
79
|
+
if (!stakeKey)
|
|
80
|
+
return Promise.resolve(null);
|
|
81
|
+
return Promise.resolve(stakeKey.to_hex());
|
|
82
|
+
}
|
|
83
|
+
catch (_a) {
|
|
84
|
+
return Promise.resolve(null);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
exports.extractStakeKeyHashFromBaseAddress = extractStakeKeyHashFromBaseAddress;
|
|
@@ -46,5 +46,8 @@ declare const onekeyUtils: {
|
|
|
46
46
|
tagCborSets: boolean;
|
|
47
47
|
}>;
|
|
48
48
|
hasSetTagWithBody: (txBodyHex: string) => Promise<boolean>;
|
|
49
|
+
parseRawTxInputs: (rawTxHex: string) => Promise<import("./parseRawTx").IParsedRawTxInput[]>;
|
|
50
|
+
parseRawTxBodyStakeInfo: (rawTxHex: string) => Promise<import("./parseRawTx").IParsedRawTxBodyStakeInfo>;
|
|
51
|
+
extractStakeKeyHashFromBaseAddress: (addr: string) => Promise<string | null>;
|
|
49
52
|
};
|
|
50
53
|
export { onekeyUtils, dAppUtils };
|
|
@@ -3,11 +3,15 @@ import { signTransaction, signTx } from './signTx';
|
|
|
3
3
|
import { dAppUtils } from './dapp';
|
|
4
4
|
import { txToOneKey } from './txToOneKey';
|
|
5
5
|
import { hasSetTagWithBody } from './hasSetTag';
|
|
6
|
+
import { parseRawTxInputs, parseRawTxBodyStakeInfo, extractStakeKeyHashFromBaseAddress, } from './parseRawTx';
|
|
6
7
|
const onekeyUtils = {
|
|
7
8
|
composeTxPlan,
|
|
8
9
|
signTransaction,
|
|
9
10
|
signTx,
|
|
10
11
|
txToOneKey,
|
|
11
12
|
hasSetTagWithBody,
|
|
13
|
+
parseRawTxInputs,
|
|
14
|
+
parseRawTxBodyStakeInfo,
|
|
15
|
+
extractStakeKeyHashFromBaseAddress,
|
|
12
16
|
};
|
|
13
17
|
export { onekeyUtils, dAppUtils };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type IParsedRawTxInput = {
|
|
2
|
+
prev_hash: string;
|
|
3
|
+
prev_index: number;
|
|
4
|
+
};
|
|
5
|
+
export type IParsedRawTxBodyStakeInfo = {
|
|
6
|
+
hasCertificates: boolean;
|
|
7
|
+
hasWithdrawals: boolean;
|
|
8
|
+
requiredSignerHashes: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare const parseRawTxInputs: (rawTxHex: string) => Promise<IParsedRawTxInput[]>;
|
|
11
|
+
export declare const parseRawTxBodyStakeInfo: (rawTxHex: string) => Promise<IParsedRawTxBodyStakeInfo>;
|
|
12
|
+
export declare const extractStakeKeyHashFromBaseAddress: (addr: string) => Promise<string | null>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as CardanoWasm from '@emurgo/cardano-serialization-lib-asmjs';
|
|
2
|
+
export const parseRawTxInputs = (rawTxHex) => {
|
|
3
|
+
const tx = CardanoWasm.Transaction.from_hex(rawTxHex);
|
|
4
|
+
const inputs = tx.body().inputs();
|
|
5
|
+
const out = [];
|
|
6
|
+
for (let i = 0; i < inputs.len(); i += 1) {
|
|
7
|
+
const input = inputs.get(i);
|
|
8
|
+
out.push({
|
|
9
|
+
prev_hash: input.transaction_id().to_hex(),
|
|
10
|
+
prev_index: input.index(),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return Promise.resolve(out);
|
|
14
|
+
};
|
|
15
|
+
export const parseRawTxBodyStakeInfo = (rawTxHex) => {
|
|
16
|
+
const tx = CardanoWasm.Transaction.from_hex(rawTxHex);
|
|
17
|
+
const body = tx.body();
|
|
18
|
+
const certs = body.certs();
|
|
19
|
+
const hasCertificates = !!certs && certs.len() > 0;
|
|
20
|
+
const withdrawals = body.withdrawals();
|
|
21
|
+
const hasWithdrawals = !!withdrawals && withdrawals.keys().len() > 0;
|
|
22
|
+
const requiredSigners = body.required_signers();
|
|
23
|
+
const requiredSignerHashes = [];
|
|
24
|
+
if (requiredSigners) {
|
|
25
|
+
for (let i = 0; i < requiredSigners.len(); i += 1) {
|
|
26
|
+
requiredSignerHashes.push(requiredSigners.get(i).to_hex());
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return Promise.resolve({
|
|
30
|
+
hasCertificates,
|
|
31
|
+
hasWithdrawals,
|
|
32
|
+
requiredSignerHashes,
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
// Returns the hex stake key hash for key-credential base addresses (types 0
|
|
36
|
+
// and 1 in Cardano address layout); returns null for script-credential stakes
|
|
37
|
+
// or non-base addresses. Caller should treat null as "cannot safely filter
|
|
38
|
+
// stake witness".
|
|
39
|
+
export const extractStakeKeyHashFromBaseAddress = (addr) => {
|
|
40
|
+
try {
|
|
41
|
+
const address = CardanoWasm.Address.from_bech32(addr);
|
|
42
|
+
const baseAddress = CardanoWasm.BaseAddress.from_address(address);
|
|
43
|
+
if (!baseAddress)
|
|
44
|
+
return Promise.resolve(null);
|
|
45
|
+
const stakeCred = baseAddress.stake_cred();
|
|
46
|
+
if (stakeCred.kind() !== CardanoWasm.CredKind.Key) {
|
|
47
|
+
return Promise.resolve(null);
|
|
48
|
+
}
|
|
49
|
+
// spell-checker:disable-next-line
|
|
50
|
+
const stakeKey = stakeCred.to_keyhash();
|
|
51
|
+
if (!stakeKey)
|
|
52
|
+
return Promise.resolve(null);
|
|
53
|
+
return Promise.resolve(stakeKey.to_hex());
|
|
54
|
+
}
|
|
55
|
+
catch (_a) {
|
|
56
|
+
return Promise.resolve(null);
|
|
57
|
+
}
|
|
58
|
+
};
|