@didcid/gatekeeper 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/drawbridge-client.cjs +103 -0
- package/dist/cjs/gatekeeper-client.cjs +10 -1
- package/dist/cjs/gatekeeper.cjs +3100 -260
- package/dist/esm/drawbridge-client.js +96 -0
- package/dist/esm/drawbridge-client.js.map +1 -0
- package/dist/esm/gatekeeper-client.js +10 -1
- package/dist/esm/gatekeeper-client.js.map +1 -1
- package/dist/types/drawbridge-client.d.ts +17 -0
- package/dist/types/gatekeeper-client.d.ts +5 -2
- package/dist/types/types.d.ts +41 -0
- package/package.json +13 -5
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var gatekeeperClient = require('./gatekeeper-client.cjs');
|
|
6
|
+
require('axios');
|
|
7
|
+
|
|
8
|
+
function throwError(error) {
|
|
9
|
+
if (error.response) {
|
|
10
|
+
throw error.response.data;
|
|
11
|
+
}
|
|
12
|
+
throw error.message;
|
|
13
|
+
}
|
|
14
|
+
class DrawbridgeClient extends gatekeeperClient.default {
|
|
15
|
+
static async create(options) {
|
|
16
|
+
const client = new DrawbridgeClient();
|
|
17
|
+
await client.connect(options);
|
|
18
|
+
return client;
|
|
19
|
+
}
|
|
20
|
+
async isLightningSupported() {
|
|
21
|
+
try {
|
|
22
|
+
const response = await this.axios.get(`${this.API}/lightning/supported`);
|
|
23
|
+
return response.data?.supported === true;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async createLightningWallet(name) {
|
|
30
|
+
try {
|
|
31
|
+
const response = await this.axios.post(`${this.API}/lightning/wallet`, { name });
|
|
32
|
+
return response.data;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
throwError(error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async getLightningBalance(invoiceKey) {
|
|
39
|
+
try {
|
|
40
|
+
const response = await this.axios.post(`${this.API}/lightning/balance`, { invoiceKey });
|
|
41
|
+
return response.data;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
throwError(error);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async createLightningInvoice(invoiceKey, amount, memo) {
|
|
48
|
+
try {
|
|
49
|
+
const response = await this.axios.post(`${this.API}/lightning/invoice`, { invoiceKey, amount, memo });
|
|
50
|
+
return response.data;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throwError(error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async payLightningInvoice(adminKey, bolt11) {
|
|
57
|
+
try {
|
|
58
|
+
const response = await this.axios.post(`${this.API}/lightning/pay`, { adminKey, bolt11 });
|
|
59
|
+
return response.data;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throwError(error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async checkLightningPayment(invoiceKey, paymentHash) {
|
|
66
|
+
try {
|
|
67
|
+
const response = await this.axios.post(`${this.API}/lightning/payment`, { invoiceKey, paymentHash });
|
|
68
|
+
return response.data;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throwError(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async publishLightning(did, invoiceKey) {
|
|
75
|
+
try {
|
|
76
|
+
const response = await this.axios.post(`${this.API}/lightning/publish`, { did, invoiceKey });
|
|
77
|
+
return response.data;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
throwError(error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async unpublishLightning(did) {
|
|
84
|
+
try {
|
|
85
|
+
const response = await this.axios.delete(`${this.API}/lightning/publish/${encodeURIComponent(did)}`);
|
|
86
|
+
return response.data.ok;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
throwError(error);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async zapLightning(adminKey, did, amount, memo) {
|
|
93
|
+
try {
|
|
94
|
+
const response = await this.axios.post(`${this.API}/lightning/zap`, { adminKey, did, amount, memo });
|
|
95
|
+
return response.data;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
throwError(error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
exports.default = DrawbridgeClient;
|
|
@@ -13,6 +13,7 @@ function throwError(error) {
|
|
|
13
13
|
}
|
|
14
14
|
class GatekeeperClient {
|
|
15
15
|
API;
|
|
16
|
+
baseUrl;
|
|
16
17
|
axios;
|
|
17
18
|
// Factory method
|
|
18
19
|
static async create(options) {
|
|
@@ -24,6 +25,7 @@ class GatekeeperClient {
|
|
|
24
25
|
const axios = axiosModule?.default ??
|
|
25
26
|
axiosModule;
|
|
26
27
|
this.API = VERSION;
|
|
28
|
+
this.baseUrl = '';
|
|
27
29
|
this.axios = axios.create();
|
|
28
30
|
}
|
|
29
31
|
addCustomHeader(header, value) {
|
|
@@ -32,9 +34,16 @@ class GatekeeperClient {
|
|
|
32
34
|
removeCustomHeader(header) {
|
|
33
35
|
delete this.axios.defaults.headers.common[header];
|
|
34
36
|
}
|
|
37
|
+
get url() {
|
|
38
|
+
return this.baseUrl;
|
|
39
|
+
}
|
|
35
40
|
async connect(options) {
|
|
36
41
|
if (options?.url) {
|
|
37
|
-
this.
|
|
42
|
+
this.baseUrl = new URL(options.url).origin;
|
|
43
|
+
this.API = `${this.baseUrl}${VERSION}`;
|
|
44
|
+
}
|
|
45
|
+
if (options?.apiKey) {
|
|
46
|
+
this.addCustomHeader('Authorization', `Bearer ${options.apiKey}`);
|
|
38
47
|
}
|
|
39
48
|
// Only used for unit testing
|
|
40
49
|
// TBD replace console with a real logging package
|