jcc_wallet 3.0.1 → 4.0.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/dist/jcc-wallet.min.js +57 -0
- package/lib/constant.d.ts +8 -0
- package/lib/constant.js +18 -0
- package/lib/constant.js.map +1 -0
- package/lib/hd/constant.d.ts +26 -0
- package/lib/hd/constant.js +56 -0
- package/lib/hd/constant.js.map +1 -0
- package/lib/hd/eos.plugin.d.ts +5 -0
- package/lib/hd/eos.plugin.js +70 -0
- package/lib/hd/eos.plugin.js.map +1 -0
- package/lib/hd/ethereum.plugin.d.ts +6 -0
- package/lib/hd/ethereum.plugin.js +120 -0
- package/lib/hd/ethereum.plugin.js.map +1 -0
- package/lib/hd/index.d.ts +228 -0
- package/lib/hd/index.js +382 -0
- package/lib/hd/index.js.map +1 -0
- package/lib/hd/plugins.d.ts +11 -0
- package/lib/hd/plugins.js +39 -0
- package/lib/hd/plugins.js.map +1 -0
- package/lib/hd/swtc.plugin.d.ts +2 -0
- package/lib/hd/swtc.plugin.js +86 -0
- package/lib/hd/swtc.plugin.js.map +1 -0
- package/lib/hd/tron.plugin.d.ts +5 -0
- package/lib/hd/tron.plugin.js +62 -0
- package/lib/hd/tron.plugin.js.map +1 -0
- package/lib/index.d.ts +25 -0
- package/lib/index.js +60 -0
- package/lib/index.js.map +1 -0
- package/lib/jingchangWallet.d.ts +273 -0
- package/lib/jingchangWallet.js +531 -0
- package/lib/jingchangWallet.js.map +1 -0
- package/lib/minify-ethereumjs-util/account.d.ts +1 -0
- package/lib/minify-ethereumjs-util/account.js +22 -0
- package/lib/minify-ethereumjs-util/account.js.map +1 -0
- package/lib/minify-ethereumjs-util/bytes.d.ts +7 -0
- package/lib/minify-ethereumjs-util/bytes.js +100 -0
- package/lib/minify-ethereumjs-util/bytes.js.map +1 -0
- package/lib/minify-ethereumjs-util/constants.d.ts +4 -0
- package/lib/minify-ethereumjs-util/constants.js +9 -0
- package/lib/minify-ethereumjs-util/constants.js.map +1 -0
- package/lib/minify-ethereumjs-util/helper.d.ts +5 -0
- package/lib/minify-ethereumjs-util/helper.js +16 -0
- package/lib/minify-ethereumjs-util/helper.js.map +1 -0
- package/lib/minify-ethereumjs-util/internal.d.ts +8 -0
- package/lib/minify-ethereumjs-util/internal.js +33 -0
- package/lib/minify-ethereumjs-util/internal.js.map +1 -0
- package/lib/minify-ethereumjs-util/signature.d.ts +13 -0
- package/lib/minify-ethereumjs-util/signature.js +45 -0
- package/lib/minify-ethereumjs-util/signature.js.map +1 -0
- package/lib/minify-swtc-keypair/address-codec.d.ts +16 -0
- package/lib/minify-swtc-keypair/address-codec.js +166 -0
- package/lib/minify-swtc-keypair/address-codec.js.map +1 -0
- package/lib/minify-swtc-keypair/index.d.ts +25 -0
- package/lib/minify-swtc-keypair/index.js +178 -0
- package/lib/minify-swtc-keypair/index.js.map +1 -0
- package/lib/minify-swtc-keypair/sha512.d.ts +9 -0
- package/lib/minify-swtc-keypair/sha512.js +33 -0
- package/lib/minify-swtc-keypair/sha512.js.map +1 -0
- package/lib/minify-swtc-keypair/utils.d.ts +13 -0
- package/lib/minify-swtc-keypair/utils.js +63 -0
- package/lib/minify-swtc-keypair/utils.js.map +1 -0
- package/lib/minify-tron/address.d.ts +6 -0
- package/lib/minify-tron/address.js +11 -0
- package/lib/minify-tron/address.js.map +1 -0
- package/lib/minify-tron/base58.d.ts +2 -0
- package/lib/minify-tron/base58.js +67 -0
- package/lib/minify-tron/base58.js.map +1 -0
- package/lib/minify-tron/bytes.d.ts +2 -0
- package/lib/minify-tron/bytes.js +23 -0
- package/lib/minify-tron/bytes.js.map +1 -0
- package/lib/minify-tron/code.d.ts +3 -0
- package/lib/minify-tron/code.js +56 -0
- package/lib/minify-tron/code.js.map +1 -0
- package/lib/minify-tron/crypto.d.ts +7 -0
- package/lib/minify-tron/crypto.js +83 -0
- package/lib/minify-tron/crypto.js.map +1 -0
- package/lib/minify-tron/message.d.ts +4 -0
- package/lib/minify-tron/message.js +42 -0
- package/lib/minify-tron/message.js.map +1 -0
- package/lib/types.d.ts +103 -0
- package/lib/types.js +16 -0
- package/lib/types.js.map +1 -0
- package/lib/util/index.d.ts +22 -0
- package/lib/util/index.js +100 -0
- package/lib/util/index.js.map +1 -0
- package/package.json +22 -17
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// forked from https://github.com/tronprotocol/tronweb/blob/5.x/src/utils/message.js
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TRON_MESSAGE_PREFIX = void 0;
|
|
5
|
+
exports.hashMessage = hashMessage;
|
|
6
|
+
exports.signMessage = signMessage;
|
|
7
|
+
exports.verifyMessage = verifyMessage;
|
|
8
|
+
const address_1 = require("./address");
|
|
9
|
+
const crypto_1 = require("./crypto");
|
|
10
|
+
const code_1 = require("./code");
|
|
11
|
+
const { keccak256, SigningKey, Signature } = require("ethers/crypto");
|
|
12
|
+
const { recoverAddress } = require("ethers/transaction");
|
|
13
|
+
const { toUtf8Bytes, concat } = require("ethers/utils");
|
|
14
|
+
const joinSignature = (splitSig) => Signature.from(splitSig).serialized;
|
|
15
|
+
exports.TRON_MESSAGE_PREFIX = "\x19TRON Signed Message:\n";
|
|
16
|
+
function hashMessage(message) {
|
|
17
|
+
if (typeof message === "string") {
|
|
18
|
+
message = toUtf8Bytes(message);
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(message)) {
|
|
21
|
+
message = new Uint8Array(message);
|
|
22
|
+
}
|
|
23
|
+
return keccak256(concat([toUtf8Bytes(exports.TRON_MESSAGE_PREFIX), toUtf8Bytes(String(message.length)), message]));
|
|
24
|
+
}
|
|
25
|
+
function signMessage(message, privateKey) {
|
|
26
|
+
if (!privateKey.match(/^0x/)) {
|
|
27
|
+
privateKey = "0x" + privateKey;
|
|
28
|
+
}
|
|
29
|
+
const signingKey = new SigningKey(privateKey);
|
|
30
|
+
const messageDigest = hashMessage(message);
|
|
31
|
+
const signature = signingKey.sign(messageDigest);
|
|
32
|
+
return joinSignature(signature);
|
|
33
|
+
}
|
|
34
|
+
function verifyMessage(message, signature) {
|
|
35
|
+
if (!signature.match(/^0x/)) {
|
|
36
|
+
signature = "0x" + signature;
|
|
37
|
+
}
|
|
38
|
+
const recovered = recoverAddress(hashMessage(message), signature);
|
|
39
|
+
const base58Address = (0, crypto_1.getBase58CheckAddress)((0, code_1.hexStr2byteArray)(recovered.replace(/^0x/, address_1.ADDRESS_PREFIX)));
|
|
40
|
+
return base58Address;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/minify-tron/message.ts"],"names":[],"mappings":";AAAA,oFAAoF;;;AAapF,kCAUC;AAED,kCAUC;AAED,sCAQC;AA3CD,uCAA2C;AAC3C,qCAAiD;AACjD,iCAA0C;AAC1C,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AACtE,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACzD,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAExD,MAAM,aAAa,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC;AAE3D,QAAA,mBAAmB,GAAG,4BAA4B,CAAC;AAEhE,SAAgB,WAAW,CAAC,OAAO;IACjC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC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: string;
|
|
10
|
+
iv: string;
|
|
11
|
+
kdf: string;
|
|
12
|
+
kdfparams: IKdfparamsModel;
|
|
13
|
+
}
|
|
14
|
+
export interface IKeystoreModel {
|
|
15
|
+
address?: string;
|
|
16
|
+
alias?: string;
|
|
17
|
+
ciphertext: string;
|
|
18
|
+
default?: boolean;
|
|
19
|
+
mac: string;
|
|
20
|
+
type?: string;
|
|
21
|
+
crypto: ICryptoModel;
|
|
22
|
+
}
|
|
23
|
+
export interface IJingchangWalletModel {
|
|
24
|
+
id?: string;
|
|
25
|
+
version?: string;
|
|
26
|
+
contact?: any;
|
|
27
|
+
wallets?: Array<IKeystoreModel>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* wallet model
|
|
31
|
+
*
|
|
32
|
+
* @export
|
|
33
|
+
* @interface IWalletModel
|
|
34
|
+
* @member address
|
|
35
|
+
* @member secret
|
|
36
|
+
*/
|
|
37
|
+
export interface IWalletModel {
|
|
38
|
+
address: string;
|
|
39
|
+
secret: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ICreateOptionsModel {
|
|
42
|
+
algorithm?: "ed25519" | "secp256k1";
|
|
43
|
+
entropy?: Uint8Array;
|
|
44
|
+
}
|
|
45
|
+
export interface IEncryptModel {
|
|
46
|
+
cipher?: string;
|
|
47
|
+
dklen?: number;
|
|
48
|
+
iv?: string;
|
|
49
|
+
n?: number;
|
|
50
|
+
p?: number;
|
|
51
|
+
r?: number;
|
|
52
|
+
salt?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface IKeypairsModel {
|
|
55
|
+
secret: string;
|
|
56
|
+
default?: boolean;
|
|
57
|
+
type?: string;
|
|
58
|
+
address: string;
|
|
59
|
+
alias?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface IKeyPair {
|
|
62
|
+
privateKey: string;
|
|
63
|
+
publicKey: string;
|
|
64
|
+
}
|
|
65
|
+
export interface IEncrypt {
|
|
66
|
+
iv: string;
|
|
67
|
+
ephemPublicKey: string;
|
|
68
|
+
ciphertext: string;
|
|
69
|
+
mac: string;
|
|
70
|
+
}
|
|
71
|
+
export interface IMnemonic {
|
|
72
|
+
mnemonic: string;
|
|
73
|
+
language: string;
|
|
74
|
+
}
|
|
75
|
+
export interface IBIP44Path {
|
|
76
|
+
chain: number;
|
|
77
|
+
account: number;
|
|
78
|
+
change: number;
|
|
79
|
+
index: number;
|
|
80
|
+
}
|
|
81
|
+
export interface IHDPlugin {
|
|
82
|
+
address(key: IKeyPair | string, ...args: any[]): string;
|
|
83
|
+
isValidAddress(...args: any[]): boolean;
|
|
84
|
+
isValidSecret(...args: any[]): boolean;
|
|
85
|
+
hash(message: string, ...args: any[]): string;
|
|
86
|
+
sign(message: string, ...args: any[]): string;
|
|
87
|
+
verify(messgae: string, signature: string, address: string, ...args: any[]): boolean;
|
|
88
|
+
recover(message: string, signature: string, ...args: any[]): string | void;
|
|
89
|
+
getAddress?(secret: string): string;
|
|
90
|
+
createWallet?(opts?: ICreateOptionsModel): IWalletModel;
|
|
91
|
+
proxy?(functionName: string, ...args: any[]): any;
|
|
92
|
+
}
|
|
93
|
+
export declare enum Alphabet {
|
|
94
|
+
JINGTUM = "jpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65rkm8oFqi1tuvAxyz",
|
|
95
|
+
SWT = "jpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65rkm8oFqi1tuvAxyz",
|
|
96
|
+
RIPPLE = "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",
|
|
97
|
+
CALL = "cpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2brdeCg65jkm8oFqi1tuvAxyz",
|
|
98
|
+
STREAM = "vpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1turAxyz",
|
|
99
|
+
BVCADT = "bpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2rcdeCg65jkm8oFqi1tuvAxyz",
|
|
100
|
+
BIZAIN = "bpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2jcdeCg65rkm8oFqi1tuvAxyz",
|
|
101
|
+
XRP = "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",
|
|
102
|
+
SWTC = "jpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65rkm8oFqi1tuvAxyz"
|
|
103
|
+
}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Alphabet = void 0;
|
|
4
|
+
var Alphabet;
|
|
5
|
+
(function (Alphabet) {
|
|
6
|
+
Alphabet["JINGTUM"] = "jpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65rkm8oFqi1tuvAxyz";
|
|
7
|
+
Alphabet["SWT"] = "jpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65rkm8oFqi1tuvAxyz";
|
|
8
|
+
Alphabet["RIPPLE"] = "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz";
|
|
9
|
+
Alphabet["CALL"] = "cpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2brdeCg65jkm8oFqi1tuvAxyz";
|
|
10
|
+
Alphabet["STREAM"] = "vpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1turAxyz";
|
|
11
|
+
Alphabet["BVCADT"] = "bpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2rcdeCg65jkm8oFqi1tuvAxyz";
|
|
12
|
+
Alphabet["BIZAIN"] = "bpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2jcdeCg65rkm8oFqi1tuvAxyz";
|
|
13
|
+
Alphabet["XRP"] = "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz";
|
|
14
|
+
Alphabet["SWTC"] = "jpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65rkm8oFqi1tuvAxyz";
|
|
15
|
+
})(Alphabet || (exports.Alphabet = Alphabet = {}));
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAwGA,IAAY,QAUX;AAVD,WAAY,QAAQ;IAClB,kFAAsE,CAAA;IACtE,8EAAkE,CAAA;IAClE,iFAAqE,CAAA;IACrE,+EAAmE,CAAA;IACnE,iFAAqE,CAAA;IACrE,iFAAqE,CAAA;IACrE,iFAAqE,CAAA;IACrE,8EAAkE,CAAA;IAClE,+EAAmE,CAAA;AACrE,CAAC,EAVW,QAAQ,wBAAR,QAAQ,QAUnB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IEncryptModel, IKeystoreModel, IKeypairsModel } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* decrypt wallet with password
|
|
4
|
+
*
|
|
5
|
+
* @param {string} password
|
|
6
|
+
* @param {IKeystoreModel} encryptData
|
|
7
|
+
* @returns {(string)} return secret if success, otherwise throws `keystore is invalid` if the keystore is invalid or
|
|
8
|
+
* throws `password is wrong` if the password is wrong
|
|
9
|
+
*/
|
|
10
|
+
declare const decrypt: (password: string, encryptData: IKeystoreModel) => string;
|
|
11
|
+
/**
|
|
12
|
+
* encrypt data with password
|
|
13
|
+
*
|
|
14
|
+
* @param {string} password
|
|
15
|
+
* @param {string} data
|
|
16
|
+
* @param {IEncryptModel} [opts={}]
|
|
17
|
+
* @returns {IKeystoreModel}
|
|
18
|
+
*/
|
|
19
|
+
declare const encrypt: (password: string, data: string, opts: IEncryptModel) => IKeystoreModel;
|
|
20
|
+
declare const encryptContact: (password: string, contacts: any, opts?: IEncryptModel) => IKeystoreModel;
|
|
21
|
+
declare const encryptWallet: (password: string, keypairs: IKeypairsModel, opts?: IEncryptModel) => IKeystoreModel;
|
|
22
|
+
export { decrypt, encrypt, encryptContact, encryptWallet };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.encryptWallet = exports.encryptContact = exports.encrypt = exports.decrypt = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const jcc_common_1 = require("jcc_common");
|
|
9
|
+
const keccak_js_1 = require("ethereum-cryptography/keccak.js");
|
|
10
|
+
const randombytes_1 = __importDefault(require("randombytes"));
|
|
11
|
+
const scrypt_1 = require("@noble/hashes/scrypt");
|
|
12
|
+
const constant_1 = require("../constant");
|
|
13
|
+
/**
|
|
14
|
+
* decrypt wallet with password
|
|
15
|
+
*
|
|
16
|
+
* @param {string} password
|
|
17
|
+
* @param {IKeystoreModel} encryptData
|
|
18
|
+
* @returns {(string)} return secret if success, otherwise throws `keystore is invalid` if the keystore is invalid or
|
|
19
|
+
* throws `password is wrong` if the password is wrong
|
|
20
|
+
*/
|
|
21
|
+
const decrypt = (password, encryptData) => {
|
|
22
|
+
if ((0, jcc_common_1.isEmptyObject)(encryptData) || (0, jcc_common_1.isEmptyObject)(encryptData.crypto) || (0, jcc_common_1.isEmptyObject)(encryptData.crypto.kdfparams)) {
|
|
23
|
+
throw new Error(constant_1.KEYSTORE_IS_INVALID);
|
|
24
|
+
}
|
|
25
|
+
const iv = Buffer.from(encryptData.crypto.iv, "hex");
|
|
26
|
+
const kdfparams = encryptData.crypto.kdfparams;
|
|
27
|
+
const derivedKey = (0, scrypt_1.scrypt)(Buffer.from(password), Buffer.from(kdfparams.salt, "hex"), {
|
|
28
|
+
N: kdfparams.n,
|
|
29
|
+
r: kdfparams.r,
|
|
30
|
+
p: kdfparams.p,
|
|
31
|
+
dkLen: kdfparams.dklen
|
|
32
|
+
});
|
|
33
|
+
const ciphertext = Buffer.from(encryptData.ciphertext, "hex");
|
|
34
|
+
const mac = keccak_js_1.keccak256
|
|
35
|
+
.create()
|
|
36
|
+
.update(Buffer.concat([derivedKey.slice(16, 32), ciphertext]))
|
|
37
|
+
.digest();
|
|
38
|
+
if (Buffer.from(mac).toString("hex") !== encryptData.mac) {
|
|
39
|
+
throw new Error(constant_1.PASSWORD_IS_WRONG);
|
|
40
|
+
}
|
|
41
|
+
const decipher = crypto_1.default.createDecipheriv("aes-128-ctr", derivedKey.slice(0, 16), iv);
|
|
42
|
+
const seed = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
43
|
+
return seed.toString();
|
|
44
|
+
};
|
|
45
|
+
exports.decrypt = decrypt;
|
|
46
|
+
/**
|
|
47
|
+
* encrypt data with password
|
|
48
|
+
*
|
|
49
|
+
* @param {string} password
|
|
50
|
+
* @param {string} data
|
|
51
|
+
* @param {IEncryptModel} [opts={}]
|
|
52
|
+
* @returns {IKeystoreModel}
|
|
53
|
+
*/
|
|
54
|
+
const encrypt = (password, data, opts) => {
|
|
55
|
+
const iv = opts.iv || (0, randombytes_1.default)(16).toString("hex");
|
|
56
|
+
const kdfparams = {
|
|
57
|
+
dklen: opts.dklen || 32,
|
|
58
|
+
n: opts.n || 4096,
|
|
59
|
+
p: opts.p || 1,
|
|
60
|
+
r: opts.r || 8,
|
|
61
|
+
salt: opts.salt || (0, randombytes_1.default)(32).toString("hex")
|
|
62
|
+
};
|
|
63
|
+
const derivedKey = (0, scrypt_1.scrypt)(Buffer.from(password), Buffer.from(kdfparams.salt, "hex"), {
|
|
64
|
+
N: kdfparams.n,
|
|
65
|
+
r: kdfparams.r,
|
|
66
|
+
p: kdfparams.p,
|
|
67
|
+
dkLen: kdfparams.dklen
|
|
68
|
+
});
|
|
69
|
+
const cipher = crypto_1.default.createCipheriv(opts.cipher || "aes-128-ctr", derivedKey.slice(0, 16), Buffer.from(iv, "hex"));
|
|
70
|
+
const ciphertext = Buffer.concat([cipher.update(Buffer.from(data)), cipher.final()]);
|
|
71
|
+
const mac = keccak_js_1.keccak256
|
|
72
|
+
.create()
|
|
73
|
+
.update(Buffer.concat([derivedKey.slice(16, 32), ciphertext]))
|
|
74
|
+
.digest();
|
|
75
|
+
return {
|
|
76
|
+
ciphertext: ciphertext.toString("hex"),
|
|
77
|
+
crypto: {
|
|
78
|
+
cipher: opts.cipher || "aes-128-ctr",
|
|
79
|
+
iv,
|
|
80
|
+
kdf: "scrypt",
|
|
81
|
+
kdfparams
|
|
82
|
+
},
|
|
83
|
+
mac: Buffer.from(mac).toString("hex")
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
exports.encrypt = encrypt;
|
|
87
|
+
const encryptContact = (password, contacts, opts = {}) => {
|
|
88
|
+
return encrypt(password, JSON.stringify(contacts), opts);
|
|
89
|
+
};
|
|
90
|
+
exports.encryptContact = encryptContact;
|
|
91
|
+
const encryptWallet = (password, keypairs, opts = {}) => {
|
|
92
|
+
const data = encrypt(password, keypairs.secret, opts);
|
|
93
|
+
data.type = keypairs.type || "swt";
|
|
94
|
+
data.address = keypairs.address;
|
|
95
|
+
data.default = typeof keypairs.default === "boolean" ? keypairs.default : true;
|
|
96
|
+
data.alias = keypairs.alias || "";
|
|
97
|
+
return data;
|
|
98
|
+
};
|
|
99
|
+
exports.encryptWallet = encryptWallet;
|
|
100
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,2CAA2C;AAC3C,+DAA4D;AAE5D,8DAAsC;AACtC,iDAA8C;AAC9C,0CAAqE;AAGrE;;;;;;;GAOG;AACH,MAAM,OAAO,GAAG,CAAC,QAAgB,EAAE,WAA2B,EAAU,EAAE;IACxE,I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AK,CAAC;IACnC,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IAChC,IAAI,CAAC,OAAO,GAAG,OAAO,QAAQ,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/E,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC;IAClC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEyC,sCAAa"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jcc_wallet",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Toolkit of wallet to manage multiple chains & support multiple keystores for each chain",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
"test:node": "npm run build && nyc --extension=.ts --reporter=lcov --reporter=html --reporter=text mocha --timeout=6000 test/*.spec.js",
|
|
19
19
|
"test:browser": "npm run build && karma start karma.conf.js",
|
|
20
20
|
"eslint": "./node_modules/.bin/eslint src",
|
|
21
|
-
"compile": "
|
|
22
|
-
"pretty": "pretty-quick --staged"
|
|
21
|
+
"compile": "./compile.sh",
|
|
22
|
+
"pretty": "pretty-quick --staged",
|
|
23
|
+
"analyzer": "cross-env REPORT=true webpack"
|
|
23
24
|
},
|
|
24
25
|
"repository": {
|
|
25
26
|
"type": "git",
|
|
@@ -50,17 +51,18 @@
|
|
|
50
51
|
"@babel/preset-env": "^7.23.2",
|
|
51
52
|
"@babel/preset-typescript": "^7.22.15",
|
|
52
53
|
"@types/eslint": "^8",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
54
|
-
"@typescript-eslint/parser": "^
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^7.12.0",
|
|
55
|
+
"@typescript-eslint/parser": "^7.12.0",
|
|
55
56
|
"babel-loader": "^8.3.0",
|
|
56
57
|
"browserify": "^16.5.0",
|
|
57
58
|
"chai": "^4.2.0",
|
|
58
59
|
"coveralls": "^3.1.1",
|
|
59
60
|
"cross-env": "^7.0.0",
|
|
60
61
|
"duplicate-package-checker-webpack-plugin": "^3.0.0",
|
|
61
|
-
"eslint": "^
|
|
62
|
+
"eslint": "^9.4.0",
|
|
62
63
|
"eslint-plugin-jsdoc": "^46.9.0",
|
|
63
64
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
65
|
+
"globals": "^15.8.0",
|
|
64
66
|
"husky": "^7.0.4",
|
|
65
67
|
"jsdom": "^22.1.0",
|
|
66
68
|
"karma": "^6.4.2",
|
|
@@ -78,32 +80,35 @@
|
|
|
78
80
|
"sinon": "^17.0.1",
|
|
79
81
|
"ts-loader": "^6.2.1",
|
|
80
82
|
"typescript": "^5.2.2",
|
|
83
|
+
"typescript-eslint": "^7.16.0",
|
|
81
84
|
"webpack": "^5.89.0",
|
|
82
85
|
"webpack-bundle-analyzer": "^4.10.1",
|
|
83
86
|
"webpack-cli": "^5.1.4"
|
|
84
87
|
},
|
|
88
|
+
"resolutions": {
|
|
89
|
+
"@noble/curves": "^1.4.2",
|
|
90
|
+
"@noble/hashes": "^1.4.0",
|
|
91
|
+
"randombytes": "^2.1.0",
|
|
92
|
+
"create-hmac": "^1.1.7",
|
|
93
|
+
"create-hash": "^1.2.0",
|
|
94
|
+
"browserify-aes": "^1.2.0",
|
|
95
|
+
"elliptic": "^6.5.5",
|
|
96
|
+
"buffer": "^6.0.3"
|
|
97
|
+
},
|
|
85
98
|
"dependencies": {
|
|
86
|
-
"@
|
|
87
|
-
"@ethereumjs/wallet": "^2.0.0",
|
|
88
|
-
"@swtc/wallet": "^1.1.1",
|
|
99
|
+
"@scure/bip32": "^1.4.0",
|
|
89
100
|
"@types/node": "^16.11.6",
|
|
90
|
-
"bip32": "^4.0.0",
|
|
91
101
|
"bip39": "^3.0.4",
|
|
92
102
|
"bip44-constants": "^123.0.0",
|
|
93
103
|
"bn.js": "^5.2.1",
|
|
94
104
|
"clone-deep": "^4.0.1",
|
|
95
105
|
"eccrypto": "^1.1.6",
|
|
96
|
-
"elliptic": "^6.5.4",
|
|
97
|
-
"eosjs": "^22.1.0",
|
|
98
106
|
"eosjs-ecc": "^4.0.1",
|
|
107
|
+
"ethereum-cryptography": "^2.2.1",
|
|
108
|
+
"ethers": "^6.13.1",
|
|
99
109
|
"jcc_common": "^0.1.0",
|
|
100
|
-
"keccak": "^3.0.3",
|
|
101
110
|
"lockr": "^0.8.5",
|
|
102
111
|
"node-polyfill-webpack-plugin": "^2.0.1",
|
|
103
|
-
"scryptsy": "^2.1.0",
|
|
104
|
-
"secp256k1": "^5.0.0",
|
|
105
|
-
"tiny-secp256k1": "^1.1.6",
|
|
106
|
-
"tronweb": "^5.3.1",
|
|
107
112
|
"wif": "^4.0.0"
|
|
108
113
|
},
|
|
109
114
|
"nyc": {
|