forked from Senyoret1/hardware-wallet-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_codes.js
181 lines (158 loc) · 4.83 KB
/
test_codes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
const deviceWallet = require('./device-wallet');
const scanf = require('scanf');
const fs = require('fs');
const sha256 = require('js-sha256');
if( deviceWallet.getDevice() === null ) {
console.log("Skycoin hardware NOT FOUND, using emulator");
deviceWallet.setDeviceType(deviceWallet.DeviceTypeEnum.EMULATOR);
} else {
deviceWallet.setDeviceType(deviceWallet.DeviceTypeEnum.USB);
}
const rejectPromise = function(msg) {
console.log("Promise rejected", msg);
};
const wordReader = function() {
return new Promise((resolve) => {
console.log("Inside wordReader callback, please input word: ");
const word = scanf('%s');
resolve(word);
});
};
const pinCodeReader = function() {
return new Promise((resolve, reject) => {
console.log("Got inside pinCodeReader");
const pinCode = scanf('%s');
if (pinCode.length != 4) {
reject(new Error("Bad bad pin code"));
return;
}
resolve(pinCode);
});
};
const testApplySettings = false;
if (testApplySettings) {
const promise = deviceWallet.devApplySettings(true);
promise.then(console.log, rejectPromise);
}
const testTransactionSign = true;
if (testTransactionSign) {
const inputTransaction = {
'hashIn': "99a1a50ffa21ab48ee7c31d01e7e14451f9834f5294468bd17e87c5018900b81",
'index': 0
};
const inputTransactionArray = [
inputTransaction,
inputTransaction
];
const outputTransaction1 = {
'address': "BCbAa3vS7bPLH2bwL7MvedND5uta5bceHj",
'address_index': 2,
'coin': 125000000,
'hour': 4
};
const outputTransaction2 = {
'address': "2kVVoMkH7aTVXsiGwZEALpkHZ6sUyumL8hH",
'coin': 2000000,
'hour': 3
};
const outputTransactionArray = [
outputTransaction1,
outputTransaction2
];
const promise = deviceWallet.devSkycoinTransactionSign(
inputTransactionArray,
outputTransactionArray,
pinCodeReader,
wordReader
);
promise.then(console.log, rejectPromise);
}
const testSign = false;
if (testSign) {
const signPromise = deviceWallet.devSkycoinSignMessage(3, "Hello World!", null);
signPromise.then(
(signature) => {
console.log("Signature promise resolved", signature);
const signPromise2 = deviceWallet.devSkycoinSignMessage(3, "Hello World!", pinCodeReader, wordReader);
signPromise2.then(
(signature2) => {
console.log("Signature promise resolved", signature2);
},
rejectPromise
);
},
rejectPromise
);
}
const testAddressGen = false;
if (testAddressGen) {
const promise = deviceWallet.devAddressGen(9, 3, true, pinCodeReader, wordReader);
promise.then(console.log, rejectPromise);
}
const testPinChange = false;
if (testPinChange) {
const promise = deviceWallet.devChangePin(pinCodeReader);
promise.then(
() => {
console.log("promise resolved");
const promise2 = deviceWallet.devChangePin();
promise2.then(
() => {
console.log("promise resolved");
},
rejectPromise
);
},
rejectPromise
);
}
const testFirmwareUpdate = false;
if (testFirmwareUpdate) {
fs.readFile('skycoin-firmware-passphrase-experiment.bin', function(err, data) {
console.log(err);
console.log(data);
console.log(data.length);
deviceWallet.devUpdateFirmware(data, sha256(data.slice(0x100)));
});
}
const testGetVersion = false;
if (testGetVersion) {
const promise = deviceWallet.devGetVersionDevice();
promise.then(
(version) => {
console.log("Version is: ", version);
},
rejectPromise
);
}
const testRecovery = false;
if (testRecovery) {
const promise = deviceWallet.devRecoveryDevice(true, wordReader);
promise.then(console.log, rejectPromise);
}
const testFeatures = false;
if (testFeatures) {
const promise = deviceWallet.devGetFeatures();
promise.then(console.log, rejectPromise);
}
const testCancel = false;
if (testCancel) {
const promise = deviceWallet.devCancelRequest();
promise.then(console.log, rejectPromise);
}
const testBackup = false;
if (testBackup) {
const promise = deviceWallet.devBackupDevice(pinCodeReader);
promise.then(console.log, rejectPromise);
}
const testMnemonic = false;
if (testMnemonic) {
const mnemonic = "cloud flower upset remain green metal below cup stem infant art thank";
const promise = deviceWallet.devSetMnemonic(mnemonic);
promise.then(console.log, rejectPromise);
}
const testGenerateMnemonic = false;
if (testGenerateMnemonic) {
const promise = deviceWallet.devGenerateMnemonic(true);
promise.then(console.log, rejectPromise);
}