user 6 tahun lalu
induk
melakukan
0307ea9f2a
5 mengubah file dengan 46 tambahan dan 43 penghapusan
  1. 5 1
      lib/index.d.ts
  2. 19 19
      lib/index.js
  3. 1 1
      lib/index.js.map
  4. 20 21
      src/index.ts
  5. 1 1
      src/sample.ts

+ 5 - 1
lib/index.d.ts

@@ -15,7 +15,11 @@ 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;
-    private parseBankLink;
 }

+ 19 - 19
lib/index.js

@@ -148,6 +148,25 @@ 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');
@@ -182,25 +201,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] = 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 };
-    }
 }
 exports.BankClient = BankClient;
 //# sourceMappingURL=index.js.map

File diff ditekan karena terlalu besar
+ 1 - 1
lib/index.js.map


+ 20 - 21
src/index.ts

@@ -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 };
-    }
-  
 }

+ 1 - 1
src/sample.ts

@@ -13,6 +13,6 @@ const bankClient = new BankClient('https://hostname');
     });
     console.log('my balance', balance);
     console.log('upl', uploadResult);
-    await bankClient.appendBank('bank:qmlink/📥', uploadResult);
+    await bankClient.appendBank('qmlink', '📥', uploadResult);
     console.log('added.');
 })();