-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
220 lines (188 loc) · 5.45 KB
/
test.js
File metadata and controls
220 lines (188 loc) · 5.45 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
const api = require("./utils/apis")
const tonUtils = require("./utils/ton");
const db = require("./utils/db")
const cashlink = require("@tonlink/api")
const redis = require("./utils/redis");
const orbs = require("@orbs-network/ton-access")
const _ton = require("@ton/ton")
const kg = require("./modules/auth/index")
const qr = require('qrcode');
const b58 = require("b58")
const nacl = require("tweetnacl")
// const Web3 = require("web3")
const web3 = require("web3")
const solanaweb3 =require("@solana/web3.js")
const hd = require("ethereumjs-wallet")
const tonCrypto = require("@ton/crypto")
const ton = require("@ton/ton")
const btc = require("bitcoinjs-lib")
var bitcoinMessage = require('bitcoinjs-message')
const bip32 = require('bip32')
const ecpair=require('ecpair');
const ecc=require('tiny-secp256k1');
require('dotenv').config()
function seedToKp()
{
var kp = new nacl.sign.keyPair()
console.log(kp)
console.log(
nacl.sign.keyPair.fromSeed(kp.publicKey)
)
console.log(
nacl.sign.keyPair.fromSeed(kp.publicKey)
)
console.log(
nacl.sign.keyPair.fromSeed(kp.publicKey)
)
console.log(
nacl.sign.keyPair.fromSeed(kp.publicKey)
)
}
function seedTest()
{
var kp = nacl.sign.keyPair.fromSecretKey(
b58.decode(process.env.WLLET_SK)
)
const master = hd.hdkey.fromMasterSeed(kp.publicKey);
var child = master.deriveChild(1111111111)
var child_wallet = child.getWallet()
console.log(child_wallet.getAddressString())
console.log(
b58.encode(nacl.sign.keyPair.fromSeed(child_wallet.getPrivateKey()).publicKey),
b58.encode(nacl.sign.keyPair.fromSeed(child_wallet.getPrivateKey()).secretKey)
)
}
function b58Test()
{
var d = {
t:1,
i:"1234567",
d:"Hello qwq",
c:{
t:0,
i:1
},
r:""
}
var c = {
t:0,
i:"1234567",
d:"wallet.tonspay.top",
c:{
t:1,
i:1
},
r:""
}
console.log(
b58.encode(
Buffer.from(JSON.stringify(c))
)
)
}
async function evmTest()
{
const account = web3.eth.accounts.privateKeyToAccount('0x1caa5efc57cea53e3761a2aa17fc9c09fea2468012bca29a6a3646b7ceb690e6');
console.log(account)
const data = account.sign("Hello world");
console.log(data)
}
async function solTest()
{
const account = new solanaweb3.Keypair()
console.log(account)
const messageBytes = Buffer.from("Hello world");
const data = nacl.sign.detached(messageBytes, account.secretKey);
console.log(data)
const result = nacl.sign.detached.verify(
messageBytes,
data,
account.publicKey.toBytes()
);
console.log(result);
}
function getTonWalletV4KeyPair(sec,workchain)
{
const kp = tonCrypto.keyPairFromSecretKey(sec);
return ton.WalletContractV4.create({ publicKey: kp.publicKey, workchain: workchain });
}
async function tonTest()
{
const naclKp = new nacl.sign.keyPair()
var tonKp = getTonWalletV4KeyPair(naclKp.secretKey,0)
console.log(tonKp)
}
async function setTimeoutTest()
{
console.log("setTimeoutTest 0")
}
async function sol_version_tx_test()
{
var tx = '';
const rawSign = new Uint8Array(b58.decode(tx))
// const realTx =solanaweb3.Transaction.populate(solanaweb3.Message.from(rawSign))
const realTx = solanaweb3.VersionedTransaction.deserialize(rawSign) //solanaweb3.VersionedMessage.deserialize(rawSign)
// const realTx = new solanaweb3.Transaction()
console.log(typeof(realTx))
console.log(realTx.constructor.name == "VersionedTransaction")
}
async function btcTest()
{
// const randomPrivate = Buffer.from(
// (new nacl.sign.keyPair()).publicKey
// )
const randomPrivate = Buffer.from(
(nacl.sign.keyPair.fromSecretKey(
b58.decode(
"67788VzaDjvjDLVUEjBi3wMHFEvyNiycWge4nozjoou1esLNyyjYdLcdvfG4ARNCg6FUBjEYt8XBKbz78nHVjhLW"
)
)).publicKey
)
const ECPair=ecpair.ECPairFactory(ecc);
// ECPair.fromPrivateKey()
// const kp =ECPair.makeRandom({network:btc.networks.testnet})
const kp = ECPair.fromPrivateKey(randomPrivate,{})
console.log(
kp
)
var private_key=kp.privateKey.toString('hex');
var public_key=kp.publicKey.toString('hex');
console.log('pri_key = '+private_key);
console.log('pub_key = '+public_key);
const { address }=btc.payments.p2pkh({pubkey:kp.publicKey});
console.log('address = '+address);
// console.log(bip32)
var privateKey = kp.privateKey
var message = 'This is an example of a signed message.'
var signature = bitcoinMessage.sign(message, privateKey, kp.compressed)
console.log("🚧 BITCOIN SIGNATURE",signature.toString('base64'))
var oldkp = ECPair.fromPrivateKey(Buffer.from(privateKey,'hex'),{})
console.log(
oldkp
)
}
async function test() {
await btcTest()
// await seedTest()
// await evmTest()
// await sol_version_tx_test()
// await tonTest()
// await setTimeoutTest()
// setTimeout(
// async function(){
// console.log('setTimeoutTest 1')
// },2000
// );
// console.log("setTimeoutTest 2")
// console.log(
// Buffer.from(
// b58.encode(
// Buffer.from('https://raydium-v3.tons.ink/')
// )
// ).toString()
// )
// console.log(
// Web3
// )
}
test()