|
|
@@ -140,7 +140,26 @@ export class BankClient {
|
|
|
url: topicURL
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ public parseBankLink(bankLink: string) {
|
|
|
+ if (!bankLink.startsWith('bank:')) {
|
|
|
+ throw new Error('address must start with bank:');
|
|
|
+ }
|
|
|
+ const deprefixed = bankLink.substring(5);
|
|
|
+ let host: string | undefined;
|
|
|
+ let address: string;
|
|
|
+ let topic: string;
|
|
|
+ if (deprefixed[0] === '/' && deprefixed[1] === '/') {
|
|
|
+ [ host, address, topic ] = deprefixed.substring(2).split('/');
|
|
|
+ } else {
|
|
|
+ [ address, topic ] = deprefixed.split('/');
|
|
|
+ }
|
|
|
+ if (!address || !topic) {
|
|
|
+ throw new Error('cannot parse address and topic');
|
|
|
+ }
|
|
|
+ return { host, address, topic };
|
|
|
+ }
|
|
|
+
|
|
|
private getPriv(): RsaPrivateKey {
|
|
|
if (!this.privateKey) {
|
|
|
throw new Error('missing private key');
|
|
|
@@ -177,24 +196,4 @@ export class BankClient {
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- private parseBankLink(bankLink: string) {
|
|
|
- if (!bankLink.startsWith('bank:')) {
|
|
|
- throw new Error('address must start with bank:');
|
|
|
- }
|
|
|
- const deprefixed = bankLink.substring(5);
|
|
|
- let host: string | undefined;
|
|
|
- let address: string;
|
|
|
- let topic: string;
|
|
|
- if (deprefixed[0] === '/' && deprefixed[1] === '/') {
|
|
|
- [ host, address, topic ] = bankLink.substring(5).split('/');
|
|
|
- } else {
|
|
|
- [ address, topic ] = bankLink.substring(5).split('/');
|
|
|
- }
|
|
|
- if (!address || !topic) {
|
|
|
- throw new Error('cannot parse address and topic');
|
|
|
- }
|
|
|
- return { host, address, topic };
|
|
|
- }
|
|
|
-
|
|
|
}
|