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> {
|
||||
const localAddress = this.sdkClient.get_address();
|
||||
const emptyTxid = '0'.repeat(64);
|
||||
|
||||
public async createPairingProcess(pairWith: string[], relayAddress: string, feeRate: number): Promise<void> {
|
||||
const myAddress: string = this.sdkClient.get_address();
|
||||
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 {
|
||||
let commitmentOutpoint = `${emptyTxid}:${U32_MAX}`;
|
||||
this.sdkClient.pair_device(commitmentOutpoint, [spAddress]);
|
||||
const newProcessReturn = this.sdkClient.create_new_process(JSON.stringify(pairingTemplate), relayAddress, feeRate);
|
||||
console.log('newProcessReturn:', newProcessReturn);
|
||||
await this.handleApiReturn(newProcessReturn);
|
||||
} catch (e) {
|
||||
console.error('Services ~ Error:', e);
|
||||
return;
|
||||
throw new Error(`Creating process failed:, ${e}`);
|
||||
}
|
||||
|
||||
setTimeout(async () => {
|
||||
const apiReturn = this.prepareProcessTx(localAddress, spAddress);
|
||||
await this.handleApiReturn(apiReturn);
|
||||
}, 1500);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
async resetDevice() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user