user преди 6 години
родител
ревизия
6c54b807da
променени са 6 файла, в които са добавени 48 реда и са изтрити 48 реда
  1. 5 5
      lib/index.d.ts
  2. 19 19
      lib/index.js
  3. 1 1
      lib/index.js.map
  4. 1 1
      lib/sample.js
  5. 1 1
      lib/sample.js.map
  6. 21 21
      src/index.ts

+ 5 - 5
lib/index.d.ts

@@ -5,6 +5,11 @@ export declare class BankClient {
     private urlBase;
     private storage;
     private webClient;
+    static parseBankLink(bankLink: string): {
+        host: string | undefined;
+        address: string;
+        topic: string;
+    };
     private privateKey;
     private bootstrapPromise;
     private bootstrapResult;
@@ -15,11 +20,6 @@ export declare class BankClient {
     getBalance(): Promise<number>;
     upload(params: UploadItemParameters): Promise<any>;
     appendBank(bankAddress: string, bankTopic: string, itemHash: string): Promise<void>;
-    parseBankLink(bankLink: string): {
-        host: string | undefined;
-        address: string;
-        topic: string;
-    };
     private getPriv;
     private makePlaintextPayload;
 }

+ 19 - 19
lib/index.js

@@ -23,6 +23,25 @@ class BankClient {
         this.storage = storage;
         this.webClient = webClient;
     }
+    static parseBankLink(bankLink) {
+        if (!bankLink.startsWith('bank:')) {
+            throw new Error('address must start with bank:');
+        }
+        const deprefixed = bankLink.substring(5);
+        let host;
+        let address;
+        let topic;
+        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 };
+    }
     getPub() {
         return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
             yield this.bootstrap();
@@ -148,25 +167,6 @@ class BankClient {
             });
         });
     }
-    parseBankLink(bankLink) {
-        if (!bankLink.startsWith('bank:')) {
-            throw new Error('address must start with bank:');
-        }
-        const deprefixed = bankLink.substring(5);
-        let host;
-        let address;
-        let topic;
-        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 };
-    }
     getPriv() {
         if (!this.privateKey) {
             throw new Error('missing private key');

Файловите разлики са ограничени, защото са твърде много
+ 1 - 1
lib/index.js.map


+ 1 - 1
lib/sample.js

@@ -21,7 +21,7 @@ const bankClient = new BankClient('https://hostname');
     });
     console.log('my balance', balance);
     console.log('upl', uploadResult);
-    yield bankClient.appendBank('bank:qmlink/📥', uploadResult);
+    yield bankClient.appendBank('qmlink', '📥', uploadResult);
     console.log('added.');
 }))();
 //# sourceMappingURL=sample.js.map

Файловите разлики са ограничени, защото са твърде много
+ 1 - 1
lib/sample.js.map


+ 21 - 21
src/index.ts

@@ -10,10 +10,29 @@ import WebClientNode from './webclient-node';
 
 export class BankClient {
 
+  public static 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 privateKey: RsaPrivateKey | undefined;
     private bootstrapPromise: any;
     private bootstrapResult: any;
-
+    
     constructor(private urlBase: string, private storage: Storage = new Storage('bankClient'), private webClient: IWebClient = new WebClientNode()) {
 
     }
@@ -140,26 +159,7 @@ 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');