@com-chain/jsc3l 2.0.1-rc.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/LICENSE +661 -0
- package/README.md +45 -0
- package/build/bcRead.d.ts +15 -0
- package/build/bcRead.js +123 -0
- package/build/bcRead.js.map +1 -0
- package/build/bcTransaction.d.ts +10 -0
- package/build/bcTransaction.js +135 -0
- package/build/bcTransaction.js.map +1 -0
- package/build/blockies.d.ts +1 -0
- package/build/blockies.js +91 -0
- package/build/blockies.js.map +1 -0
- package/build/config.d.ts +6 -0
- package/build/config.js +25 -0
- package/build/config.js.map +1 -0
- package/build/connection.d.ts +58 -0
- package/build/connection.js +204 -0
- package/build/connection.js.map +1 -0
- package/build/customization.d.ts +37 -0
- package/build/customization.js +129 -0
- package/build/customization.js.map +1 -0
- package/build/ethereum/cipher.d.ts +3 -0
- package/build/ethereum/cipher.js +94 -0
- package/build/ethereum/cipher.js.map +1 -0
- package/build/ethereum/ethFuncs.d.ts +12 -0
- package/build/ethereum/ethFuncs.js +70 -0
- package/build/ethereum/ethFuncs.js.map +1 -0
- package/build/ethereum/etherUnits.d.ts +5 -0
- package/build/ethereum/etherUnits.js +60 -0
- package/build/ethereum/etherUnits.js.map +1 -0
- package/build/ethereum/myetherwallet.d.ts +47 -0
- package/build/ethereum/myetherwallet.js +294 -0
- package/build/ethereum/myetherwallet.js.map +1 -0
- package/build/ethereum/uiFuncs.d.ts +3 -0
- package/build/ethereum/uiFuncs.js +51 -0
- package/build/ethereum/uiFuncs.js.map +1 -0
- package/build/index.d.ts +111 -0
- package/build/index.js +310 -0
- package/build/index.js.map +1 -0
- package/build/memo.d.ts +6 -0
- package/build/memo.js +24 -0
- package/build/memo.js.map +1 -0
- package/build/qr.d.ts +8 -0
- package/build/qr.js +35 -0
- package/build/qr.js.map +1 -0
- package/build/rest/ajaxReq.d.ts +31 -0
- package/build/rest/ajaxReq.js +127 -0
- package/build/rest/ajaxReq.js.map +1 -0
- package/build/rest/endpoint.d.ts +18 -0
- package/build/rest/endpoint.js +26 -0
- package/build/rest/endpoint.js.map +1 -0
- package/build/rest/http.d.ts +10 -0
- package/build/rest/http.js +60 -0
- package/build/rest/http.js.map +1 -0
- package/build/rest/serializer.d.ts +1 -0
- package/build/rest/serializer.js +94 -0
- package/build/rest/serializer.js.map +1 -0
- package/build/type.d.ts +24 -0
- package/build/type.js +9 -0
- package/build/type.js.map +1 -0
- package/build/wallet.d.ts +35 -0
- package/build/wallet.js +162 -0
- package/build/wallet.js.map +1 -0
- package/package.json +41 -0
- package/src/bcRead.ts +184 -0
- package/src/bcTransaction.ts +157 -0
- package/src/blockies.ts +113 -0
- package/src/config.ts +33 -0
- package/src/connection.ts +243 -0
- package/src/customization.ts +156 -0
- package/src/ethereum/cipher.ts +118 -0
- package/src/ethereum/ethFuncs.ts +73 -0
- package/src/ethereum/etherUnits.ts +66 -0
- package/src/ethereum/myetherwallet.ts +354 -0
- package/src/ethereum/uiFuncs.ts +55 -0
- package/src/index.ts +366 -0
- package/src/memo.ts +37 -0
- package/src/qr.ts +34 -0
- package/src/rest/ajaxReq.ts +160 -0
- package/src/rest/endpoint.ts +31 -0
- package/src/rest/http.ts +69 -0
- package/src/rest/serializer.ts +99 -0
- package/src/type.ts +37 -0
- package/src/wallet.ts +200 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
function getHostOrUrlParts(HostOrUrl) {
|
|
2
|
+
let protocol, host, port, path;
|
|
3
|
+
if (HostOrUrl.includes('://')) {
|
|
4
|
+
;
|
|
5
|
+
[protocol, HostOrUrl] = HostOrUrl.split('://');
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
protocol = 'https';
|
|
9
|
+
HostOrUrl = HostOrUrl.replace(/\/$/, '');
|
|
10
|
+
}
|
|
11
|
+
if (HostOrUrl.includes('/')) {
|
|
12
|
+
const splits = HostOrUrl.split('/');
|
|
13
|
+
[host, path] = [splits[0], '/' + splits.slice(1).join('/')];
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
// assume host only
|
|
17
|
+
path = '';
|
|
18
|
+
host = HostOrUrl;
|
|
19
|
+
}
|
|
20
|
+
if (host.includes(':')) {
|
|
21
|
+
const splits = host.split(':');
|
|
22
|
+
if (splits.length > 2) {
|
|
23
|
+
throw new Error(`Too many ':' to get host and port: ${host}`);
|
|
24
|
+
}
|
|
25
|
+
;
|
|
26
|
+
[host, port] = [splits[0], parseInt(splits[1])];
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (protocol === 'http') {
|
|
30
|
+
port = 80;
|
|
31
|
+
}
|
|
32
|
+
else if (protocol === 'https') {
|
|
33
|
+
port = 443;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw new Error(`Could not infer port from unknown protocol ${protocol}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
protocol,
|
|
41
|
+
host,
|
|
42
|
+
port,
|
|
43
|
+
path,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Support passing data to querystring when method is GET.
|
|
48
|
+
*/
|
|
49
|
+
export default class HttpAbstract {
|
|
50
|
+
async request(...[method, url, data, opts]) {
|
|
51
|
+
if (method === 'GET' && data && Object.keys(data).length > 0) {
|
|
52
|
+
url += '?' + (new URLSearchParams(data)).toString();
|
|
53
|
+
}
|
|
54
|
+
var coreOpts = Object.assign(Object.assign({ method, data: method === 'GET' ? null : data }, opts), getHostOrUrlParts(url));
|
|
55
|
+
return await this.httpRequest(coreOpts);
|
|
56
|
+
}
|
|
57
|
+
get(...args) { return this.request('GET', ...args); }
|
|
58
|
+
post(...args) { return this.request('POST', ...args); }
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/rest/http.ts"],"names":[],"mappings":"A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isWindow(obj) {
|
|
5
|
+
return obj && obj.window === obj;
|
|
6
|
+
}
|
|
7
|
+
function toJsonReplacer(key, value) {
|
|
8
|
+
let val = value;
|
|
9
|
+
if (typeof key === 'string' &&
|
|
10
|
+
key.charAt(0) === '$' &&
|
|
11
|
+
key.charAt(1) === '$') {
|
|
12
|
+
val = undefined;
|
|
13
|
+
}
|
|
14
|
+
else if (isWindow(value)) {
|
|
15
|
+
val = '$WINDOW';
|
|
16
|
+
}
|
|
17
|
+
else if (value && window.document === value) {
|
|
18
|
+
val = '$DOCUMENT';
|
|
19
|
+
}
|
|
20
|
+
else if (isScope(value)) {
|
|
21
|
+
val = '$SCOPE';
|
|
22
|
+
}
|
|
23
|
+
return val;
|
|
24
|
+
}
|
|
25
|
+
function isNumber(arg) {
|
|
26
|
+
return typeof arg === 'number';
|
|
27
|
+
}
|
|
28
|
+
function toJson(obj, pretty) {
|
|
29
|
+
if (isUndefined(obj)) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
if (!isNumber(pretty)) {
|
|
33
|
+
pretty = pretty ? 2 : null;
|
|
34
|
+
}
|
|
35
|
+
return JSON.stringify(obj, toJsonReplacer, pretty);
|
|
36
|
+
}
|
|
37
|
+
function isDate(value) {
|
|
38
|
+
return toString.call(value) === '[object Date]';
|
|
39
|
+
}
|
|
40
|
+
function isObject(value) {
|
|
41
|
+
return value !== null && typeof value === 'object';
|
|
42
|
+
}
|
|
43
|
+
function serializeValue(v) {
|
|
44
|
+
if (isObject(v)) {
|
|
45
|
+
return isDate(v) ? v.toISOString() : toJson(v);
|
|
46
|
+
}
|
|
47
|
+
return v;
|
|
48
|
+
}
|
|
49
|
+
function encodeUriQuery(val, pctEncodeSpaces) {
|
|
50
|
+
return encodeURIComponent(val)
|
|
51
|
+
.replace(/%40/gi, '@')
|
|
52
|
+
.replace(/%3A/gi, ':')
|
|
53
|
+
.replace(/%24/g, '$')
|
|
54
|
+
.replace(/%2C/gi, ',')
|
|
55
|
+
.replace(/%3B/gi, ';')
|
|
56
|
+
.replace(/%20/g, pctEncodeSpaces ? '%20' : '+');
|
|
57
|
+
}
|
|
58
|
+
function isUndefined(value) {
|
|
59
|
+
return typeof value === 'undefined';
|
|
60
|
+
}
|
|
61
|
+
function forEachSorted(obj, iterator, context) {
|
|
62
|
+
const keys = Object.keys(obj).sort();
|
|
63
|
+
for (let i = 0; i < keys.length; i++) {
|
|
64
|
+
iterator.call(context, obj[keys[i]], keys[i]);
|
|
65
|
+
}
|
|
66
|
+
return keys;
|
|
67
|
+
}
|
|
68
|
+
export default function postSerializer(params) {
|
|
69
|
+
if (!params)
|
|
70
|
+
return '';
|
|
71
|
+
const parts = [];
|
|
72
|
+
serialize(params, '', true);
|
|
73
|
+
return parts.join('&');
|
|
74
|
+
function serialize(toSerialize, prefix, topLevel) {
|
|
75
|
+
if (toSerialize === null || isUndefined(toSerialize)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (Array.isArray(toSerialize)) {
|
|
79
|
+
toSerialize.forEach(function (value, index) {
|
|
80
|
+
serialize(value, prefix + '[' + (isObject(value) ? index : '') + ']');
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
else if (isObject(toSerialize) && !isDate(toSerialize)) {
|
|
84
|
+
forEachSorted(toSerialize, function (value, key) {
|
|
85
|
+
serialize(value, prefix + (topLevel ? '' : '[') + key + (topLevel ? '' : ']'));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
parts.push(encodeUriQuery(prefix) + '=' +
|
|
90
|
+
encodeUriQuery(serializeValue(toSerialize)));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../src/rest/serializer.ts"],"names":[],"mappings":"AACA,SAAS,OAAO,CAAE,GAAG;IACnB,OAAO,GAAG,IAA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H,CAAC;AACH,CAAC"}
|
package/build/type.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const httpMethods: readonly ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"];
|
|
2
|
+
export declare type httpMethod = typeof httpMethods[number];
|
|
3
|
+
export declare type coreHttpOpts = {
|
|
4
|
+
protocol: string;
|
|
5
|
+
host: string;
|
|
6
|
+
path: string;
|
|
7
|
+
method: httpMethod;
|
|
8
|
+
headers?: {};
|
|
9
|
+
port?: number;
|
|
10
|
+
data?: any;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
};
|
|
13
|
+
export declare type HttpRequest = (opts: coreHttpOpts) => Object;
|
|
14
|
+
export interface IPersistentStore {
|
|
15
|
+
get(key: string, defaultValue?: string): string;
|
|
16
|
+
set(key: string, value: string): void;
|
|
17
|
+
del(key: string): void;
|
|
18
|
+
}
|
|
19
|
+
export declare type UrlParts = {
|
|
20
|
+
protocol: string;
|
|
21
|
+
host: string;
|
|
22
|
+
port: number;
|
|
23
|
+
path: string;
|
|
24
|
+
};
|
package/build/type.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK;IACL,MAAM;IACN,KAAK;IACL,QAAQ;IACR,OAAO;IACP,MAAM;CACE,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import AjaxReq from './rest/ajaxReq';
|
|
2
|
+
import Wallet from './ethereum/myetherwallet';
|
|
3
|
+
export default abstract class MessagingWalletAbstract extends Wallet {
|
|
4
|
+
abstract ajaxReq: AjaxReq;
|
|
5
|
+
abstract currencyName: string;
|
|
6
|
+
abstract unlockUrl: string;
|
|
7
|
+
message_key: null | {
|
|
8
|
+
pub: string;
|
|
9
|
+
priv: string;
|
|
10
|
+
};
|
|
11
|
+
static createWallet(this: {
|
|
12
|
+
new (): MessagingWalletAbstract;
|
|
13
|
+
}): Promise<"REPLACED_WITH_REMOTE" | "CREATED_NEW">;
|
|
14
|
+
private publishMessageKey;
|
|
15
|
+
publishReqMessages(addTo: any, message: any): Promise<any>;
|
|
16
|
+
ensureWalletMessageKey(): Promise<"REPLACED_WITH_REMOTE" | "CREATED_NEW">;
|
|
17
|
+
getReqMessage(otherAdd: any, myMessageKey: any, didISentThisMsg: any): Promise<string>;
|
|
18
|
+
private newMessageKey;
|
|
19
|
+
messageKeysFromCrypted(cipheredKey: any): any;
|
|
20
|
+
messageKeysFromWallet(): any;
|
|
21
|
+
encryptWallet(password: any): {
|
|
22
|
+
[k: string]: any;
|
|
23
|
+
};
|
|
24
|
+
enrollAddress(codeId: any, token: any): any;
|
|
25
|
+
requestUnlock(): any;
|
|
26
|
+
static getWalletFromPrivKeyFile(jsonStr: any, password: any): Wallet;
|
|
27
|
+
makeSignedQRWithPubKey(objContent: any, pubKey: any): {
|
|
28
|
+
signature: any;
|
|
29
|
+
qrContent: string;
|
|
30
|
+
};
|
|
31
|
+
makeSignedQR(obj: any): {
|
|
32
|
+
signature: any;
|
|
33
|
+
qrContent: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
package/build/wallet.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import ethUtil from 'ethereumjs-util';
|
|
2
|
+
import { shortenAddress, cipherMsg, decipherMsg } from './ethereum/cipher';
|
|
3
|
+
import Wallet from './ethereum/myetherwallet';
|
|
4
|
+
export default class MessagingWalletAbstract extends Wallet {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.message_key = null;
|
|
8
|
+
}
|
|
9
|
+
static async createWallet() {
|
|
10
|
+
const wallet = new this();
|
|
11
|
+
return wallet.ensureWalletMessageKey();
|
|
12
|
+
}
|
|
13
|
+
publishMessageKey() {
|
|
14
|
+
const dataStr = JSON.stringify({
|
|
15
|
+
address: this.getAddressString(),
|
|
16
|
+
public_message_key: this.message_key.pub,
|
|
17
|
+
private_message_key: this.message_key.priv,
|
|
18
|
+
});
|
|
19
|
+
return this.ajaxReq.publishMessageKey(dataStr, this.signMessage(dataStr));
|
|
20
|
+
}
|
|
21
|
+
async publishReqMessages(addTo, message) {
|
|
22
|
+
const addFrom = this.getAddressString();
|
|
23
|
+
const pubKey = async (add) => (await this.ajaxReq.getMessageKey(add, false)).public_message_key;
|
|
24
|
+
const fromMsgKey = await pubKey(addFrom);
|
|
25
|
+
const toMsgKey = await pubKey(addTo);
|
|
26
|
+
const dataStr = JSON.stringify({
|
|
27
|
+
add_req: addFrom,
|
|
28
|
+
add_cli: addTo,
|
|
29
|
+
ref_req: fromMsgKey ? cipherMsg(fromMsgKey, message) : '',
|
|
30
|
+
ref_cli: toMsgKey ? cipherMsg(toMsgKey, message) : '',
|
|
31
|
+
});
|
|
32
|
+
return this.ajaxReq.publishReqMessages(dataStr, this.signMessage(dataStr));
|
|
33
|
+
}
|
|
34
|
+
async ensureWalletMessageKey() {
|
|
35
|
+
const remoteKey = await this.ajaxReq.getMessageKey(this.getAddressString(), true);
|
|
36
|
+
const walletMessageKey = this === null || this === void 0 ? void 0 : this.message_key;
|
|
37
|
+
if (remoteKey.public_message_key !== undefined) {
|
|
38
|
+
this.message_key = {
|
|
39
|
+
pub: remoteKey.public_message_key,
|
|
40
|
+
priv: remoteKey.private_message_key,
|
|
41
|
+
};
|
|
42
|
+
if ((walletMessageKey === null || walletMessageKey === void 0 ? void 0 : walletMessageKey.pub) !== remoteKey.public_message_key) {
|
|
43
|
+
return 'REPLACED_WITH_REMOTE';
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!(walletMessageKey === null || walletMessageKey === void 0 ? void 0 : walletMessageKey.pub) || !(walletMessageKey === null || walletMessageKey === void 0 ? void 0 : walletMessageKey.priv)) {
|
|
48
|
+
this.message_key = this.newMessageKey();
|
|
49
|
+
this.publishMessageKey();
|
|
50
|
+
return 'CREATED_NEW';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async getReqMessage(otherAdd, myMessageKey, didISentThisMsg) {
|
|
54
|
+
const myAdd = this.getAddressString();
|
|
55
|
+
const addFrom = didISentThisMsg ? myAdd : otherAdd;
|
|
56
|
+
const addTo = !didISentThisMsg ? myAdd : otherAdd;
|
|
57
|
+
const data = await this.ajaxReq.getReqMessages(addFrom, addTo);
|
|
58
|
+
if (!data)
|
|
59
|
+
return '';
|
|
60
|
+
let crypted = '';
|
|
61
|
+
if (didISentThisMsg && data.ref_from) {
|
|
62
|
+
crypted = data.ref_from;
|
|
63
|
+
}
|
|
64
|
+
else if (!didISentThisMsg && data.ref_to) {
|
|
65
|
+
crypted = data.ref_to;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return '';
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
return decipherMsg(myMessageKey, crypted);
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
return '';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
newMessageKey() {
|
|
78
|
+
const newKey = Wallet.generate(false);
|
|
79
|
+
const mPub = newKey.getPublicKeyString();
|
|
80
|
+
const mPriv = newKey.getPrivateKeyString();
|
|
81
|
+
return { pub: mPub, priv: cipherMsg(this.getPublicKey(), mPriv) };
|
|
82
|
+
}
|
|
83
|
+
messageKeysFromCrypted(cipheredKey) {
|
|
84
|
+
// XXXvlab: here we are converting to hex and de-converting in decipherMsg...
|
|
85
|
+
return shortenAddress(decipherMsg(this.getPrivateKeyString(), cipheredKey));
|
|
86
|
+
}
|
|
87
|
+
messageKeysFromWallet() {
|
|
88
|
+
return this.messageKeysFromCrypted(this.message_key.priv);
|
|
89
|
+
}
|
|
90
|
+
//
|
|
91
|
+
// Using currencyName
|
|
92
|
+
//
|
|
93
|
+
encryptWallet(password) {
|
|
94
|
+
return this.toV3(password, {
|
|
95
|
+
kdf: 'scrypt',
|
|
96
|
+
n: 1024,
|
|
97
|
+
server_name: this.currencyName,
|
|
98
|
+
message_key: this.message_key
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
enrollAddress(codeId, token) {
|
|
102
|
+
return this.ajaxReq.enrollAddress(codeId, this.getAddressString(), this.currencyName, token);
|
|
103
|
+
}
|
|
104
|
+
requestUnlock() {
|
|
105
|
+
return this.ajaxReq.requestUnlock(this.getAddressString(), this.unlockUrl);
|
|
106
|
+
}
|
|
107
|
+
static getWalletFromPrivKeyFile(jsonStr, password) {
|
|
108
|
+
const jsonArr = JSON.parse(jsonStr);
|
|
109
|
+
if (jsonArr.encseed != null)
|
|
110
|
+
return this.fromEthSale(jsonStr, password);
|
|
111
|
+
else if (jsonArr.Crypto != null ||
|
|
112
|
+
jsonArr.crypto != null) {
|
|
113
|
+
return this.fromV3(jsonStr, password, true);
|
|
114
|
+
}
|
|
115
|
+
else if (jsonArr.hash != null) {
|
|
116
|
+
return this.fromMyEtherWallet(jsonStr, password);
|
|
117
|
+
}
|
|
118
|
+
else if (jsonArr.publisher === 'MyEtherWallet') {
|
|
119
|
+
return this.fromMyEtherWalletV2(jsonStr);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
throw new Error("Sorry! We don't recognize this type of wallet file.");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//
|
|
126
|
+
// QR Codes requires EthUtils
|
|
127
|
+
//
|
|
128
|
+
makeSignedQRWithPubKey(objContent, pubKey) {
|
|
129
|
+
objContent.message_key = cipherMsg(pubKey, this.messageKeysFromWallet());
|
|
130
|
+
objContent.address = this.getAddressString();
|
|
131
|
+
return this.makeSignedQR(objContent);
|
|
132
|
+
}
|
|
133
|
+
makeSignedQR(obj) {
|
|
134
|
+
// Values expected:
|
|
135
|
+
const { server, destinary, begin, end, viewbalance, viewoldtran, pub_key } = obj;
|
|
136
|
+
const formatDate = (date) => `${begin.getFullYear()}/${begin.getMonth()}/${begin.getDate()}`;
|
|
137
|
+
const objContent = Object.assign(obj, {
|
|
138
|
+
address: this.getAddressString(),
|
|
139
|
+
begin: formatDate(begin),
|
|
140
|
+
end: formatDate(end)
|
|
141
|
+
});
|
|
142
|
+
const hash = ethUtil.sha3(JSON.stringify(objContent));
|
|
143
|
+
const signature = ethUtil.ecsign(hash, this.privKey);
|
|
144
|
+
return {
|
|
145
|
+
signature,
|
|
146
|
+
qrContent: JSON.stringify({
|
|
147
|
+
data: objContent,
|
|
148
|
+
signature: {
|
|
149
|
+
v: signature.v,
|
|
150
|
+
r: '0x' + signature.r.toString('hex'),
|
|
151
|
+
s: '0x' + signature.s.toString('hex')
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// // TODO: What to do with this validateEnrollment
|
|
158
|
+
// public static validateEnrollment (codeId, signature) {
|
|
159
|
+
// return this.ajaxReq.validateEnrollmentLetter(
|
|
160
|
+
// codeId, this.currencyName, signature)
|
|
161
|
+
// }
|
|
162
|
+
//# sourceMappingURL=wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,iBAAiB,CAAA;AAGrC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC1E,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAG7C,MAAM,CAAC,OAAO,OAAgB,uBAAwB,SAAQ,MAAM;IAApE;;QAME,gBAAW,GAAuC,IAAI,CAAA;IAmLxD,CAAC;IAjLQ,MAAM,CAAC,KAAK,CAAC,YAAY;QAC9B,MAAM,MAAM,GAAG,IAAI,IAAI,EAAE,CAAA;QACzB,OAAO,MAAM,CAAC,sBAAsB,EAAE,CAAA;IACxC,CAAC;IAEO,iBAAiB;QACvB,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC;YAC7B,OAAO,EAAE,IAAI,CAAC,gB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|
|
2
|
+
"name": "@com-chain/jsc3l",
|
|
3
|
+
"version": "2.0.1-rc.0",
|
|
4
|
+
"description": "JavaScript Com-Chain Communication Library",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"watch": "tsc -w"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/com-chain/JSC3L.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"Com-Chain",
|
|
17
|
+
"JS",
|
|
18
|
+
"Client"
|
|
19
|
+
],
|
|
20
|
+
"author": "Florian Dubath",
|
|
21
|
+
"license": "AGPL-3.0",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/com-chain/JSC3L/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/com-chain/JSC3L#readme",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^16.10.3",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
29
|
+
"@typescript-eslint/parser": "^4.33.0",
|
|
30
|
+
"eslint": "^7.29.0",
|
|
31
|
+
"typescript": "^4.4.3"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@babel/runtime": "^7.15.4",
|
|
35
|
+
"bignumber.js": "^2.4.0",
|
|
36
|
+
"ethereumjs-tx": "^1.3.7",
|
|
37
|
+
"scryptsy": "^2.1.0",
|
|
38
|
+
"through2": "^4.0.2",
|
|
39
|
+
"uuid": "^8.3.2"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/bcRead.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js'
|
|
2
|
+
|
|
3
|
+
import AjaxReq from './rest/ajaxReq'
|
|
4
|
+
import { getNakedAddress, padLeft, getDataObj } from './ethereum/ethFuncs'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
function getNumber (data, ratio) {
|
|
8
|
+
const shortData = '0x' + data.slice(-12)
|
|
9
|
+
let a = parseInt(shortData, 16)
|
|
10
|
+
|
|
11
|
+
if (a > (34359738368 * 4096)) {
|
|
12
|
+
a -= 68719476736 * 4096
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return a / ratio
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export default abstract class BcReadAbstract {
|
|
20
|
+
|
|
21
|
+
abstract ajaxReq: AjaxReq
|
|
22
|
+
abstract contracts: string[]
|
|
23
|
+
|
|
24
|
+
// Get Global status of the contract
|
|
25
|
+
async getContractStatus () { return this.getGlobInfo('0x8b3c7c69') }
|
|
26
|
+
// Get Global infos: Tax destinary Account
|
|
27
|
+
async getTaxAccount () { return this.getGlobInfo('0x4f2eabe0') }
|
|
28
|
+
|
|
29
|
+
// Get Historical infos infos: Global balance
|
|
30
|
+
async getHistoricalGlobalBalance (walletAddress, blockNb) {
|
|
31
|
+
return this.getAmountAt('0x70a08231', walletAddress, blockNb)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// //////////////////////////////////////////////////////////////////////////
|
|
36
|
+
// Generic read function
|
|
37
|
+
|
|
38
|
+
async getAmount (address, walletAddress) {
|
|
39
|
+
const userInfo = getDataObj(
|
|
40
|
+
this.contracts[0], address, [getNakedAddress(walletAddress)])
|
|
41
|
+
const data = await this.ajaxReq.getEthCall(userInfo)
|
|
42
|
+
return getNumber(data, 100.0).toString()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async getAccInfo (address, walletAddress) {
|
|
46
|
+
return this.getInfo(this.contracts[0], address, walletAddress)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getGlobInfo (address) {
|
|
50
|
+
const userInfo = getDataObj(this.contracts[0], address, [])
|
|
51
|
+
return this.ajaxReq.getEthCall(userInfo)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async getAmountAt (address, walletAddress, blockNb) {
|
|
55
|
+
const userInfo = getDataObj(
|
|
56
|
+
this.contracts[0], address, [getNakedAddress(walletAddress)])
|
|
57
|
+
const blockHex = '0x' + new BigNumber(blockNb).toString(16)
|
|
58
|
+
const data = await this.ajaxReq.getEthCallAt(userInfo, blockHex)
|
|
59
|
+
return getNumber(data, 100.0).toString()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async getInfo (contract, address, walletAddress) {
|
|
63
|
+
const userInfo = getDataObj(
|
|
64
|
+
contract, address, [getNakedAddress(walletAddress)])
|
|
65
|
+
const data = await this.ajaxReq.getEthCall(userInfo)
|
|
66
|
+
return getNumber(data, 1.0)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async getAmountForElement (
|
|
70
|
+
contract, functionAddress, callerAddress, elementAddress) {
|
|
71
|
+
const userInfo = getDataObj(
|
|
72
|
+
contract, functionAddress,
|
|
73
|
+
[
|
|
74
|
+
getNakedAddress(callerAddress),
|
|
75
|
+
getNakedAddress(elementAddress)
|
|
76
|
+
])
|
|
77
|
+
const data = await this.ajaxReq.getEthCall(userInfo)
|
|
78
|
+
return getNumber(data, 100.0).toString()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async getElementInList (
|
|
82
|
+
contract, mapFunctionAddress, amountFunctionAddress,
|
|
83
|
+
callerAddress, index, list, indMin) {
|
|
84
|
+
|
|
85
|
+
if (index < indMin) return list
|
|
86
|
+
|
|
87
|
+
const userInfo = getDataObj(
|
|
88
|
+
contract, mapFunctionAddress,
|
|
89
|
+
[
|
|
90
|
+
getNakedAddress(callerAddress),
|
|
91
|
+
padLeft(new BigNumber(index).toString(16), 64)
|
|
92
|
+
])
|
|
93
|
+
const data: {[k: string]: any} = await this.ajaxReq.getEthCall(userInfo)
|
|
94
|
+
|
|
95
|
+
const amount = await this.getAmountForElement(
|
|
96
|
+
contract, amountFunctionAddress, callerAddress, data)
|
|
97
|
+
|
|
98
|
+
const cleanedAdd = '0x' + data.substring(data.length - 40)
|
|
99
|
+
const element = { address: cleanedAdd, amount: amount }
|
|
100
|
+
list.unshift(element)
|
|
101
|
+
return this.getElementInList(
|
|
102
|
+
contract, mapFunctionAddress,
|
|
103
|
+
amountFunctionAddress, callerAddress, index - 1, list,
|
|
104
|
+
indMin)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
const fnHashes = [
|
|
112
|
+
{
|
|
113
|
+
fn: 'getAmount',
|
|
114
|
+
hashes: { // Function to read amount of coin
|
|
115
|
+
getGlobalBalance: '0x70a08231',
|
|
116
|
+
getNantBalance: '0xae261aba',
|
|
117
|
+
getCmBalance: '0xbbc72a17',
|
|
118
|
+
getCmLimitBelow: '0xcc885a65',
|
|
119
|
+
getCmLimitAbove: '0xae7143d6'
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
fn: 'getAccInfo',
|
|
124
|
+
hashes: { // Function to read Account infos
|
|
125
|
+
getAccountStatus: '0x61242bdd',
|
|
126
|
+
getAccountType: '0xba99af70',
|
|
127
|
+
getIsOwner: '0x2f54bf6e',
|
|
128
|
+
getTaxAmount: '0x98a9cfac',
|
|
129
|
+
getLegTaxAmount: '0x48455399',
|
|
130
|
+
getTotalAmount: '0x18160ddd'
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
|
|
135
|
+
fnHashes.forEach(({ fn, hashes }) => {
|
|
136
|
+
for (const fnName in hashes) {
|
|
137
|
+
const fnHash = hashes[fnName]
|
|
138
|
+
BcReadAbstract.prototype[fnName] = function (walletAddress) {
|
|
139
|
+
return this[fn](fnHash, walletAddress)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
// Handle lists
|
|
147
|
+
const ListFunction = {
|
|
148
|
+
Allowance: { count: 'aa7adb3d', map: 'b545b11f', amount: 'dd62ed3e' },
|
|
149
|
+
|
|
150
|
+
RequestToApprove: { count: 'debb9d28', map: '726d0a28', amount: '3537d3fa' },
|
|
151
|
+
PendingRequest: { count: '418d0fd4', map: '0becf93f', amount: '09a15e43' },
|
|
152
|
+
|
|
153
|
+
Delegation: { count: '58fb5218', map: 'ca40edf1', amount: '046d3307' },
|
|
154
|
+
MyDelegation: { count: '7737784d', map: '49bce08d', amount: 'f24111d2' },
|
|
155
|
+
|
|
156
|
+
AcceptedRequest: { count: '8d768f84', map: '59a1921a', amount: '958cde37' },
|
|
157
|
+
RejectedRequest: { count: '20cde8fa', map: '9aa9366e', amount: 'eac9dd4d' }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
for (const key in ListFunction) {
|
|
161
|
+
const configList = ListFunction[key]
|
|
162
|
+
BcReadAbstract.prototype[`get${key}List`] =
|
|
163
|
+
async function (walletAddress, indMin, indMax) {
|
|
164
|
+
// Simple protection against ill inputs on indMin and indMax and to
|
|
165
|
+
// avoid unwanted infinite loops
|
|
166
|
+
indMax = indMax || 0
|
|
167
|
+
indMin = indMin || 0
|
|
168
|
+
const count = await this.getInfo(
|
|
169
|
+
this.contracts[1],
|
|
170
|
+
`0x${configList.count}`,
|
|
171
|
+
walletAddress)
|
|
172
|
+
const list = []
|
|
173
|
+
const index = Math.min(count - 1, indMax)
|
|
174
|
+
return this.getElementInList(
|
|
175
|
+
this.contracts[1],
|
|
176
|
+
`0x${configList.map}`,
|
|
177
|
+
`0x${configList.amount}`,
|
|
178
|
+
walletAddress,
|
|
179
|
+
index,
|
|
180
|
+
list,
|
|
181
|
+
indMin)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|