@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,328 @@
|
|
|
1
|
+
import { getKraken } from '@astrox/agent';
|
|
2
|
+
import { Principal } from '@astrox/principal';
|
|
3
|
+
import { AnonymousIdentity } from '../../auth';
|
|
4
|
+
import * as cbor from '../../cbor';
|
|
5
|
+
import { requestIdOf } from '../../request_id';
|
|
6
|
+
import { fromHex, toHex } from '../../utils/buffer';
|
|
7
|
+
import { Expiry } from './transforms';
|
|
8
|
+
import { SubmitRequestType, } from './types';
|
|
9
|
+
export * from './transforms';
|
|
10
|
+
export { makeNonce } from './types';
|
|
11
|
+
export var RequestStatusResponseStatus;
|
|
12
|
+
(function (RequestStatusResponseStatus) {
|
|
13
|
+
RequestStatusResponseStatus["Received"] = "received";
|
|
14
|
+
RequestStatusResponseStatus["Processing"] = "processing";
|
|
15
|
+
RequestStatusResponseStatus["Replied"] = "replied";
|
|
16
|
+
RequestStatusResponseStatus["Rejected"] = "rejected";
|
|
17
|
+
RequestStatusResponseStatus["Unknown"] = "unknown";
|
|
18
|
+
RequestStatusResponseStatus["Done"] = "done";
|
|
19
|
+
})(RequestStatusResponseStatus || (RequestStatusResponseStatus = {}));
|
|
20
|
+
// Default delta for ingress expiry is 5 minutes.
|
|
21
|
+
const DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS = 5 * 60 * 1000;
|
|
22
|
+
// Root public key for the IC, encoded as hex
|
|
23
|
+
const IC_ROOT_KEY = '308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814' +
|
|
24
|
+
'c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d968' +
|
|
25
|
+
'5f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484' +
|
|
26
|
+
'b01291091c5f87b98883463f98091a0baaae';
|
|
27
|
+
function getDefaultFetch() {
|
|
28
|
+
const result = typeof window === 'undefined'
|
|
29
|
+
? typeof global === 'undefined'
|
|
30
|
+
? typeof self === 'undefined'
|
|
31
|
+
? undefined
|
|
32
|
+
: self.fetch.bind(self)
|
|
33
|
+
: global.fetch.bind(global)
|
|
34
|
+
: window.fetch.bind(window);
|
|
35
|
+
if (!result) {
|
|
36
|
+
throw new Error('Could not find default `fetch` implementation.');
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
function getKrakenFetch() {
|
|
41
|
+
if (getKraken()) {
|
|
42
|
+
const result = typeof window === 'undefined'
|
|
43
|
+
? typeof global === 'undefined'
|
|
44
|
+
? typeof self === 'undefined'
|
|
45
|
+
? undefined
|
|
46
|
+
: self.fetchAgent.bind(self)
|
|
47
|
+
: global.fetchAgent.bind(global)
|
|
48
|
+
: window.fetchAgent.bind(window);
|
|
49
|
+
if (!result) {
|
|
50
|
+
throw new Error('Could not find default `fetch` implementation.');
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return getDefaultFetch();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// A HTTP agent allows users to interact with a client of the internet computer
|
|
59
|
+
// using the available methods. It exposes an API that closely follows the
|
|
60
|
+
// public view of the internet computer, and is not intended to be exposed
|
|
61
|
+
// directly to the majority of users due to its low-level interface.
|
|
62
|
+
//
|
|
63
|
+
// There is a pipeline to apply transformations to the request before sending
|
|
64
|
+
// it to the client. This is to decouple signature, nonce generation and
|
|
65
|
+
// other computations so that this class can stay as simple as possible while
|
|
66
|
+
// allowing extensions.
|
|
67
|
+
export class HttpAgent {
|
|
68
|
+
constructor(options = {}) {
|
|
69
|
+
this.rootKey = fromHex(IC_ROOT_KEY);
|
|
70
|
+
this._pipeline = [];
|
|
71
|
+
this._rootKeyFetched = false;
|
|
72
|
+
if (options.source) {
|
|
73
|
+
if (!(options.source instanceof HttpAgent)) {
|
|
74
|
+
throw new Error("An Agent's source can only be another HttpAgent");
|
|
75
|
+
}
|
|
76
|
+
this._pipeline = [...options.source._pipeline];
|
|
77
|
+
this._identity = options.source._identity;
|
|
78
|
+
this._fetch = options.source._fetch;
|
|
79
|
+
this._fetchAgent = options.source._fetchAgent;
|
|
80
|
+
this._host = options.source._host;
|
|
81
|
+
this._credentials = options.source._credentials;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this._fetch = options.fetch || getDefaultFetch() || fetch.bind(global);
|
|
85
|
+
this._fetchAgent = options.fetchAgent || getKrakenFetch() || fetch.bind(global);
|
|
86
|
+
}
|
|
87
|
+
if (options.host !== undefined) {
|
|
88
|
+
if (!options.host.match(/^[a-z]+:/) && typeof window !== 'undefined') {
|
|
89
|
+
this._host = new URL(window.location.protocol + '//' + options.host);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this._host = new URL(options.host);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else if (options.source !== undefined) {
|
|
96
|
+
// Safe to ignore here.
|
|
97
|
+
this._host = options.source._host;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const location = typeof window !== 'undefined' ? window.location : undefined;
|
|
101
|
+
if (!location) {
|
|
102
|
+
throw new Error('Must specify a host to connect to.');
|
|
103
|
+
}
|
|
104
|
+
this._host = new URL(location + '');
|
|
105
|
+
}
|
|
106
|
+
if (options.credentials) {
|
|
107
|
+
const { name, password } = options.credentials;
|
|
108
|
+
this._credentials = `${name}${password ? ':' + password : ''}`;
|
|
109
|
+
}
|
|
110
|
+
this._identity = Promise.resolve(options.identity || new AnonymousIdentity());
|
|
111
|
+
}
|
|
112
|
+
addTransform(fn, priority = fn.priority || 0) {
|
|
113
|
+
// Keep the pipeline sorted at all time, by priority.
|
|
114
|
+
const i = this._pipeline.findIndex(x => (x.priority || 0) < priority);
|
|
115
|
+
this._pipeline.splice(i >= 0 ? i : this._pipeline.length, 0, Object.assign(fn, { priority }));
|
|
116
|
+
}
|
|
117
|
+
async getPrincipal() {
|
|
118
|
+
return (await this._identity).getPrincipal();
|
|
119
|
+
}
|
|
120
|
+
async call(canisterId, options, identity) {
|
|
121
|
+
const id = (await (identity !== undefined ? await identity : await this._identity));
|
|
122
|
+
const canister = Principal.from(canisterId);
|
|
123
|
+
const ecid = options.effectiveCanisterId
|
|
124
|
+
? Principal.from(options.effectiveCanisterId)
|
|
125
|
+
: canister;
|
|
126
|
+
const sender = id.getPrincipal() || Principal.anonymous();
|
|
127
|
+
const submit = {
|
|
128
|
+
request_type: SubmitRequestType.Call,
|
|
129
|
+
canister_id: canister,
|
|
130
|
+
method_name: options.methodName,
|
|
131
|
+
arg: options.arg,
|
|
132
|
+
sender,
|
|
133
|
+
ingress_expiry: new Expiry(DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS),
|
|
134
|
+
};
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
136
|
+
let transformedRequest = (await this._transform({
|
|
137
|
+
request: {
|
|
138
|
+
body: null,
|
|
139
|
+
method: 'POST',
|
|
140
|
+
headers: Object.assign({ 'Content-Type': 'application/cbor' }, (this._credentials ? { Authorization: 'Basic ' + btoa(this._credentials) } : {})),
|
|
141
|
+
},
|
|
142
|
+
endpoint: "call" /* Call */,
|
|
143
|
+
body: submit,
|
|
144
|
+
}));
|
|
145
|
+
// Apply transform for identity.
|
|
146
|
+
transformedRequest = await id.transformRequest(transformedRequest);
|
|
147
|
+
const body = cbor.encode(transformedRequest.body);
|
|
148
|
+
const kraken = getKraken();
|
|
149
|
+
if (!kraken) {
|
|
150
|
+
// Run both in parallel. The fetch is quite expensive, so we have plenty of time to
|
|
151
|
+
// calculate the requestId locally.
|
|
152
|
+
const [response, requestId] = await Promise.all([
|
|
153
|
+
this._fetch('' + new URL(`/api/v2/canister/${ecid.toText()}/call`, this._host), Object.assign(Object.assign({}, transformedRequest.request), { body })),
|
|
154
|
+
requestIdOf(submit),
|
|
155
|
+
]);
|
|
156
|
+
console.log('astorx call');
|
|
157
|
+
if (!response.ok) {
|
|
158
|
+
throw new Error(`Server returned an error:\n` +
|
|
159
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
160
|
+
` Body: ${await response.text()}\n`);
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
requestId,
|
|
164
|
+
response: {
|
|
165
|
+
ok: response.ok,
|
|
166
|
+
status: response.status,
|
|
167
|
+
statusText: response.statusText,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
const [response, requestId] = await Promise.all([
|
|
173
|
+
this._fetchAgent('' + new URL(`/api/v2/canister/${ecid.toText()}/call`, this._host), Object.assign(Object.assign({}, transformedRequest.request), { body: toHex(body) })),
|
|
174
|
+
requestIdOf(submit),
|
|
175
|
+
]);
|
|
176
|
+
if (!response.ok) {
|
|
177
|
+
throw new Error(`Server returned an error:\n` +
|
|
178
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
179
|
+
` Body: ${response.body}\n`);
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
requestId,
|
|
183
|
+
response: {
|
|
184
|
+
ok: response.ok,
|
|
185
|
+
status: response.status,
|
|
186
|
+
statusText: response.statusText,
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async query(canisterId, fields, identity) {
|
|
192
|
+
const id = await (identity !== undefined ? await identity : await this._identity);
|
|
193
|
+
const canister = typeof canisterId === 'string' ? Principal.fromText(canisterId) : canisterId;
|
|
194
|
+
const sender = (id === null || id === void 0 ? void 0 : id.getPrincipal()) || Principal.anonymous();
|
|
195
|
+
const request = {
|
|
196
|
+
request_type: "query" /* Query */,
|
|
197
|
+
canister_id: canister,
|
|
198
|
+
method_name: fields.methodName,
|
|
199
|
+
arg: fields.arg,
|
|
200
|
+
sender,
|
|
201
|
+
ingress_expiry: new Expiry(DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS),
|
|
202
|
+
};
|
|
203
|
+
// TODO: remove this any. This can be a Signed or UnSigned request.
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
205
|
+
let transformedRequest = await this._transform({
|
|
206
|
+
request: {
|
|
207
|
+
method: 'POST',
|
|
208
|
+
headers: Object.assign({ 'Content-Type': 'application/cbor' }, (this._credentials ? { Authorization: 'Basic ' + btoa(this._credentials) } : {})),
|
|
209
|
+
},
|
|
210
|
+
endpoint: "read" /* Query */,
|
|
211
|
+
body: request,
|
|
212
|
+
});
|
|
213
|
+
// Apply transform for identity.
|
|
214
|
+
transformedRequest = await id.transformRequest(transformedRequest);
|
|
215
|
+
const body = cbor.encode(transformedRequest.body);
|
|
216
|
+
const kraken = getKraken();
|
|
217
|
+
if (!kraken) {
|
|
218
|
+
const response = await this._fetch('' + new URL(`/api/v2/canister/${canister.toText()}/query`, this._host), Object.assign(Object.assign({}, transformedRequest.request), { body }));
|
|
219
|
+
console.log('astorx query');
|
|
220
|
+
if (!response.ok) {
|
|
221
|
+
throw new Error(`Server returned an error:\n` +
|
|
222
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
223
|
+
` Body: ${await response.text()}\n`);
|
|
224
|
+
}
|
|
225
|
+
return cbor.decode(await response.arrayBuffer());
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
const response = await this._fetchAgent('' + new URL(`/api/v2/canister/${canister.toText()}/query`, this._host), Object.assign(Object.assign({}, transformedRequest.request), { body: toHex(body) }));
|
|
229
|
+
console.log('astrox query');
|
|
230
|
+
if (!response.ok) {
|
|
231
|
+
throw new Error(`Server returned an error:\n` +
|
|
232
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
233
|
+
` Body: ${response.body}\n`);
|
|
234
|
+
}
|
|
235
|
+
return cbor.decode(fromHex(response.body));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async readState(canisterId, fields, identity) {
|
|
239
|
+
const canister = typeof canisterId === 'string' ? Principal.fromText(canisterId) : canisterId;
|
|
240
|
+
const id = await (identity !== undefined ? await identity : await this._identity);
|
|
241
|
+
const sender = (id === null || id === void 0 ? void 0 : id.getPrincipal()) || Principal.anonymous();
|
|
242
|
+
// TODO: remove this any. This can be a Signed or UnSigned request.
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
244
|
+
let transformedRequest = await this._transform({
|
|
245
|
+
request: {
|
|
246
|
+
method: 'POST',
|
|
247
|
+
headers: Object.assign({ 'Content-Type': 'application/cbor' }, (this._credentials ? { Authorization: 'Basic ' + btoa(this._credentials) } : {})),
|
|
248
|
+
},
|
|
249
|
+
endpoint: "read_state" /* ReadState */,
|
|
250
|
+
body: {
|
|
251
|
+
request_type: "read_state" /* ReadState */,
|
|
252
|
+
paths: fields.paths,
|
|
253
|
+
sender,
|
|
254
|
+
ingress_expiry: new Expiry(DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS),
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
// Apply transform for identity.
|
|
258
|
+
transformedRequest = await id.transformRequest(transformedRequest);
|
|
259
|
+
const body = cbor.encode(transformedRequest.body);
|
|
260
|
+
const kraken = getKraken();
|
|
261
|
+
if (!kraken) {
|
|
262
|
+
const response = await this._fetch('' + new URL(`/api/v2/canister/${canister}/read_state`, this._host), Object.assign(Object.assign({}, transformedRequest.request), { body }));
|
|
263
|
+
console.log('astorx read_state');
|
|
264
|
+
if (!response.ok) {
|
|
265
|
+
throw new Error(`Server returned an error:\n` +
|
|
266
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
267
|
+
` Body: ${await response.text()}\n`);
|
|
268
|
+
}
|
|
269
|
+
return cbor.decode(await response.arrayBuffer());
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
const response = await this._fetchAgent('' + new URL(`/api/v2/canister/${canister}/read_state`, this._host), Object.assign(Object.assign({}, transformedRequest.request), { body: toHex(body) }));
|
|
273
|
+
console.log('astorx read_state');
|
|
274
|
+
if (!response.ok) {
|
|
275
|
+
throw new Error(`Server returned an error:\n` +
|
|
276
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
277
|
+
` Body: ${response.body}\n`);
|
|
278
|
+
}
|
|
279
|
+
return cbor.decode(fromHex(response.body));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async status() {
|
|
283
|
+
const headers = this._credentials
|
|
284
|
+
? {
|
|
285
|
+
Authorization: 'Basic ' + btoa(this._credentials),
|
|
286
|
+
}
|
|
287
|
+
: {};
|
|
288
|
+
const kraken = getKraken();
|
|
289
|
+
if (!kraken) {
|
|
290
|
+
const response = await this._fetch('' + new URL(`/api/v2/status`, this._host), { headers });
|
|
291
|
+
console.log('astorx status');
|
|
292
|
+
if (!response.ok) {
|
|
293
|
+
throw new Error(`Server returned an error:\n` +
|
|
294
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
295
|
+
` Body: ${await response.text()}\n`);
|
|
296
|
+
}
|
|
297
|
+
return cbor.decode(await response.arrayBuffer());
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
const response = await this._fetchAgent('' + new URL(`/api/v2/status`, this._host), {
|
|
301
|
+
headers,
|
|
302
|
+
});
|
|
303
|
+
console.log('astrox status');
|
|
304
|
+
if (!response.ok) {
|
|
305
|
+
throw new Error(`Server returned an error:\n` +
|
|
306
|
+
` Code: ${response.status} (${response.statusText})\n` +
|
|
307
|
+
` Body: ${response.body}\n`);
|
|
308
|
+
}
|
|
309
|
+
return cbor.decode(fromHex(response.body));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
async fetchRootKey() {
|
|
313
|
+
if (!this._rootKeyFetched) {
|
|
314
|
+
// Hex-encoded version of the replica root key
|
|
315
|
+
this.rootKey = (await this.status()).root_key;
|
|
316
|
+
this._rootKeyFetched = true;
|
|
317
|
+
}
|
|
318
|
+
return this.rootKey;
|
|
319
|
+
}
|
|
320
|
+
_transform(request) {
|
|
321
|
+
let p = Promise.resolve(request);
|
|
322
|
+
for (const fn of this._pipeline) {
|
|
323
|
+
p = p.then(r => fn(r).then(r2 => r2 || r));
|
|
324
|
+
}
|
|
325
|
+
return p;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/agent/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAY,MAAM,YAAY,CAAC;AACzD,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AASpD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAQL,iBAAiB,GAClB,MAAM,SAAS,CAAC;AAEjB,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAS,SAAS,EAAE,MAAM,SAAS,CAAC;AAE3C,MAAM,CAAN,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,KAA3B,2BAA2B,QAOtC;AAED,iDAAiD;AACjD,MAAM,qCAAqC,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAE5D,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,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEjC,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,SAAS,EAAE;YAC/B,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;SAC5C;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF"}
|
|
@@ -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,45 @@
|
|
|
1
|
+
import { lebEncode } from '@astrox/candid';
|
|
2
|
+
import * as cbor from 'simple-cbor';
|
|
3
|
+
import { makeNonce } from './types';
|
|
4
|
+
const NANOSECONDS_PER_MILLISECONDS = BigInt(1000000);
|
|
5
|
+
const REPLICA_PERMITTED_DRIFT_MILLISECONDS = BigInt(60 * 1000);
|
|
6
|
+
export class Expiry {
|
|
7
|
+
constructor(deltaInMSec) {
|
|
8
|
+
// Use bigint because it can overflow the maximum number allowed in a double float.
|
|
9
|
+
this._value =
|
|
10
|
+
(BigInt(Date.now()) + BigInt(deltaInMSec) - REPLICA_PERMITTED_DRIFT_MILLISECONDS) *
|
|
11
|
+
NANOSECONDS_PER_MILLISECONDS;
|
|
12
|
+
}
|
|
13
|
+
toCBOR() {
|
|
14
|
+
// TODO: change this to take the minimum amount of space (it always takes 8 bytes now).
|
|
15
|
+
return cbor.value.u64(this._value.toString(16), 16);
|
|
16
|
+
}
|
|
17
|
+
toHash() {
|
|
18
|
+
return lebEncode(this._value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a Nonce transform, which takes a function that returns a Buffer, and adds it
|
|
23
|
+
* as the nonce to every call requests.
|
|
24
|
+
* @param nonceFn A function that returns a buffer. By default uses a semi-random method.
|
|
25
|
+
*/
|
|
26
|
+
export function makeNonceTransform(nonceFn = makeNonce) {
|
|
27
|
+
return async (request) => {
|
|
28
|
+
// Nonce are only useful for async calls, to prevent replay attacks. Other types of
|
|
29
|
+
// calls don't need Nonce so we just skip creating one.
|
|
30
|
+
if (request.endpoint === "call" /* Call */) {
|
|
31
|
+
request.body.nonce = nonceFn();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create a transform that adds a delay (by default 5 minutes) to the expiry.
|
|
37
|
+
*
|
|
38
|
+
* @param delayInMilliseconds The delay to add to the call time, in milliseconds.
|
|
39
|
+
*/
|
|
40
|
+
export function makeExpiryTransform(delayInMilliseconds) {
|
|
41
|
+
return async (request) => {
|
|
42
|
+
request.body.ingress_expiry = new Expiry(delayInMilliseconds);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=transforms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transforms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,CAAC;IAChE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -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,20 @@
|
|
|
1
|
+
// tslint:enable:camel-case
|
|
2
|
+
// The types of values allowed in the `request_type` field for submit requests.
|
|
3
|
+
export var SubmitRequestType;
|
|
4
|
+
(function (SubmitRequestType) {
|
|
5
|
+
SubmitRequestType["Call"] = "call";
|
|
6
|
+
})(SubmitRequestType || (SubmitRequestType = {}));
|
|
7
|
+
/**
|
|
8
|
+
* Create a random Nonce, based on date and a random suffix.
|
|
9
|
+
*/
|
|
10
|
+
export function makeNonce() {
|
|
11
|
+
// Encode 128 bits.
|
|
12
|
+
const buffer = new ArrayBuffer(16);
|
|
13
|
+
const view = new DataView(buffer);
|
|
14
|
+
const value = BigInt(+Date.now()) * BigInt(100000) + BigInt(Math.floor(Math.random() * 100000));
|
|
15
|
+
view.setBigUint64(0, value);
|
|
16
|
+
// tslint:disable-next-line:no-bitwise
|
|
17
|
+
view.setBigUint64(1, value >> BigInt(64));
|
|
18
|
+
return buffer;
|
|
19
|
+
}
|
|
20
|
+
//# 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,MAAM,CAAN,IAAY,iBAEX;AAFD,WAAY,iBAAiB;IAC3B,kCAAa,CAAA;AACf,CAAC,EAFW,iBAAiB,KAAjB,iBAAiB,QAE5B;AA8BD;;GAEG;AACH,MAAM,UAAU,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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from './api';
|
|
2
|
+
export * from './http';
|
|
3
|
+
export * from './proxy';
|
|
4
|
+
export function getDefaultAgent() {
|
|
5
|
+
const agent = typeof window === 'undefined'
|
|
6
|
+
? typeof global === 'undefined'
|
|
7
|
+
? typeof self === 'undefined'
|
|
8
|
+
? undefined
|
|
9
|
+
: self.ic.agent
|
|
10
|
+
: global.ic.agent
|
|
11
|
+
: window.ic.agent;
|
|
12
|
+
if (!agent) {
|
|
13
|
+
throw new Error('No Agent could be found.');
|
|
14
|
+
}
|
|
15
|
+
return agent;
|
|
16
|
+
}
|
|
17
|
+
export function getKraken() {
|
|
18
|
+
const kraken = typeof window === 'undefined'
|
|
19
|
+
? typeof global === 'undefined'
|
|
20
|
+
? typeof self === 'undefined'
|
|
21
|
+
? undefined
|
|
22
|
+
: self.kraken
|
|
23
|
+
: global.kraken
|
|
24
|
+
: window.kraken;
|
|
25
|
+
return kraken;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agent/index.ts"],"names":[],"mappings":"AAGA,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AAMxB,MAAM,UAAU,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;AAED,MAAM,UAAU,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"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { CallOptions, QueryFields, QueryResponse, ReadStateOptions, ReadStateResponse, SubmitResponse } from '..';
|
|
2
|
+
import { JsonObject } from '@astrox/candid';
|
|
3
|
+
import { Agent } from './api';
|
|
4
|
+
import { Principal } from '@astrox/principal';
|
|
5
|
+
export declare enum ProxyMessageKind {
|
|
6
|
+
Error = "err",
|
|
7
|
+
GetPrincipal = "gp",
|
|
8
|
+
GetPrincipalResponse = "gpr",
|
|
9
|
+
Query = "q",
|
|
10
|
+
QueryResponse = "qr",
|
|
11
|
+
Call = "c",
|
|
12
|
+
CallResponse = "cr",
|
|
13
|
+
ReadState = "rs",
|
|
14
|
+
ReadStateResponse = "rsr",
|
|
15
|
+
Status = "s",
|
|
16
|
+
StatusResponse = "sr"
|
|
17
|
+
}
|
|
18
|
+
export interface ProxyMessageBase {
|
|
19
|
+
id: number;
|
|
20
|
+
type: ProxyMessageKind;
|
|
21
|
+
}
|
|
22
|
+
export interface ProxyMessageError extends ProxyMessageBase {
|
|
23
|
+
type: ProxyMessageKind.Error;
|
|
24
|
+
error: any;
|
|
25
|
+
}
|
|
26
|
+
export interface ProxyMessageGetPrincipal extends ProxyMessageBase {
|
|
27
|
+
type: ProxyMessageKind.GetPrincipal;
|
|
28
|
+
}
|
|
29
|
+
export interface ProxyMessageGetPrincipalResponse extends ProxyMessageBase {
|
|
30
|
+
type: ProxyMessageKind.GetPrincipalResponse;
|
|
31
|
+
response: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ProxyMessageQuery extends ProxyMessageBase {
|
|
34
|
+
type: ProxyMessageKind.Query;
|
|
35
|
+
args: [string, QueryFields];
|
|
36
|
+
}
|
|
37
|
+
export interface ProxyMessageQueryResponse extends ProxyMessageBase {
|
|
38
|
+
type: ProxyMessageKind.QueryResponse;
|
|
39
|
+
response: QueryResponse;
|
|
40
|
+
}
|
|
41
|
+
export interface ProxyMessageCall extends ProxyMessageBase {
|
|
42
|
+
type: ProxyMessageKind.Call;
|
|
43
|
+
args: [string, CallOptions];
|
|
44
|
+
}
|
|
45
|
+
export interface ProxyMessageCallResponse extends ProxyMessageBase {
|
|
46
|
+
type: ProxyMessageKind.CallResponse;
|
|
47
|
+
response: SubmitResponse;
|
|
48
|
+
}
|
|
49
|
+
export interface ProxyMessageReadState extends ProxyMessageBase {
|
|
50
|
+
type: ProxyMessageKind.ReadState;
|
|
51
|
+
args: [string, ReadStateOptions];
|
|
52
|
+
}
|
|
53
|
+
export interface ProxyMessageReadStateResponse extends ProxyMessageBase {
|
|
54
|
+
type: ProxyMessageKind.ReadStateResponse;
|
|
55
|
+
response: ReadStateResponse;
|
|
56
|
+
}
|
|
57
|
+
export interface ProxyMessageStatus extends ProxyMessageBase {
|
|
58
|
+
type: ProxyMessageKind.Status;
|
|
59
|
+
}
|
|
60
|
+
export interface ProxyMessageStatusResponse extends ProxyMessageBase {
|
|
61
|
+
type: ProxyMessageKind.StatusResponse;
|
|
62
|
+
response: JsonObject;
|
|
63
|
+
}
|
|
64
|
+
export declare type ProxyMessage = ProxyMessageError | ProxyMessageGetPrincipal | ProxyMessageGetPrincipalResponse | ProxyMessageQuery | ProxyMessageQueryResponse | ProxyMessageCall | ProxyMessageReadState | ProxyMessageReadStateResponse | ProxyMessageCallResponse | ProxyMessageStatus | ProxyMessageStatusResponse;
|
|
65
|
+
export declare class ProxyStubAgent {
|
|
66
|
+
private _frontend;
|
|
67
|
+
private _agent;
|
|
68
|
+
constructor(_frontend: (msg: ProxyMessage) => void, _agent: Agent);
|
|
69
|
+
onmessage(msg: ProxyMessage): void;
|
|
70
|
+
}
|
|
71
|
+
export declare class ProxyAgent implements Agent {
|
|
72
|
+
private _backend;
|
|
73
|
+
private _nextId;
|
|
74
|
+
private _pendingCalls;
|
|
75
|
+
rootKey: null;
|
|
76
|
+
constructor(_backend: (msg: ProxyMessage) => void);
|
|
77
|
+
onmessage(msg: ProxyMessage): void;
|
|
78
|
+
getPrincipal(): Promise<Principal>;
|
|
79
|
+
readState(canisterId: Principal | string, fields: ReadStateOptions): Promise<ReadStateResponse>;
|
|
80
|
+
call(canisterId: Principal | string, fields: CallOptions): Promise<SubmitResponse>;
|
|
81
|
+
status(): Promise<JsonObject>;
|
|
82
|
+
query(canisterId: Principal | string, fields: QueryFields): Promise<QueryResponse>;
|
|
83
|
+
private _sendAndWait;
|
|
84
|
+
fetchRootKey(): Promise<ArrayBuffer>;
|
|
85
|
+
}
|