Closed 0x009922 closed 3 years ago
This issue may be resolved with https://github.com/hyperledger/iroha-javascript/pull/69.
Note that to use crypto you have to initialize it firstly. More about it in the README of the @iroha/crypto
package
import { KeyGenConfiguration, KeyPair } from '@iroha2/crypto';
const SEED_BYTES = [49, 50, 51, 52];
const config = new KeyGenConfiguration().use_seed(Uint8Array.from(SEED_BYTES));
const keyPair = KeyPair.generate_with_configuration(config);
// now `keyPair` is usable in client
import { types, createClient } from '@iroha2/client';
import { KeyPair } from '@iroha2/crypto';
// Having a payload of bytes
const PAYLOAD_BYTES = new Uint8Array([1, 2, 3 /* ... */]);
// And a KeyPair
const keyPair: KeyPair = /* ... */;
// firstly, decode payload into JS representation
const payloadDecoded = types.decode('iroha_data_model::transaction::Payload', PAYLOAD_BYTES);
// init a client
const client = createClient({
toriiURL: 'http://localhost:8080',
});
// and submit a transaction
await client.submitTransaction({
payload: payloadDecoded,
signing: keyPair,
});
Request
There are two tasks:
Key pairs generation
The most efficient way to reach this goal and an ultimative solution for this is to completely port
iroha_crypto
crate into WASM. It is a big task and requires a lot of refactoring in Rust's sources.Building transaction
I guess the solution for this will be a special
TransactionBuilder
helper that will provide several ways to build a transaction. I don't know how it will be looks like because it depends on how the new@iroha/crypto
package will looks like.