Add createPairingProcess
This commit is contained in:
parent
f99f9a6199
commit
da32410c71
@ -152,24 +152,35 @@ export default class Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendPairingTx(spAddress: string): Promise<void> {
|
public async createPairingProcess(pairWith: string[], relayAddress: string, feeRate: number): Promise<void> {
|
||||||
const localAddress = this.sdkClient.get_address();
|
const myAddress: string = this.sdkClient.get_address();
|
||||||
const emptyTxid = '0'.repeat(64);
|
pairWith.push(myAddress);
|
||||||
|
const newKey = this.sdkClient.get_new_keypair();
|
||||||
|
const pairingTemplate = {
|
||||||
|
description: 'pairing',
|
||||||
|
roles: {
|
||||||
|
owner: {
|
||||||
|
members: [{ sp_addresses: pairWith }],
|
||||||
|
validation_rules: [
|
||||||
|
{
|
||||||
|
quorum: 1.0,
|
||||||
|
fields: ['description', 'roles', 'session_privkey', 'session_pubkey', 'key_parity'],
|
||||||
|
min_sig_member: 1.0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
session_privkey: newKey['private_key'],
|
||||||
|
session_pubkey: newKey['x_only_public_key'],
|
||||||
|
key_parity: newKey['key_parity'],
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
let commitmentOutpoint = `${emptyTxid}:${U32_MAX}`;
|
const newProcessReturn = this.sdkClient.create_new_process(JSON.stringify(pairingTemplate), relayAddress, feeRate);
|
||||||
this.sdkClient.pair_device(commitmentOutpoint, [spAddress]);
|
console.log('newProcessReturn:', newProcessReturn);
|
||||||
|
await this.handleApiReturn(newProcessReturn);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Services ~ Error:', e);
|
throw new Error(`Creating process failed:, ${e}`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(async () => {
|
|
||||||
const apiReturn = this.prepareProcessTx(localAddress, spAddress);
|
|
||||||
await this.handleApiReturn(apiReturn);
|
|
||||||
}, 1500);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async resetDevice() {
|
async resetDevice() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user