@astrox/agent 0.0.24 → 0.0.30
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/lib/cjs/actor.d.ts +126 -0
- package/lib/cjs/actor.js +207 -0
- package/lib/cjs/actor.js.map +1 -0
- package/lib/cjs/agent/api.d.ts +140 -0
- package/lib/cjs/agent/api.js +16 -0
- package/lib/cjs/agent/api.js.map +1 -0
- package/lib/cjs/agent/http/index.d.ts +49 -0
- package/lib/cjs/agent/http/index.js +355 -0
- package/lib/cjs/agent/http/index.js.map +1 -0
- package/lib/cjs/agent/http/transforms.d.ts +20 -0
- package/lib/cjs/agent/http/transforms.js +70 -0
- package/lib/cjs/agent/http/transforms.js.map +1 -0
- package/lib/cjs/agent/http/types.d.ts +77 -0
- package/lib/cjs/agent/http/types.js +24 -0
- package/lib/cjs/agent/http/types.js.map +1 -0
- package/lib/cjs/agent/index.d.ts +7 -0
- package/lib/cjs/agent/index.js +42 -0
- package/lib/cjs/agent/index.js.map +1 -0
- package/lib/cjs/agent/proxy.d.ts +85 -0
- package/lib/cjs/agent/proxy.js +159 -0
- package/lib/cjs/agent/proxy.js.map +1 -0
- package/lib/cjs/auth.d.ts +87 -0
- package/lib/cjs/auth.js +70 -0
- package/lib/cjs/auth.js.map +1 -0
- package/lib/cjs/canisters/asset.d.ts +10 -0
- package/lib/cjs/canisters/asset.js +18 -0
- package/lib/cjs/canisters/asset.js.map +1 -0
- package/lib/cjs/canisters/asset_idl.d.ts +7 -0
- package/lib/cjs/canisters/asset_idl.js +14 -0
- package/lib/cjs/canisters/asset_idl.js.map +1 -0
- package/lib/cjs/canisters/management.d.ts +33 -0
- package/lib/cjs/canisters/management.js +30 -0
- package/lib/cjs/canisters/management.js.map +1 -0
- package/lib/cjs/canisters/management_idl.d.ts +7 -0
- package/lib/cjs/canisters/management_idl.js +29 -0
- package/lib/cjs/canisters/management_idl.js.map +1 -0
- package/lib/cjs/cbor.d.ts +9 -0
- package/lib/cjs/cbor.js +138 -0
- package/lib/cjs/cbor.js.map +1 -0
- package/lib/cjs/certificate.d.ts +43 -0
- package/lib/cjs/certificate.js +227 -0
- package/lib/cjs/certificate.js.map +1 -0
- package/lib/cjs/errors.d.ts +8 -0
- package/lib/cjs/errors.js +13 -0
- package/lib/cjs/errors.js.map +1 -0
- package/lib/cjs/index.d.ts +52 -0
- package/lib/cjs/index.js +38 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/polling/index.d.ts +16 -0
- package/lib/cjs/polling/index.js +81 -0
- package/lib/cjs/polling/index.js.map +1 -0
- package/lib/cjs/polling/strategy.d.ts +47 -0
- package/lib/cjs/polling/strategy.js +106 -0
- package/lib/cjs/polling/strategy.js.map +1 -0
- package/lib/cjs/request_id.d.ts +15 -0
- package/lib/cjs/request_id.js +89 -0
- package/lib/cjs/request_id.js.map +1 -0
- package/lib/cjs/utils/bls.d.ts +9 -0
- package/lib/cjs/utils/bls.js +65 -0
- package/lib/cjs/utils/bls.js.map +1 -0
- package/lib/cjs/utils/buffer.d.ts +16 -0
- package/lib/cjs/utils/buffer.js +59 -0
- package/lib/cjs/utils/buffer.js.map +1 -0
- package/lib/cjs/vendor/bls/bls.d.ts +28 -0
- package/lib/cjs/vendor/bls/bls.js +894 -0
- package/lib/cjs/vendor/bls/bls.js.map +1 -0
- package/lib/esm/actor.d.ts +126 -0
- package/lib/esm/actor.js +200 -0
- package/lib/esm/actor.js.map +1 -0
- package/lib/esm/agent/api.d.ts +140 -0
- package/lib/esm/agent/api.js +13 -0
- package/lib/esm/agent/api.js.map +1 -0
- package/lib/esm/agent/http/index.d.ts +49 -0
- package/lib/esm/agent/http/index.js +328 -0
- package/lib/esm/agent/http/index.js.map +1 -0
- package/lib/esm/agent/http/transforms.d.ts +20 -0
- package/lib/esm/agent/http/transforms.js +45 -0
- package/lib/esm/agent/http/transforms.js.map +1 -0
- package/lib/esm/agent/http/types.d.ts +77 -0
- package/lib/esm/agent/http/types.js +20 -0
- package/lib/esm/agent/http/types.js.map +1 -0
- package/lib/esm/agent/index.d.ts +7 -0
- package/lib/esm/agent/index.js +27 -0
- package/lib/esm/agent/index.js.map +1 -0
- package/lib/esm/agent/proxy.d.ts +85 -0
- package/lib/esm/agent/proxy.js +154 -0
- package/lib/esm/agent/proxy.js.map +1 -0
- package/lib/esm/auth.d.ts +87 -0
- package/lib/esm/auth.js +64 -0
- package/lib/esm/auth.js.map +1 -0
- package/lib/esm/canisters/asset.d.ts +10 -0
- package/lib/esm/canisters/asset.js +11 -0
- package/lib/esm/canisters/asset.js.map +1 -0
- package/lib/esm/canisters/asset_idl.d.ts +7 -0
- package/lib/esm/canisters/asset_idl.js +12 -0
- package/lib/esm/canisters/asset_idl.js.map +1 -0
- package/lib/esm/canisters/management.d.ts +37 -0
- package/lib/esm/canisters/management.js +23 -0
- package/lib/esm/canisters/management.js.map +1 -0
- package/lib/esm/canisters/management_idl.d.ts +7 -0
- package/lib/esm/canisters/management_idl.js +27 -0
- package/lib/esm/canisters/management_idl.js.map +1 -0
- package/lib/esm/cbor.d.ts +9 -0
- package/lib/esm/cbor.js +111 -0
- package/lib/esm/cbor.js.map +1 -0
- package/lib/esm/certificate.d.ts +43 -0
- package/lib/esm/certificate.js +200 -0
- package/lib/esm/certificate.js.map +1 -0
- package/lib/esm/errors.d.ts +8 -0
- package/lib/esm/errors.js +9 -0
- package/lib/esm/errors.js.map +1 -0
- package/lib/esm/index.d.ts +52 -0
- package/lib/esm/index.js +14 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/polling/index.d.ts +16 -0
- package/lib/esm/polling/index.js +57 -0
- package/lib/esm/polling/index.js.map +1 -0
- package/lib/esm/polling/strategy.d.ts +47 -0
- package/lib/esm/polling/strategy.js +95 -0
- package/lib/esm/polling/strategy.js.map +1 -0
- package/lib/esm/request_id.d.ts +15 -0
- package/lib/esm/request_id.js +81 -0
- package/lib/esm/request_id.js.map +1 -0
- package/lib/esm/utils/bls.d.ts +9 -0
- package/lib/esm/utils/bls.js +43 -0
- package/lib/esm/utils/bls.js.map +1 -0
- package/lib/esm/utils/buffer.d.ts +16 -0
- package/lib/esm/utils/buffer.js +52 -0
- package/lib/esm/utils/buffer.js.map +1 -0
- package/lib/esm/vendor/bls/bls.d.ts +28 -0
- package/lib/esm/vendor/bls/bls.js +870 -0
- package/lib/esm/vendor/bls/bls.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.HttpAgent = exports.RequestStatusResponseStatus = void 0;
|
|
26
|
+
const agent_1 = require("@astrox/agent");
|
|
27
|
+
const principal_1 = require("@astrox/principal");
|
|
28
|
+
const auth_1 = require("../../auth");
|
|
29
|
+
const cbor = __importStar(require("../../cbor"));
|
|
30
|
+
const request_id_1 = require("../../request_id");
|
|
31
|
+
const buffer_1 = require("../../utils/buffer");
|
|
32
|
+
const transforms_1 = require("./transforms");
|
|
33
|
+
const types_1 = require("./types");
|
|
34
|
+
__exportStar(require("./transforms"), exports);
|
|
35
|
+
var types_2 = require("./types");
|
|
36
|
+
Object.defineProperty(exports, "makeNonce", { enumerable: true, get: function () { return types_2.makeNonce; } });
|
|
37
|
+
var RequestStatusResponseStatus;
|
|
38
|
+
(function (RequestStatusResponseStatus) {
|
|
39
|
+
RequestStatusResponseStatus["Received"] = "received";
|
|
40
|
+
RequestStatusResponseStatus["Processing"] = "processing";
|
|
41
|
+
RequestStatusResponseStatus["Replied"] = "replied";
|
|
42
|
+
RequestStatusResponseStatus["Rejected"] = "rejected";
|
|
43
|
+
RequestStatusResponseStatus["Unknown"] = "unknown";
|
|
44
|
+
RequestStatusResponseStatus["Done"] = "done";
|
|
45
|
+
})(RequestStatusResponseStatus = exports.RequestStatusResponseStatus || (exports.RequestStatusResponseStatus = {}));
|
|
46
|
+
// Default delta for ingress expiry is 5 minutes.
|
|
47
|
+
const DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS = 5 * 60 * 1000;
|
|
48
|
+
// Root public key for the IC, encoded as hex
|
|
49
|
+
const IC_ROOT_KEY = '308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814' +
|
|
50
|
+
'c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d968' +
|
|
51
|
+
'5f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484' +
|
|
52
|
+
'b01291091c5f87b98883463f98091a0baaae';
|
|
53
|
+
function getDefaultFetch() {
|
|
54
|
+
const result = typeof window === 'undefined'
|
|
55
|
+
? typeof global === 'undefined'
|
|
56
|
+
? typeof self === 'undefined'
|
|
57
|
+
? undefined
|
|
58
|
+
: self.fetch.bind(self)
|
|
59
|
+
: global.fetch.bind(global)
|
|
60
|
+
: window.fetch.bind(window);
|
|
61
|
+
if (!result) {
|
|
62
|
+
throw new Error('Could not find default `fetch` implementation.');
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
function getKrakenFetch() {
|
|
67
|
+
if (agent_1.getKraken()) {
|
|
68
|
+
const result = typeof window === 'undefined'
|
|
69
|
+
? typeof global === 'undefined'
|
|
70
|
+
? typeof self === 'undefined'
|
|
71
|
+
? undefined
|
|
72
|
+
: self.fetchAgent.bind(self)
|
|
73
|
+
: global.fetchAgent.bind(global)
|
|
74
|
+
: window.fetchAgent.bind(window);
|
|
75
|
+
if (!result) {
|
|
76
|
+
throw new Error('Could not find default `fetch` implementation.');
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
return getDefaultFetch();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// A HTTP agent allows users to interact with a client of the internet computer
|
|
85
|
+
// using the available methods. It exposes an API that closely follows the
|
|
86
|
+
// public view of the internet computer, and is not intended to be exposed
|
|
87
|
+
// directly to the majority of users due to its low-level interface.
|
|
88
|
+
//
|
|
89
|
+
// There is a pipeline to apply transformations to the request before sending
|
|
90
|
+
// it to the client. This is to decouple signature, nonce generation and
|
|
91
|
+
// other computations so that this class can stay as simple as possible while
|
|
92
|
+
// allowing extensions.
|
|
93
|
+
class HttpAgent {
|
|
94
|
+
constructor(options = {}) {
|
|
95
|
+
this.rootKey = buffer_1.fromHex(IC_ROOT_KEY);
|
|
96
|
+
this._pipeline = [];
|
|
97
|
+
this._rootKeyFetched = false;
|
|
98
|
+
if (options.source) {
|
|
99
|
+
if (!(options.source instanceof HttpAgent)) {
|
|
100
|
+
throw new Error("An Agent's source can only be another HttpAgent");
|
|
101
|
+
}
|
|
102
|
+
this._pipeline = [...options.source._pipeline];
|
|
103
|
+
this._identity = options.source._identity;
|
|
104
|
+
this._fetch = options.source._fetch;
|
|
105
|
+
this._fetchAgent = options.source._fetchAgent;
|
|
106
|
+
this._host = options.source._host;
|
|
107
|
+
this._credentials = options.source._credentials;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
this._fetch = options.fetch || getDefaultFetch() || fetch.bind(global);
|
|
111
|
+
this._fetchAgent = options.fetchAgent || getKrakenFetch() || fetch.bind(global);
|
|
112
|
+
}
|
|
113
|
+
if (options.host !== undefined) {
|
|
114
|
+
if (!options.host.match(/^[a-z]+:/) && typeof window !== 'undefined') {
|
|
115
|
+
this._host = new URL(window.location.protocol + '//' + options.host);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
this._host = new URL(options.host);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else if (options.source !== undefined) {
|
|
122
|
+
// Safe to ignore here.
|
|
123
|
+
this._host = options.source._host;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const location = typeof window !== 'undefined' ? window.location : undefined;
|
|
127
|
+
if (!location) {
|
|
128
|
+
throw new Error('Must specify a host to connect to.');
|
|
129
|
+
}
|
|
130
|
+
this._host = new URL(location + '');
|
|
131
|
+
}
|
|
132
|
+
if (options.credentials) {
|
|
133
|
+
const { name, password } = options.credentials;
|
|
134
|
+
this._credentials = `${name}${password ? ':' + password : ''}`;
|
|
135
|
+
}
|
|
136
|
+
this._identity = Promise.resolve(options.identity || new auth_1.AnonymousIdentity());
|
|
137
|
+
}
|
|
138
|
+
addTransform(fn, priority = fn.priority || 0) {
|
|
139
|
+
// Keep the pipeline sorted at all time, by priority.
|
|
140
|
+
const i = this._pipeline.findIndex(x => (x.priority || 0) < priority);
|
|
141
|
+
this._pipeline.splice(i >= 0 ? i : this._pipeline.length, 0, Object.assign(fn, { priority }));
|
|
142
|
+
}
|
|
143
|
+
async getPrincipal() {
|
|
144
|
+
return (await this._identity).getPrincipal();
|
|
145
|
+
}
|
|
146
|
+
async call(canisterId, options, identity) {
|
|
147
|
+
const id = (await (identity !== undefined ? await identity : await this._identity));
|
|
148
|
+
const canister = principal_1.Principal.from(canisterId);
|
|
149
|
+
const ecid = options.effectiveCanisterId
|
|
150
|
+
? principal_1.Principal.from(options.effectiveCanisterId)
|
|
151
|
+
: canister;
|
|
152
|
+
const sender = id.getPrincipal() || principal_1.Principal.anonymous();
|
|
153
|
+
const submit = {
|
|
154
|
+
request_type: types_1.SubmitRequestType.Call,
|
|
155
|
+
canister_id: canister,
|
|
156
|
+
method_name: options.methodName,
|
|
157
|
+
arg: options.arg,
|
|
158
|
+
sender,
|
|
159
|
+
ingress_expiry: new transforms_1.Expiry(DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS),
|
|
160
|
+
};
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
162
|
+
let transformedRequest = (await this._transform({
|
|
163
|
+
request: {
|
|
164
|
+
body: null,
|
|
165
|
+
method: 'POST',
|
|
166
|
+
headers: Object.assign({ 'Content-Type': 'application/cbor' }, (this._credentials ? { Authorization: 'Basic ' + btoa(this._credentials) } : {})),
|
|
167
|
+
},
|
|
168
|
+
endpoint: "call" /* Call */,
|
|
169
|
+
body: submit,
|
|
170
|
+
}));
|
|
171
|
+
// Apply transform for identity.
|
|
172
|
+
transformedRequest = await id.transformRequest(transformedRequest);
|
|
173
|
+
const body = cbor.encode(transformedRequest.body);
|
|
174
|
+
const kraken = agent_1.getKraken();
|
|
175
|
+
if (!kraken) {
|
|
176
|
+
// Run both in parallel. The fetch is quite expensive, so we have plenty of time to
|
|
177
|
+
// calculate the requestId locally.
|
|
178
|
+
const [response, requestId] = await Promise.all([
|
|
179
|
+
this._fetch('' + new URL(`/api/v2/canister/${ecid.toText()}/call`, this._host), Object.assign(Object.assign({}, transformedRequest.request), { body })),
|
|
180
|
+
request_id_1.requestIdOf(submit),
|
|
181
|
+
]);
|
|
182
|
+
console.log('astorx call');
|
|
183
|
+
if (!response.ok) {
|
|
184
|
+
throw new Error(`Server returned an error:\n` +
|
|
185
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
186
|
+
` Body: ${await response.text()}\n`);
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
requestId,
|
|
190
|
+
response: {
|
|
191
|
+
ok: response.ok,
|
|
192
|
+
status: response.status,
|
|
193
|
+
statusText: response.statusText,
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
const [response, requestId] = await Promise.all([
|
|
199
|
+
this._fetchAgent('' + new URL(`/api/v2/canister/${ecid.toText()}/call`, this._host), Object.assign(Object.assign({}, transformedRequest.request), { body: buffer_1.toHex(body) })),
|
|
200
|
+
request_id_1.requestIdOf(submit),
|
|
201
|
+
]);
|
|
202
|
+
if (!response.ok) {
|
|
203
|
+
throw new Error(`Server returned an error:\n` +
|
|
204
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
205
|
+
` Body: ${response.body}\n`);
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
requestId,
|
|
209
|
+
response: {
|
|
210
|
+
ok: response.ok,
|
|
211
|
+
status: response.status,
|
|
212
|
+
statusText: response.statusText,
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
async query(canisterId, fields, identity) {
|
|
218
|
+
const id = await (identity !== undefined ? await identity : await this._identity);
|
|
219
|
+
const canister = typeof canisterId === 'string' ? principal_1.Principal.fromText(canisterId) : canisterId;
|
|
220
|
+
const sender = (id === null || id === void 0 ? void 0 : id.getPrincipal()) || principal_1.Principal.anonymous();
|
|
221
|
+
const request = {
|
|
222
|
+
request_type: "query" /* Query */,
|
|
223
|
+
canister_id: canister,
|
|
224
|
+
method_name: fields.methodName,
|
|
225
|
+
arg: fields.arg,
|
|
226
|
+
sender,
|
|
227
|
+
ingress_expiry: new transforms_1.Expiry(DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS),
|
|
228
|
+
};
|
|
229
|
+
// TODO: remove this any. This can be a Signed or UnSigned request.
|
|
230
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
231
|
+
let transformedRequest = await this._transform({
|
|
232
|
+
request: {
|
|
233
|
+
method: 'POST',
|
|
234
|
+
headers: Object.assign({ 'Content-Type': 'application/cbor' }, (this._credentials ? { Authorization: 'Basic ' + btoa(this._credentials) } : {})),
|
|
235
|
+
},
|
|
236
|
+
endpoint: "read" /* Query */,
|
|
237
|
+
body: request,
|
|
238
|
+
});
|
|
239
|
+
// Apply transform for identity.
|
|
240
|
+
transformedRequest = await id.transformRequest(transformedRequest);
|
|
241
|
+
const body = cbor.encode(transformedRequest.body);
|
|
242
|
+
const kraken = agent_1.getKraken();
|
|
243
|
+
if (!kraken) {
|
|
244
|
+
const response = await this._fetch('' + new URL(`/api/v2/canister/${canister.toText()}/query`, this._host), Object.assign(Object.assign({}, transformedRequest.request), { body }));
|
|
245
|
+
console.log('astorx query');
|
|
246
|
+
if (!response.ok) {
|
|
247
|
+
throw new Error(`Server returned an error:\n` +
|
|
248
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
249
|
+
` Body: ${await response.text()}\n`);
|
|
250
|
+
}
|
|
251
|
+
return cbor.decode(await response.arrayBuffer());
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
const response = await this._fetchAgent('' + new URL(`/api/v2/canister/${canister.toText()}/query`, this._host), Object.assign(Object.assign({}, transformedRequest.request), { body: buffer_1.toHex(body) }));
|
|
255
|
+
console.log('astrox query');
|
|
256
|
+
if (!response.ok) {
|
|
257
|
+
throw new Error(`Server returned an error:\n` +
|
|
258
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
259
|
+
` Body: ${response.body}\n`);
|
|
260
|
+
}
|
|
261
|
+
return cbor.decode(buffer_1.fromHex(response.body));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async readState(canisterId, fields, identity) {
|
|
265
|
+
const canister = typeof canisterId === 'string' ? principal_1.Principal.fromText(canisterId) : canisterId;
|
|
266
|
+
const id = await (identity !== undefined ? await identity : await this._identity);
|
|
267
|
+
const sender = (id === null || id === void 0 ? void 0 : id.getPrincipal()) || principal_1.Principal.anonymous();
|
|
268
|
+
// TODO: remove this any. This can be a Signed or UnSigned request.
|
|
269
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
270
|
+
let transformedRequest = await this._transform({
|
|
271
|
+
request: {
|
|
272
|
+
method: 'POST',
|
|
273
|
+
headers: Object.assign({ 'Content-Type': 'application/cbor' }, (this._credentials ? { Authorization: 'Basic ' + btoa(this._credentials) } : {})),
|
|
274
|
+
},
|
|
275
|
+
endpoint: "read_state" /* ReadState */,
|
|
276
|
+
body: {
|
|
277
|
+
request_type: "read_state" /* ReadState */,
|
|
278
|
+
paths: fields.paths,
|
|
279
|
+
sender,
|
|
280
|
+
ingress_expiry: new transforms_1.Expiry(DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS),
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
// Apply transform for identity.
|
|
284
|
+
transformedRequest = await id.transformRequest(transformedRequest);
|
|
285
|
+
const body = cbor.encode(transformedRequest.body);
|
|
286
|
+
const kraken = agent_1.getKraken();
|
|
287
|
+
if (!kraken) {
|
|
288
|
+
const response = await this._fetch('' + new URL(`/api/v2/canister/${canister}/read_state`, this._host), Object.assign(Object.assign({}, transformedRequest.request), { body }));
|
|
289
|
+
console.log('astorx read_state');
|
|
290
|
+
if (!response.ok) {
|
|
291
|
+
throw new Error(`Server returned an error:\n` +
|
|
292
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
293
|
+
` Body: ${await response.text()}\n`);
|
|
294
|
+
}
|
|
295
|
+
return cbor.decode(await response.arrayBuffer());
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
const response = await this._fetchAgent('' + new URL(`/api/v2/canister/${canister}/read_state`, this._host), Object.assign(Object.assign({}, transformedRequest.request), { body: buffer_1.toHex(body) }));
|
|
299
|
+
console.log('astorx read_state');
|
|
300
|
+
if (!response.ok) {
|
|
301
|
+
throw new Error(`Server returned an error:\n` +
|
|
302
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
303
|
+
` Body: ${response.body}\n`);
|
|
304
|
+
}
|
|
305
|
+
return cbor.decode(buffer_1.fromHex(response.body));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async status() {
|
|
309
|
+
const headers = this._credentials
|
|
310
|
+
? {
|
|
311
|
+
Authorization: 'Basic ' + btoa(this._credentials),
|
|
312
|
+
}
|
|
313
|
+
: {};
|
|
314
|
+
const kraken = agent_1.getKraken();
|
|
315
|
+
if (!kraken) {
|
|
316
|
+
const response = await this._fetch('' + new URL(`/api/v2/status`, this._host), { headers });
|
|
317
|
+
console.log('astorx status');
|
|
318
|
+
if (!response.ok) {
|
|
319
|
+
throw new Error(`Server returned an error:\n` +
|
|
320
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
321
|
+
` Body: ${await response.text()}\n`);
|
|
322
|
+
}
|
|
323
|
+
return cbor.decode(await response.arrayBuffer());
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
const response = await this._fetchAgent('' + new URL(`/api/v2/status`, this._host), {
|
|
327
|
+
headers,
|
|
328
|
+
});
|
|
329
|
+
console.log('astrox status');
|
|
330
|
+
if (!response.ok) {
|
|
331
|
+
throw new Error(`Server returned an error:\n` +
|
|
332
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
333
|
+
` Body: ${response.body}\n`);
|
|
334
|
+
}
|
|
335
|
+
return cbor.decode(buffer_1.fromHex(response.body));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
async fetchRootKey() {
|
|
339
|
+
if (!this._rootKeyFetched) {
|
|
340
|
+
// Hex-encoded version of the replica root key
|
|
341
|
+
this.rootKey = (await this.status()).root_key;
|
|
342
|
+
this._rootKeyFetched = true;
|
|
343
|
+
}
|
|
344
|
+
return this.rootKey;
|
|
345
|
+
}
|
|
346
|
+
_transform(request) {
|
|
347
|
+
let p = Promise.resolve(request);
|
|
348
|
+
for (const fn of this._pipeline) {
|
|
349
|
+
p = p.then(r => fn(r).then(r2 => r2 || r));
|
|
350
|
+
}
|
|
351
|
+
return p;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
exports.HttpAgent = HttpAgent;
|
|
355
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/agent/http/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA0C;AAE1C,iDAA8C;AAC9C,qCAAyD;AACzD,iDAAmC;AACnC,iDAA+C;AAC/C,+CAAoD;AASpD,6CAAsC;AACtC,mCASiB;AAEjB,+CAA6B;AAC7B,iCAA2C;AAA3B,kGAAA,SAAS,OAAA;AAEzB,IAAY,2BAOX;AAPD,WAAY,2BAA2B;IACrC,oDAAqB,CAAA;IACrB,wDAAyB,CAAA;IACzB,kDAAmB,CAAA;IACnB,oDAAqB,CAAA;IACrB,kDAAmB,CAAA;IACnB,4CAAa,CAAA;AACf,CAAC,EAPW,2BAA2B,GAA3B,mCAA2B,KAA3B,mCAA2B,QAOtC;AAED,iDAAiD;AACjD,MAAM,qCAAqC,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAE5D,6CAA6C;AAC7C,MAAM,WAAW,GACf,+EAA+E;IAC/E,+EAA+E;IAC/E,8EAA8E;IAC9E,sCAAsC,CAAC;AA8BzC,SAAS,eAAe;IACtB,MAAM,MAAM,GACV,OAAO,MAAM,KAAK,WAAW;QAC3B,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW;YAC7B,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;gBAC3B,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC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C;IACX,CAAC;CACF;AAhWD,8BAgWC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as cbor from 'simple-cbor';
|
|
2
|
+
import { HttpAgentRequestTransformFn, Nonce } from './types';
|
|
3
|
+
export declare class Expiry {
|
|
4
|
+
private readonly _value;
|
|
5
|
+
constructor(deltaInMSec: number);
|
|
6
|
+
toCBOR(): cbor.CborValue;
|
|
7
|
+
toHash(): ArrayBuffer;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a Nonce transform, which takes a function that returns a Buffer, and adds it
|
|
11
|
+
* as the nonce to every call requests.
|
|
12
|
+
* @param nonceFn A function that returns a buffer. By default uses a semi-random method.
|
|
13
|
+
*/
|
|
14
|
+
export declare function makeNonceTransform(nonceFn?: () => Nonce): HttpAgentRequestTransformFn;
|
|
15
|
+
/**
|
|
16
|
+
* Create a transform that adds a delay (by default 5 minutes) to the expiry.
|
|
17
|
+
*
|
|
18
|
+
* @param delayInMilliseconds The delay to add to the call time, in milliseconds.
|
|
19
|
+
*/
|
|
20
|
+
export declare function makeExpiryTransform(delayInMilliseconds: number): HttpAgentRequestTransformFn;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.makeExpiryTransform = exports.makeNonceTransform = exports.Expiry = void 0;
|
|
23
|
+
const candid_1 = require("@astrox/candid");
|
|
24
|
+
const cbor = __importStar(require("simple-cbor"));
|
|
25
|
+
const types_1 = require("./types");
|
|
26
|
+
const NANOSECONDS_PER_MILLISECONDS = BigInt(1000000);
|
|
27
|
+
const REPLICA_PERMITTED_DRIFT_MILLISECONDS = BigInt(60 * 1000);
|
|
28
|
+
class Expiry {
|
|
29
|
+
constructor(deltaInMSec) {
|
|
30
|
+
// Use bigint because it can overflow the maximum number allowed in a double float.
|
|
31
|
+
this._value =
|
|
32
|
+
(BigInt(Date.now()) + BigInt(deltaInMSec) - REPLICA_PERMITTED_DRIFT_MILLISECONDS) *
|
|
33
|
+
NANOSECONDS_PER_MILLISECONDS;
|
|
34
|
+
}
|
|
35
|
+
toCBOR() {
|
|
36
|
+
// TODO: change this to take the minimum amount of space (it always takes 8 bytes now).
|
|
37
|
+
return cbor.value.u64(this._value.toString(16), 16);
|
|
38
|
+
}
|
|
39
|
+
toHash() {
|
|
40
|
+
return candid_1.lebEncode(this._value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Expiry = Expiry;
|
|
44
|
+
/**
|
|
45
|
+
* Create a Nonce transform, which takes a function that returns a Buffer, and adds it
|
|
46
|
+
* as the nonce to every call requests.
|
|
47
|
+
* @param nonceFn A function that returns a buffer. By default uses a semi-random method.
|
|
48
|
+
*/
|
|
49
|
+
function makeNonceTransform(nonceFn = types_1.makeNonce) {
|
|
50
|
+
return async (request) => {
|
|
51
|
+
// Nonce are only useful for async calls, to prevent replay attacks. Other types of
|
|
52
|
+
// calls don't need Nonce so we just skip creating one.
|
|
53
|
+
if (request.endpoint === "call" /* Call */) {
|
|
54
|
+
request.body.nonce = nonceFn();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.makeNonceTransform = makeNonceTransform;
|
|
59
|
+
/**
|
|
60
|
+
* Create a transform that adds a delay (by default 5 minutes) to the expiry.
|
|
61
|
+
*
|
|
62
|
+
* @param delayInMilliseconds The delay to add to the call time, in milliseconds.
|
|
63
|
+
*/
|
|
64
|
+
function makeExpiryTransform(delayInMilliseconds) {
|
|
65
|
+
return async (request) => {
|
|
66
|
+
request.body.ingress_expiry = new Expiry(delayInMilliseconds);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
exports.makeExpiryTransform = makeExpiryTransform;
|
|
70
|
+
//# sourceMappingURL=transforms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transforms.js","sourceRoot":"","sources":["../../../../src/agent/http/transforms.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA2C;AAC3C,kDAAoC;AACpC,mCAAoG;AAEpG,MAAM,4BAA4B,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AAErD,MAAM,oCAAoC,GAAG,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;AAE/D,MAAa,MAAM;IAGjB,YAAY,WAAmB;QAC7B,mFAAmF;QACnF,IAAI,CAAC,MAAM;YACT,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,oCAAoC,CAAC;gBACjF,4BAA4B,CAAC;IACjC,CAAC;IAEM,MAAM;QACX,uFAAuF;QACvF,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACtD,CAAC;IAEM,MAAM;QACX,OAAO,kBAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;CACF;AAlBD,wBAkBC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,UAAuB,iBAAS;IACjE,OAAO,KAAK,EAAE,OAAyB,EAAE,EAAE;QACzC,mFAAmF;QACnF,uDAAuD;QACvD,IAAI,OAAO,CAAC,QAAQ,sBAAkB,EAAE;YACtC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,CAAC;SAChC;IACH,CAAC,CAAC;AACJ,CAAC;AARD,gDAQC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,mBAA2B;IAC7D,OAAO,KAAK,EAAE,OAAyB,EAAE,EAAE;QACzC,OAAO,CAAC,IAAI,CAAC,cAAc,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAChE,CAAC,CAAC;AACJ,CAAC;AAJD,kDAIC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Principal } from '@astrox/principal';
|
|
2
|
+
import { Expiry } from './transforms';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare const enum Endpoint {
|
|
7
|
+
Query = "read",
|
|
8
|
+
ReadState = "read_state",
|
|
9
|
+
Call = "call"
|
|
10
|
+
}
|
|
11
|
+
export declare type HttpAgentRequest = HttpAgentQueryRequest | HttpAgentSubmitRequest | HttpAgentReadStateRequest;
|
|
12
|
+
export interface HttpAgentBaseRequest {
|
|
13
|
+
readonly endpoint: Endpoint;
|
|
14
|
+
request: RequestInit;
|
|
15
|
+
}
|
|
16
|
+
export interface HttpAgentSubmitRequest extends HttpAgentBaseRequest {
|
|
17
|
+
readonly endpoint: Endpoint.Call;
|
|
18
|
+
body: CallRequest;
|
|
19
|
+
}
|
|
20
|
+
export interface HttpAgentQueryRequest extends HttpAgentBaseRequest {
|
|
21
|
+
readonly endpoint: Endpoint.Query;
|
|
22
|
+
body: ReadRequest;
|
|
23
|
+
}
|
|
24
|
+
export interface HttpAgentReadStateRequest extends HttpAgentBaseRequest {
|
|
25
|
+
readonly endpoint: Endpoint.ReadState;
|
|
26
|
+
body: ReadRequest;
|
|
27
|
+
}
|
|
28
|
+
export interface Signed<T> {
|
|
29
|
+
content: T;
|
|
30
|
+
sender_pubkey: ArrayBuffer;
|
|
31
|
+
sender_sig: ArrayBuffer;
|
|
32
|
+
}
|
|
33
|
+
export interface UnSigned<T> {
|
|
34
|
+
content: T;
|
|
35
|
+
}
|
|
36
|
+
export declare type Envelope<T> = Signed<T> | UnSigned<T>;
|
|
37
|
+
export interface HttpAgentRequestTransformFn {
|
|
38
|
+
(args: HttpAgentRequest): Promise<HttpAgentRequest | undefined | void>;
|
|
39
|
+
priority?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface CallRequest extends Record<string, any> {
|
|
42
|
+
request_type: SubmitRequestType.Call;
|
|
43
|
+
canister_id: Principal;
|
|
44
|
+
method_name: string;
|
|
45
|
+
arg: ArrayBuffer;
|
|
46
|
+
sender: Uint8Array | Principal;
|
|
47
|
+
ingress_expiry: Expiry;
|
|
48
|
+
}
|
|
49
|
+
export declare enum SubmitRequestType {
|
|
50
|
+
Call = "call"
|
|
51
|
+
}
|
|
52
|
+
export declare const enum ReadRequestType {
|
|
53
|
+
Query = "query",
|
|
54
|
+
ReadState = "read_state"
|
|
55
|
+
}
|
|
56
|
+
export interface QueryRequest extends Record<string, any> {
|
|
57
|
+
request_type: ReadRequestType.Query;
|
|
58
|
+
canister_id: Principal;
|
|
59
|
+
method_name: string;
|
|
60
|
+
arg: ArrayBuffer;
|
|
61
|
+
sender: Uint8Array | Principal;
|
|
62
|
+
ingress_expiry: Expiry;
|
|
63
|
+
}
|
|
64
|
+
export interface ReadStateRequest extends Record<string, any> {
|
|
65
|
+
request_type: ReadRequestType.ReadState;
|
|
66
|
+
paths: ArrayBuffer[][];
|
|
67
|
+
ingress_expiry: Expiry;
|
|
68
|
+
sender: Uint8Array | Principal;
|
|
69
|
+
}
|
|
70
|
+
export declare type ReadRequest = QueryRequest | ReadStateRequest;
|
|
71
|
+
export declare type Nonce = Uint8Array & {
|
|
72
|
+
__nonce__: void;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Create a random Nonce, based on date and a random suffix.
|
|
76
|
+
*/
|
|
77
|
+
export declare function makeNonce(): Nonce;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeNonce = exports.SubmitRequestType = void 0;
|
|
4
|
+
// tslint:enable:camel-case
|
|
5
|
+
// The types of values allowed in the `request_type` field for submit requests.
|
|
6
|
+
var SubmitRequestType;
|
|
7
|
+
(function (SubmitRequestType) {
|
|
8
|
+
SubmitRequestType["Call"] = "call";
|
|
9
|
+
})(SubmitRequestType = exports.SubmitRequestType || (exports.SubmitRequestType = {}));
|
|
10
|
+
/**
|
|
11
|
+
* Create a random Nonce, based on date and a random suffix.
|
|
12
|
+
*/
|
|
13
|
+
function makeNonce() {
|
|
14
|
+
// Encode 128 bits.
|
|
15
|
+
const buffer = new ArrayBuffer(16);
|
|
16
|
+
const view = new DataView(buffer);
|
|
17
|
+
const value = BigInt(+Date.now()) * BigInt(100000) + BigInt(Math.floor(Math.random() * 100000));
|
|
18
|
+
view.setBigUint64(0, value);
|
|
19
|
+
// tslint:disable-next-line:no-bitwise
|
|
20
|
+
view.setBigUint64(1, value >> BigInt(64));
|
|
21
|
+
return buffer;
|
|
22
|
+
}
|
|
23
|
+
exports.makeNonce = makeNonce;
|
|
24
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/agent/http/types.ts"],"names":[],"mappings":";;;AAmEA,2BAA2B;AAE3B,+EAA+E;AAC/E,IAAY,iBAEX;AAFD,WAAY,iBAAiB;IAC3B,kCAAa,CAAA;AACf,CAAC,EAFW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAE5B;AA8BD;;GAEG;AACH,SAAgB,SAAS;IACvB,mBAAmB;IACnB,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC;IAChG,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC5B,sCAAsC;IACtC,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,KAAK,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAE1C,OAAO,MAAe,CAAC;AACzB,CAAC;AAVD,8BAUC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.getKraken = exports.getDefaultAgent = void 0;
|
|
14
|
+
__exportStar(require("./api"), exports);
|
|
15
|
+
__exportStar(require("./http"), exports);
|
|
16
|
+
__exportStar(require("./proxy"), exports);
|
|
17
|
+
function getDefaultAgent() {
|
|
18
|
+
const agent = typeof window === 'undefined'
|
|
19
|
+
? typeof global === 'undefined'
|
|
20
|
+
? typeof self === 'undefined'
|
|
21
|
+
? undefined
|
|
22
|
+
: self.ic.agent
|
|
23
|
+
: global.ic.agent
|
|
24
|
+
: window.ic.agent;
|
|
25
|
+
if (!agent) {
|
|
26
|
+
throw new Error('No Agent could be found.');
|
|
27
|
+
}
|
|
28
|
+
return agent;
|
|
29
|
+
}
|
|
30
|
+
exports.getDefaultAgent = getDefaultAgent;
|
|
31
|
+
function getKraken() {
|
|
32
|
+
const kraken = typeof window === 'undefined'
|
|
33
|
+
? typeof global === 'undefined'
|
|
34
|
+
? typeof self === 'undefined'
|
|
35
|
+
? undefined
|
|
36
|
+
: self.kraken
|
|
37
|
+
: global.kraken
|
|
38
|
+
: window.kraken;
|
|
39
|
+
return kraken;
|
|
40
|
+
}
|
|
41
|
+
exports.getKraken = getKraken;
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agent/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAGA,wCAAsB;AACtB,yCAAuB;AACvB,0CAAwB;AAMxB,SAAgB,eAAe;IAC7B,MAAM,KAAK,GACT,OAAO,MAAM,KAAK,WAAW;QAC3B,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW;YAC7B,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;gBAC3B,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK;YACjB,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK;QACnB,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC;IAEtB,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;KAC7C;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAfD,0CAeC;AAED,SAAgB,SAAS;IACvB,MAAM,MAAM,GACV,OAAO,MAAM,KAAK,WAAW;QAC3B,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW;YAC7B,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;gBAC3B,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,IAAI,CAAC,MAAM;YACf,CAAC,CAAC,MAAM,CAAC,MAAM;QACjB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IAEpB,OAAO,MAAM,CAAC;AAChB,CAAC;AAXD,8BAWC"}
|