forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathed25519-program.test.ts
54 lines (47 loc) · 1.46 KB
/
ed25519-program.test.ts
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
import {Buffer} from 'buffer';
import nacl from 'tweetnacl';
import {
Connection,
Keypair,
sendAndConfirmTransaction,
LAMPORTS_PER_SOL,
Transaction,
Ed25519Program,
} from '../src';
import {url} from './url';
if (process.env.TEST_LIVE) {
describe('ed25519', () => {
const keypair = Keypair.generate();
const privateKey = keypair.secretKey;
const publicKey = keypair.publicKey.toBytes();
const from = Keypair.generate();
const connection = new Connection(url, 'confirmed');
before(async function () {
await connection.confirmTransaction(
await connection.requestAirdrop(from.publicKey, 10 * LAMPORTS_PER_SOL),
);
});
it('create ed25519 instruction', async () => {
const message = Buffer.from('string address');
const signature = nacl.sign.detached(message, privateKey);
const transaction = new Transaction().add(
Ed25519Program.createInstructionWithPublicKey({
publicKey,
message,
signature,
}),
);
await sendAndConfirmTransaction(connection, transaction, [from]);
});
it('create ed25519 instruction with private key', async () => {
const message = Buffer.from('private key');
const transaction = new Transaction().add(
Ed25519Program.createInstructionWithPrivateKey({
privateKey,
message,
}),
);
await sendAndConfirmTransaction(connection, transaction, [from]);
});
});
}