@keetanetwork/anchor 0.0.6 → 0.0.8
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/client/index.d.ts +6 -0
- package/client/index.d.ts.map +1 -1
- package/client/index.js +7 -0
- package/client/index.js.map +1 -1
- package/lib/resolver.d.ts +59 -18
- package/lib/resolver.d.ts.map +1 -1
- package/lib/resolver.js +1368 -309
- package/lib/resolver.js.map +1 -1
- package/npm-shrinkwrap.json +5 -5
- package/package.json +2 -2
- package/services/asset-movement/client.d.ts +106 -0
- package/services/asset-movement/client.d.ts.map +1 -0
- package/services/asset-movement/client.js +279 -0
- package/services/asset-movement/client.js.map +1 -0
- package/services/asset-movement/common.d.ts +229 -0
- package/services/asset-movement/common.d.ts.map +1 -0
- package/services/asset-movement/common.js +2776 -0
- package/services/asset-movement/common.js.map +1 -0
- package/services/asset-movement/server.d.ts +60 -0
- package/services/asset-movement/server.d.ts.map +1 -0
- package/services/asset-movement/server.js +143 -0
- package/services/asset-movement/server.js.map +1 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';
|
|
2
|
+
import { getDefaultResolver } from '../../config.js';
|
|
3
|
+
import type { UserClient as KeetaNetUserClient } from '@keetanetwork/keetanet-client';
|
|
4
|
+
import type { KeetaAssetMovementAnchorInitiateTransferRequest, KeetaAssetMovementAnchorGetTransferStatusRequest, KeetaAssetMovementAnchorGetTransferStatusResponse, KeetaAssetMovementAnchorCreatePersistentForwardingRequest, KeetaAssetMovementAnchorCreatePersistentForwardingResponse, SupportedAssets, ProviderSearchInput, KeetaAssetMovementAnchorlistTransactionsRequest, KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse, AssetTransferInstructions } from './common.js';
|
|
5
|
+
import type { Logger } from '../../lib/log/index.ts';
|
|
6
|
+
import Resolver from "../../lib/resolver.js";
|
|
7
|
+
import type { ServiceMetadata } from '../../lib/resolver.ts';
|
|
8
|
+
import type { BrandedString } from '../../lib/utils/brand.js';
|
|
9
|
+
/**
|
|
10
|
+
* The configuration options for the Asset Movement (Inbound/Outbound) Anchor client.
|
|
11
|
+
*/
|
|
12
|
+
export type KeetaAssetMovementClientConfig = {
|
|
13
|
+
/**
|
|
14
|
+
* The ID of the client. This is used to identify the client in logs.
|
|
15
|
+
* If not provided, a random ID will be generated.
|
|
16
|
+
*/
|
|
17
|
+
id?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The logger to use for logging messages. If not provided, no logging
|
|
20
|
+
* will be done.
|
|
21
|
+
*/
|
|
22
|
+
logger?: Logger;
|
|
23
|
+
/**
|
|
24
|
+
* The resolver to use for resolving Asset Movement Anchor services. If not
|
|
25
|
+
* provided, a default resolver will be created using the provided
|
|
26
|
+
* client and network (if the network is also not provided and the
|
|
27
|
+
* client is not a UserClient, an error occurs).
|
|
28
|
+
*/
|
|
29
|
+
resolver?: Resolver;
|
|
30
|
+
/**
|
|
31
|
+
* The account to use for signing requests. If not provided, the
|
|
32
|
+
* account associated with the provided client will be used. If there
|
|
33
|
+
* is no account associated with the client, an error occurs.
|
|
34
|
+
*/
|
|
35
|
+
signer?: InstanceType<typeof KeetaNetLib.Account>;
|
|
36
|
+
/**
|
|
37
|
+
* Account to perform changes on. If not provided, the account
|
|
38
|
+
* associated with the provided client will be used. If there is no
|
|
39
|
+
* account associated with the client, an error occurs.
|
|
40
|
+
*/
|
|
41
|
+
account?: InstanceType<typeof KeetaNetLib.Account>;
|
|
42
|
+
} & Omit<NonNullable<Parameters<typeof getDefaultResolver>[1]>, 'client'>;
|
|
43
|
+
/**
|
|
44
|
+
* An opaque type that represents a provider ID.
|
|
45
|
+
*/
|
|
46
|
+
type ProviderID = BrandedString<'AssetMovementProviderID'>;
|
|
47
|
+
/**
|
|
48
|
+
* A list of operations that can be performed by the Asset Movement Anchor service.
|
|
49
|
+
*/
|
|
50
|
+
type KeetaAssetMovementAnchorOperations = {
|
|
51
|
+
[operation in keyof NonNullable<ServiceMetadata['services']['assetMovement']>[string]['operations']]?: (params?: {
|
|
52
|
+
[key: string]: string;
|
|
53
|
+
}) => URL;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The service information for a KYC Anchor service.
|
|
57
|
+
*/
|
|
58
|
+
type KeetaAssetMovementServiceInfo = {
|
|
59
|
+
operations: {
|
|
60
|
+
[operation in keyof KeetaAssetMovementAnchorOperations]: Promise<KeetaAssetMovementAnchorOperations[operation]>;
|
|
61
|
+
};
|
|
62
|
+
supportedAssets: SupportedAssets[];
|
|
63
|
+
};
|
|
64
|
+
interface KeetaAssetMovementAnchorBaseConfig {
|
|
65
|
+
client: KeetaNetUserClient;
|
|
66
|
+
logger?: Logger | undefined;
|
|
67
|
+
}
|
|
68
|
+
declare class KeetaAssetMovementAnchorBase {
|
|
69
|
+
protected readonly logger?: Logger | undefined;
|
|
70
|
+
protected readonly client: KeetaNetUserClient;
|
|
71
|
+
constructor(config: KeetaAssetMovementAnchorBaseConfig);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Represents an in-progress Asset Movement request.
|
|
75
|
+
*/
|
|
76
|
+
declare class KeetaAssetMovementTransfer {
|
|
77
|
+
private readonly provider;
|
|
78
|
+
private request;
|
|
79
|
+
private transfer;
|
|
80
|
+
constructor(provider: KeetaAssetMovementAnchorProvider, request: KeetaAssetMovementAnchorInitiateTransferRequest, transfer: {
|
|
81
|
+
id: string;
|
|
82
|
+
instructionChoices: AssetTransferInstructions[];
|
|
83
|
+
});
|
|
84
|
+
getTransferStatus(): Promise<KeetaAssetMovementAnchorGetTransferStatusResponse>;
|
|
85
|
+
get transferId(): string;
|
|
86
|
+
get instructions(): AssetTransferInstructions[];
|
|
87
|
+
}
|
|
88
|
+
declare class KeetaAssetMovementAnchorProvider extends KeetaAssetMovementAnchorBase {
|
|
89
|
+
readonly serviceInfo: KeetaAssetMovementServiceInfo;
|
|
90
|
+
readonly providerID: ProviderID;
|
|
91
|
+
private readonly parent;
|
|
92
|
+
constructor(serviceInfo: KeetaAssetMovementServiceInfo, providerID: ProviderID, parent: KeetaAssetMovementAnchorClient);
|
|
93
|
+
initiateTransfer(request: KeetaAssetMovementAnchorInitiateTransferRequest): Promise<KeetaAssetMovementTransfer>;
|
|
94
|
+
getTransferStatus(request: KeetaAssetMovementAnchorGetTransferStatusRequest): Promise<KeetaAssetMovementAnchorGetTransferStatusResponse>;
|
|
95
|
+
createPersistentForwardingAddress(request: KeetaAssetMovementAnchorCreatePersistentForwardingRequest): Promise<KeetaAssetMovementAnchorCreatePersistentForwardingResponse | null>;
|
|
96
|
+
listTransactions(request: KeetaAssetMovementAnchorlistTransactionsRequest): Promise<KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse | null>;
|
|
97
|
+
}
|
|
98
|
+
declare class KeetaAssetMovementAnchorClient extends KeetaAssetMovementAnchorBase {
|
|
99
|
+
#private;
|
|
100
|
+
readonly resolver: Resolver;
|
|
101
|
+
readonly id: string;
|
|
102
|
+
constructor(client: KeetaNetUserClient, config?: KeetaAssetMovementClientConfig);
|
|
103
|
+
getProvidersForTransfer(request: ProviderSearchInput): Promise<KeetaAssetMovementAnchorProvider[] | null>;
|
|
104
|
+
}
|
|
105
|
+
export default KeetaAssetMovementAnchorClient;
|
|
106
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/services/asset-movement/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,KAAK,EACX,UAAU,IAAI,kBAAkB,EAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACX,+CAA+C,EAC/C,gDAAgD,EAChD,iDAAiD,EACjD,yDAAyD,EACzD,0DAA0D,EAC1D,eAAe,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IA6BxI,iCAAiC,CAAC,OAAO,EAAE,yDAAyD,GAAG,OAAO,CAAC,0DAA0D,GAAG,IAAI,CAAC;IAkCjL,gBAAgB,CAAC,OAAO,EAAE,+CAA+C,GAAG,OAAO,CAAC,oEAAoE,GAAG,IAAI,CAAC;CAiCtK;AAED,cAAM,8BAA+B,SAAQ,4BAA4B;;IACxE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;gBAMR,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAE,8BAAmC;IAwB7E,uBAAuB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,gCAAgC,EAAE,GAAG,IAAI,CAAC;CAyB/G;AAED,eAAe,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { getDefaultResolver } from '../../config.js';
|
|
2
|
+
import { assertKeetaSupportedAssets, convertAssetLocationToString, convertAssetSearchInputToCanonical, isKeetaAssetMovementAnchorCreatePersistentForwardingResponse, isKeetaAssetMovementAnchorGetExchangeStatusResponse, isKeetaAssetMovementAnchorInitiateTransferResponse, isKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse } from './common.js';
|
|
3
|
+
import Resolver from "../../lib/resolver.js";
|
|
4
|
+
import crypto from '../../lib/utils/crypto.js';
|
|
5
|
+
/**
|
|
6
|
+
* An opaque type that represents an Asset Movement Anchor request ID
|
|
7
|
+
*/
|
|
8
|
+
// type RequestID = BrandedString<'AssetMovementRequestID'>;
|
|
9
|
+
const KeetaAssetMovementAnchorClientAccessToken = Symbol('KeetaAssetMovementAnchorClientAccessToken');
|
|
10
|
+
function typedAssetMovementServiceEntries(obj) {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
12
|
+
return Object.entries(obj);
|
|
13
|
+
}
|
|
14
|
+
function validateURL(url) {
|
|
15
|
+
if (url === undefined || url === null) {
|
|
16
|
+
throw (new Error('Invalid URL: null or undefined'));
|
|
17
|
+
}
|
|
18
|
+
const parsedURL = new URL(url);
|
|
19
|
+
return (parsedURL);
|
|
20
|
+
}
|
|
21
|
+
async function getEndpoints(resolver, request) {
|
|
22
|
+
const asset = request.asset ? convertAssetSearchInputToCanonical(request.asset) : undefined;
|
|
23
|
+
if (asset === undefined) {
|
|
24
|
+
throw (new Error('asset it required to lookup provider'));
|
|
25
|
+
}
|
|
26
|
+
const from = request.from ? { from: convertAssetLocationToString(request.from) } : {};
|
|
27
|
+
const to = request.to ? { to: convertAssetLocationToString(request.to) } : {};
|
|
28
|
+
const response = await resolver.lookup('assetMovement', {
|
|
29
|
+
asset,
|
|
30
|
+
...from,
|
|
31
|
+
...to
|
|
32
|
+
});
|
|
33
|
+
if (response === undefined) {
|
|
34
|
+
return (null);
|
|
35
|
+
}
|
|
36
|
+
const serviceInfoPromises = Object.entries(response).map(async function ([id, serviceInfo]) {
|
|
37
|
+
const supportedAssetsMetadata = await Resolver.Metadata.fullyResolveValuizable(serviceInfo.supportedAssets);
|
|
38
|
+
const supportedAssets = assertKeetaSupportedAssets(supportedAssetsMetadata);
|
|
39
|
+
const operations = await serviceInfo.operations('object');
|
|
40
|
+
const operationsFunctions = {};
|
|
41
|
+
for (const [key, operation] of Object.entries(operations)) {
|
|
42
|
+
if (operation === undefined) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
Object.defineProperty(operationsFunctions, key, {
|
|
46
|
+
get: async function () {
|
|
47
|
+
const url = await operation('string');
|
|
48
|
+
return (function (params) {
|
|
49
|
+
let substitutedURL = url;
|
|
50
|
+
for (const [paramKey, paramValue] of Object.entries(params ?? {})) {
|
|
51
|
+
substitutedURL = substitutedURL.replace(`{${paramKey}}`, encodeURIComponent(paramValue));
|
|
52
|
+
}
|
|
53
|
+
return (validateURL(substitutedURL));
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return ([
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
62
|
+
id,
|
|
63
|
+
{
|
|
64
|
+
operations: operationsFunctions,
|
|
65
|
+
supportedAssets: supportedAssets
|
|
66
|
+
}
|
|
67
|
+
]);
|
|
68
|
+
});
|
|
69
|
+
const retval = Object.fromEntries(await Promise.all(serviceInfoPromises));
|
|
70
|
+
return (retval);
|
|
71
|
+
}
|
|
72
|
+
class KeetaAssetMovementAnchorBase {
|
|
73
|
+
logger;
|
|
74
|
+
client;
|
|
75
|
+
constructor(config) {
|
|
76
|
+
this.client = config.client;
|
|
77
|
+
this.logger = config.logger;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Represents an in-progress Asset Movement request.
|
|
82
|
+
*/
|
|
83
|
+
class KeetaAssetMovementTransfer {
|
|
84
|
+
provider;
|
|
85
|
+
request;
|
|
86
|
+
transfer;
|
|
87
|
+
constructor(provider, request, transfer) {
|
|
88
|
+
this.provider = provider;
|
|
89
|
+
this.request = request;
|
|
90
|
+
this.transfer = transfer;
|
|
91
|
+
}
|
|
92
|
+
async getTransferStatus() {
|
|
93
|
+
return (await this.provider.getTransferStatus({ id: this.transfer.id }));
|
|
94
|
+
}
|
|
95
|
+
get transferId() {
|
|
96
|
+
return (this.transfer.id);
|
|
97
|
+
}
|
|
98
|
+
get instructions() {
|
|
99
|
+
return (this.transfer.instructionChoices);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
class KeetaAssetMovementAnchorProvider extends KeetaAssetMovementAnchorBase {
|
|
103
|
+
serviceInfo;
|
|
104
|
+
providerID;
|
|
105
|
+
parent;
|
|
106
|
+
constructor(serviceInfo, providerID, parent) {
|
|
107
|
+
const parentPrivate = parent._internals(KeetaAssetMovementAnchorClientAccessToken);
|
|
108
|
+
super(parentPrivate);
|
|
109
|
+
this.serviceInfo = serviceInfo;
|
|
110
|
+
this.providerID = providerID;
|
|
111
|
+
this.parent = parent;
|
|
112
|
+
}
|
|
113
|
+
async initiateTransfer(request) {
|
|
114
|
+
this.logger?.debug(`Starting Asset Movement Transfer for provider ID: ${String(this.providerID)}, request: ${JSON.stringify(request)}`);
|
|
115
|
+
const endpoints = this.serviceInfo.operations;
|
|
116
|
+
const initiateTransfer = await endpoints.initiateTransfer;
|
|
117
|
+
if (initiateTransfer === undefined) {
|
|
118
|
+
throw (new Error('Asset Movement service does not support initiateTransfer operation'));
|
|
119
|
+
}
|
|
120
|
+
const initiateTransferURL = initiateTransfer();
|
|
121
|
+
const requestInformation = await fetch(initiateTransferURL, {
|
|
122
|
+
method: 'POST',
|
|
123
|
+
headers: {
|
|
124
|
+
'Content-Type': 'application/json',
|
|
125
|
+
'Accept': 'application/json'
|
|
126
|
+
},
|
|
127
|
+
body: JSON.stringify({
|
|
128
|
+
...request
|
|
129
|
+
})
|
|
130
|
+
});
|
|
131
|
+
const requestInformationJSON = await requestInformation.json();
|
|
132
|
+
if (!isKeetaAssetMovementAnchorInitiateTransferResponse(requestInformationJSON)) {
|
|
133
|
+
throw (new Error(`Invalid response from asset movement service: ${JSON.stringify(requestInformationJSON)}`));
|
|
134
|
+
}
|
|
135
|
+
if (!requestInformationJSON.ok) {
|
|
136
|
+
throw (new Error(`asset movement request failed: ${requestInformationJSON.error}`));
|
|
137
|
+
}
|
|
138
|
+
this.logger?.debug(`asset movement request successful, request ID ${requestInformationJSON.id}`);
|
|
139
|
+
const anchorTransfer = new KeetaAssetMovementTransfer(this, request, { id: requestInformationJSON.id, instructionChoices: requestInformationJSON.instructionChoices });
|
|
140
|
+
return (anchorTransfer);
|
|
141
|
+
}
|
|
142
|
+
async getTransferStatus(request) {
|
|
143
|
+
const endpoints = this.serviceInfo.operations;
|
|
144
|
+
const getTransferStatus = await endpoints.getTransferStatus;
|
|
145
|
+
if (getTransferStatus === undefined) {
|
|
146
|
+
throw (new Error('Asset Movement service does not support getTransferStatus operation'));
|
|
147
|
+
}
|
|
148
|
+
const getTransferURL = getTransferStatus({ id: request.id });
|
|
149
|
+
const requestInformation = await fetch(getTransferURL, {
|
|
150
|
+
method: 'GET',
|
|
151
|
+
headers: {
|
|
152
|
+
'Content-Type': 'application/json',
|
|
153
|
+
'Accept': 'application/json'
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
const requestInformationJSON = await requestInformation.json();
|
|
157
|
+
if (!isKeetaAssetMovementAnchorGetExchangeStatusResponse(requestInformationJSON)) {
|
|
158
|
+
throw (new Error(`Invalid response from asset movement service: ${JSON.stringify(requestInformationJSON)}`));
|
|
159
|
+
}
|
|
160
|
+
if (!requestInformationJSON.ok) {
|
|
161
|
+
throw (new Error(`asset movement request failed: ${requestInformationJSON.error}`));
|
|
162
|
+
}
|
|
163
|
+
this.logger?.debug(`asset movement request successful, request ID ${request.id}`);
|
|
164
|
+
return (requestInformationJSON);
|
|
165
|
+
}
|
|
166
|
+
async createPersistentForwardingAddress(request) {
|
|
167
|
+
this.logger?.debug(`Creating persistent forwarding for provider ID: ${String(this.providerID)}, request: ${JSON.stringify(request)}`);
|
|
168
|
+
const endpoints = this.serviceInfo.operations;
|
|
169
|
+
const createPersistentForwarding = await endpoints.createPersistentForwarding;
|
|
170
|
+
if (createPersistentForwarding === undefined) {
|
|
171
|
+
throw (new Error('Asset Movement service does not support createPersistentForwarding operation'));
|
|
172
|
+
}
|
|
173
|
+
const createPersistentForwardingURL = createPersistentForwarding();
|
|
174
|
+
const requestInformation = await fetch(createPersistentForwardingURL, {
|
|
175
|
+
method: 'POST',
|
|
176
|
+
headers: {
|
|
177
|
+
'Content-Type': 'application/json',
|
|
178
|
+
'Accept': 'application/json'
|
|
179
|
+
},
|
|
180
|
+
body: JSON.stringify({
|
|
181
|
+
...request
|
|
182
|
+
})
|
|
183
|
+
});
|
|
184
|
+
const requestInformationJSON = await requestInformation.json();
|
|
185
|
+
if (!isKeetaAssetMovementAnchorCreatePersistentForwardingResponse(requestInformationJSON)) {
|
|
186
|
+
throw (new Error(`Invalid response from create persistent forwarding request: ${JSON.stringify(requestInformationJSON)}`));
|
|
187
|
+
}
|
|
188
|
+
if (!requestInformationJSON.ok) {
|
|
189
|
+
throw (new Error(`create persistent forwarding request failed: ${requestInformationJSON.error}`));
|
|
190
|
+
}
|
|
191
|
+
this.logger?.debug(`create persistent forwarding request successful, ${requestInformationJSON.address}`);
|
|
192
|
+
return (requestInformationJSON);
|
|
193
|
+
}
|
|
194
|
+
async listTransactions(request) {
|
|
195
|
+
this.logger?.debug(`List persistent forwarding transactions provider ID: ${String(this.providerID)}, request: ${JSON.stringify(request)}`);
|
|
196
|
+
const endpoints = this.serviceInfo.operations;
|
|
197
|
+
const listTransactions = await endpoints.listTransactions;
|
|
198
|
+
if (listTransactions === undefined) {
|
|
199
|
+
throw (new Error('Asset Movement service does not support listTransactions operation'));
|
|
200
|
+
}
|
|
201
|
+
const listTransactionsURL = listTransactions();
|
|
202
|
+
const requestInformation = await fetch(listTransactionsURL, {
|
|
203
|
+
method: 'POST',
|
|
204
|
+
headers: {
|
|
205
|
+
'Content-Type': 'application/json',
|
|
206
|
+
'Accept': 'application/json'
|
|
207
|
+
},
|
|
208
|
+
body: JSON.stringify({
|
|
209
|
+
...request
|
|
210
|
+
})
|
|
211
|
+
});
|
|
212
|
+
const requestInformationJSON = await requestInformation.json();
|
|
213
|
+
if (!isKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse(requestInformationJSON)) {
|
|
214
|
+
throw (new Error(`Invalid response from list persistent transactions request: ${JSON.stringify(requestInformationJSON)}`));
|
|
215
|
+
}
|
|
216
|
+
if (!requestInformationJSON.ok) {
|
|
217
|
+
throw (new Error(`list persistent transactions request failed: ${requestInformationJSON.error}`));
|
|
218
|
+
}
|
|
219
|
+
this.logger?.debug(`list persistent transactions request successful, ${requestInformationJSON.transactions}`);
|
|
220
|
+
return (requestInformationJSON);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
class KeetaAssetMovementAnchorClient extends KeetaAssetMovementAnchorBase {
|
|
224
|
+
resolver;
|
|
225
|
+
id;
|
|
226
|
+
// eslint-disable-next-line no-unused-private-class-members
|
|
227
|
+
#signer;
|
|
228
|
+
// eslint-disable-next-line no-unused-private-class-members
|
|
229
|
+
#account;
|
|
230
|
+
constructor(client, config = {}) {
|
|
231
|
+
super({ client, logger: config.logger });
|
|
232
|
+
this.resolver = config.resolver ?? getDefaultResolver(client, config);
|
|
233
|
+
this.id = config.id ?? crypto.randomUUID();
|
|
234
|
+
if (config.signer) {
|
|
235
|
+
this.#signer = config.signer;
|
|
236
|
+
}
|
|
237
|
+
else if ('signer' in client && client.signer !== null) {
|
|
238
|
+
this.#signer = client.signer;
|
|
239
|
+
}
|
|
240
|
+
else if ('account' in client && client.account.hasPrivateKey) {
|
|
241
|
+
this.#signer = client.account;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
throw (new Error('KeetaAssetMovementAnchorClient requires a Signer or a UserClient with an associated Signer'));
|
|
245
|
+
}
|
|
246
|
+
if (config.account) {
|
|
247
|
+
this.#account = config.account;
|
|
248
|
+
}
|
|
249
|
+
else if ('account' in client) {
|
|
250
|
+
this.#account = client.account;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
throw (new Error('KeetaAssetMovementAnchorClient requires an Account or a UserClient with an associated Account'));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async getProvidersForTransfer(request) {
|
|
257
|
+
const endpoints = await getEndpoints(this.resolver, request);
|
|
258
|
+
if (endpoints === null) {
|
|
259
|
+
return (null);
|
|
260
|
+
}
|
|
261
|
+
const providers = typedAssetMovementServiceEntries(endpoints).map(([id, serviceInfo]) => {
|
|
262
|
+
return (new KeetaAssetMovementAnchorProvider(serviceInfo, id, this));
|
|
263
|
+
});
|
|
264
|
+
return (providers);
|
|
265
|
+
}
|
|
266
|
+
/** @internal */
|
|
267
|
+
_internals(accessToken) {
|
|
268
|
+
if (accessToken !== KeetaAssetMovementAnchorClientAccessToken) {
|
|
269
|
+
throw (new Error('invalid access token'));
|
|
270
|
+
}
|
|
271
|
+
return ({
|
|
272
|
+
resolver: this.resolver,
|
|
273
|
+
logger: this.logger,
|
|
274
|
+
client: this.client
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
export default KeetaAssetMovementAnchorClient;
|
|
279
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/services/asset-movement/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAiBrD,OAAO,EACN,0BAA0B,EAC1B,4BAA4B,EAC5B,kCAAkC,EAClC,4DAA4D,EAC5D,mDAAmD,EACnD,kDAAkD,EAClD,sEAAsE,EACtE,MAAM,aAAa,CAAC;AAErB,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAE7C,OAAO,MAAM,MAAM,2BAA2B,CAAC;AA6C/C;;GAEG;AACH,4DAA4D;AAE5D,MAAM,yCAAyC,GAAG,MAAM,CAAC,2CAA2C,CAAC,CAAC;AAEtG,SAAS,gCAAgC,CAAmB,GAAM;IACjE,yEAAyE;IACzE,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAA6B,CAAC;AACxD,CAAC;AA4BD,SAAS,WAAW,CAAC,GAAuB;IAC3C,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACvC,MAAK,CAAC,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAE/B,OAAM,CAAC,SAAS,CAAC,CAAC;AACnB,CAAC;AAED,KAAK,UAAU,YAAY,CAAC,QAAkB,EAAE,OAA4B;IAC3E,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,kCAAkC,CA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IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACxB,OAAM,CAAC,IAAI,CAAC,CAAC;QACd,CAAC;QAED,MAAM,SAAS,GAAG,gCAAgC,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,WAAW,CAAC,EAAE,EAAE;YACvF,OAAM,CAAC,IAAI,gCAAgC,CAAC,WAAW,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;QAEH,OAAM,CAAC,SAAS,CAAC,CAAC;IACnB,CAAC;IAED,gBAAgB;IAChB,UAAU,CAAC,WAAmB;QAC7B,IAAI,WAAW,KAAK,yCAAyC,EAAE,CAAC;YAC/D,MAAK,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC;QAC1C,CAAC;QAED,OAAM,CAAC;YACN,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI,CAAC,MAAM;SACnB,CAAC,CAAC;IACJ,CAAC;CACD;AAED,eAAe,8BAA8B,CAAC","sourcesContent":["import type { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\n\nimport { getDefaultResolver } from '../../config.js';\n\nimport type {\n\tUserClient as KeetaNetUserClient\n} from '@keetanetwork/keetanet-client';\nimport type {\n\tKeetaAssetMovementAnchorInitiateTransferRequest,\n\tKeetaAssetMovementAnchorGetTransferStatusRequest,\n\tKeetaAssetMovementAnchorGetTransferStatusResponse,\n\tKeetaAssetMovementAnchorCreatePersistentForwardingRequest,\n\tKeetaAssetMovementAnchorCreatePersistentForwardingResponse,\n\tSupportedAssets,\n\tProviderSearchInput,\n\tKeetaAssetMovementAnchorlistTransactionsRequest,\n\tKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse,\n\tAssetTransferInstructions\n} from './common.js';\nimport {\n\tassertKeetaSupportedAssets,\n\tconvertAssetLocationToString,\n\tconvertAssetSearchInputToCanonical,\n\tisKeetaAssetMovementAnchorCreatePersistentForwardingResponse,\n\tisKeetaAssetMovementAnchorGetExchangeStatusResponse,\n\tisKeetaAssetMovementAnchorInitiateTransferResponse,\n\tisKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse\n} from './common.js';\nimport type { Logger } from '../../lib/log/index.ts';\nimport Resolver from \"../../lib/resolver.js\";\nimport type { ServiceMetadata } from '../../lib/resolver.ts';\nimport crypto from '../../lib/utils/crypto.js';\nimport type { BrandedString } from '../../lib/utils/brand.js';\n\n// const PARANOID = true;\n\n/**\n * The configuration options for the Asset Movement (Inbound/Outbound) Anchor client.\n */\nexport type KeetaAssetMovementClientConfig = {\n\t/**\n\t * The ID of the client. This is used to identify the client in logs.\n\t * If not provided, a random ID will be generated.\n\t */\n\tid?: string;\n\t/**\n\t * The logger to use for logging messages. If not provided, no logging\n\t * will be done.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The resolver to use for resolving Asset Movement Anchor services. If not\n\t * provided, a default resolver will be created using the provided\n\t * client and network (if the network is also not provided and the\n\t * client is not a UserClient, an error occurs).\n\t */\n\tresolver?: Resolver;\n\t/**\n\t * The account to use for signing requests. If not provided, the\n\t * account associated with the provided client will be used. If there\n\t * is no account associated with the client, an error occurs.\n\t */\n\tsigner?: InstanceType<typeof KeetaNetLib.Account>;\n\t/**\n\t * Account to perform changes on. If not provided, the account\n\t * associated with the provided client will be used. If there is no\n\t * account associated with the client, an error occurs.\n\t */\n\taccount?: InstanceType<typeof KeetaNetLib.Account>;\n} & Omit<NonNullable<Parameters<typeof getDefaultResolver>[1]>, 'client'>;\n\n/**\n * An opaque type that represents a provider ID.\n */\ntype ProviderID = BrandedString<'AssetMovementProviderID'>;\n\n/**\n * An opaque type that represents an Asset Movement Anchor request ID\n */\n// type RequestID = BrandedString<'AssetMovementRequestID'>;\n\nconst KeetaAssetMovementAnchorClientAccessToken = Symbol('KeetaAssetMovementAnchorClientAccessToken');\n\nfunction typedAssetMovementServiceEntries<T extends object>(obj: T): [keyof T, T[keyof T]][] {\n\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\treturn(Object.entries(obj) as [keyof T, T[keyof T]][]);\n}\n\n/**\n * A list of operations that can be performed by the Asset Movement Anchor service.\n */\ntype KeetaAssetMovementAnchorOperations = {\n\t[operation in keyof NonNullable<ServiceMetadata['services']['assetMovement']>[string]['operations']]?: (params?: { [key: string]: string; }) => URL;\n};\n\n/**\n * The service information for a KYC Anchor service.\n */\ntype KeetaAssetMovementServiceInfo = {\n\toperations: {\n\t\t[operation in keyof KeetaAssetMovementAnchorOperations]: Promise<KeetaAssetMovementAnchorOperations[operation]>;\n\t};\n\n\tsupportedAssets: SupportedAssets[];\n};\n\n/**\n * For each matching KYC Anchor service, this type describes the\n * operations available and the country codes that the service supports.\n */\ntype GetEndpointsResult = {\n\t[id: ProviderID]: KeetaAssetMovementServiceInfo;\n};\n\nfunction validateURL(url: string | undefined): URL {\n\tif (url === undefined || url === null) {\n\t\tthrow(new Error('Invalid URL: null or undefined'));\n\t}\n\n\tconst parsedURL = new URL(url);\n\n\treturn(parsedURL);\n}\n\nasync function getEndpoints(resolver: Resolver, request: ProviderSearchInput): Promise<GetEndpointsResult | null> {\n\tconst asset = request.asset ? convertAssetSearchInputToCanonical(request.asset) : undefined;\n\tif (asset === undefined) {\n\t\tthrow(new Error('asset it required to lookup provider'));\n\t}\n\tconst from = request.from ? { from: convertAssetLocationToString(request.from) } : {};\n\tconst to = request.to ? { to: convertAssetLocationToString(request.to) } : {};\n\tconst response = await resolver.lookup('assetMovement', {\n\t\tasset,\n\t\t...from,\n\t\t...to\n\t});\n\n\tif (response === undefined) {\n\t\treturn(null);\n\t}\n\n\tconst serviceInfoPromises = Object.entries(response).map(async function([id, serviceInfo]): Promise<[ProviderID, KeetaAssetMovementServiceInfo]> {\n\t\tconst supportedAssetsMetadata = await Resolver.Metadata.fullyResolveValuizable(serviceInfo.supportedAssets);\n\t\tconst supportedAssets = assertKeetaSupportedAssets(supportedAssetsMetadata);\n\n\t\tconst operations = await serviceInfo.operations('object');\n\t\tconst operationsFunctions: KeetaAssetMovementServiceInfo['operations'] = {};\n\t\tfor (const [key, operation] of Object.entries(operations)) {\n\t\t\tif (operation === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tObject.defineProperty(operationsFunctions, key, {\n\t\t\t\tget: async function() {\n\t\t\t\t\tconst url = await operation('string');\n\t\t\t\t\treturn(function(params?: { [key: string]: string; }): URL {\n\t\t\t\t\t\tlet substitutedURL = url;\n\t\t\t\t\t\tfor (const [paramKey, paramValue] of Object.entries(params ?? {})) {\n\t\t\t\t\t\t\tsubstitutedURL = substitutedURL.replace(`{${paramKey}}`, encodeURIComponent(paramValue));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn(validateURL(substitutedURL));\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true\n\t\t\t});\n\t\t}\n\n\t\treturn([\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tid as unknown as ProviderID,\n\t\t\t{\n\t\t\t\toperations: operationsFunctions,\n\t\t\t\tsupportedAssets: supportedAssets\n\t\t\t}\n\t\t]);\n\t});\n\n\tconst retval = Object.fromEntries(await Promise.all(serviceInfoPromises));\n\n\treturn(retval);\n}\n\ninterface KeetaAssetMovementAnchorBaseConfig {\n\tclient: KeetaNetUserClient;\n\tlogger?: Logger | undefined;\n}\n\nclass KeetaAssetMovementAnchorBase {\n\tprotected readonly logger?: Logger | undefined;\n\tprotected readonly client: KeetaNetUserClient;\n\n\tconstructor(config: KeetaAssetMovementAnchorBaseConfig) {\n\t\tthis.client = config.client;\n\t\tthis.logger = config.logger;\n\t}\n}\n\n/**\n * Represents an in-progress Asset Movement request.\n */\nclass KeetaAssetMovementTransfer {\n\tprivate readonly provider: KeetaAssetMovementAnchorProvider;\n\tprivate request: KeetaAssetMovementAnchorInitiateTransferRequest;\n\tprivate transfer: { id: string, instructionChoices: AssetTransferInstructions[] }\n\n\tconstructor(provider: KeetaAssetMovementAnchorProvider, request: KeetaAssetMovementAnchorInitiateTransferRequest, transfer: { id: string, instructionChoices: AssetTransferInstructions[] }) {\n\t\tthis.provider = provider;\n\t\tthis.request = request;\n\t\tthis.transfer = transfer;\n\t}\n\n\tasync getTransferStatus(): Promise<KeetaAssetMovementAnchorGetTransferStatusResponse> {\n\t\treturn(await this.provider.getTransferStatus({ id: this.transfer.id }));\n\t}\n\n\tget transferId(): string {\n\t\treturn(this.transfer.id);\n\t}\n\n\tget instructions(): AssetTransferInstructions[] {\n\t\treturn(this.transfer.instructionChoices);\n\t}\n}\n\nclass KeetaAssetMovementAnchorProvider extends KeetaAssetMovementAnchorBase {\n\treadonly serviceInfo: KeetaAssetMovementServiceInfo;\n\treadonly providerID: ProviderID;\n\tprivate readonly parent: KeetaAssetMovementAnchorClient;\n\n\tconstructor(serviceInfo: KeetaAssetMovementServiceInfo, providerID: ProviderID, parent: KeetaAssetMovementAnchorClient) {\n\t\tconst parentPrivate = parent._internals(KeetaAssetMovementAnchorClientAccessToken);\n\t\tsuper(parentPrivate);\n\n\t\tthis.serviceInfo = serviceInfo;\n\t\tthis.providerID = providerID;\n\t\tthis.parent = parent;\n\t}\n\n\tasync initiateTransfer(request: KeetaAssetMovementAnchorInitiateTransferRequest): Promise<KeetaAssetMovementTransfer> {\n\t\tthis.logger?.debug(`Starting Asset Movement Transfer for provider ID: ${String(this.providerID)}, request: ${JSON.stringify(request)}`);\n\n\t\tconst endpoints = this.serviceInfo.operations;\n\t\tconst initiateTransfer = await endpoints.initiateTransfer;\n\t\tif (initiateTransfer === undefined) {\n\t\t\tthrow(new Error('Asset Movement service does not support initiateTransfer operation'));\n\t\t}\n\t\tconst initiateTransferURL = initiateTransfer();\n\t\tconst requestInformation = await fetch(initiateTransferURL, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Accept': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\t...request\n\t\t\t})\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaAssetMovementAnchorInitiateTransferResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from asset movement service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(new Error(`asset movement request failed: ${requestInformationJSON.error}`));\n\t\t}\n\n\t\tthis.logger?.debug(`asset movement request successful, request ID ${requestInformationJSON.id}`);\n\n\t\tconst anchorTransfer = new KeetaAssetMovementTransfer(this, request, { id: requestInformationJSON.id, instructionChoices: requestInformationJSON.instructionChoices });\n\t\treturn(anchorTransfer);\n\t}\n\n\tasync getTransferStatus(request: KeetaAssetMovementAnchorGetTransferStatusRequest): Promise<KeetaAssetMovementAnchorGetTransferStatusResponse> {\n\t\tconst endpoints = this.serviceInfo.operations;\n\t\tconst getTransferStatus = await endpoints.getTransferStatus;\n\t\tif (getTransferStatus === undefined) {\n\t\t\tthrow(new Error('Asset Movement service does not support getTransferStatus operation'));\n\t\t}\n\t\tconst getTransferURL = getTransferStatus({ id: request.id });\n\t\tconst requestInformation = await fetch(getTransferURL, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Accept': 'application/json'\n\t\t\t}\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaAssetMovementAnchorGetExchangeStatusResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from asset movement service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(new Error(`asset movement request failed: ${requestInformationJSON.error}`));\n\t\t}\n\n\t\tthis.logger?.debug(`asset movement request successful, request ID ${request.id}`);\n\n\t\treturn(requestInformationJSON);\n\t}\n\n\tasync createPersistentForwardingAddress(request: KeetaAssetMovementAnchorCreatePersistentForwardingRequest): Promise<KeetaAssetMovementAnchorCreatePersistentForwardingResponse | null> {\n\t\tthis.logger?.debug(`Creating persistent forwarding for provider ID: ${String(this.providerID)}, request: ${JSON.stringify(request)}`);\n\n\t\tconst endpoints = this.serviceInfo.operations;\n\t\tconst createPersistentForwarding = await endpoints.createPersistentForwarding;\n\t\tif (createPersistentForwarding === undefined) {\n\t\t\tthrow(new Error('Asset Movement service does not support createPersistentForwarding operation'));\n\t\t}\n\t\tconst createPersistentForwardingURL = createPersistentForwarding();\n\t\tconst requestInformation = await fetch(createPersistentForwardingURL, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Accept': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\t...request\n\t\t\t})\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaAssetMovementAnchorCreatePersistentForwardingResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from create persistent forwarding request: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(new Error(`create persistent forwarding request failed: ${requestInformationJSON.error}`));\n\t\t}\n\n\t\tthis.logger?.debug(`create persistent forwarding request successful, ${requestInformationJSON.address}`);\n\n\t\treturn(requestInformationJSON);\n\t}\n\n\tasync listTransactions(request: KeetaAssetMovementAnchorlistTransactionsRequest): Promise<KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse | null> {\n\t\tthis.logger?.debug(`List persistent forwarding transactions provider ID: ${String(this.providerID)}, request: ${JSON.stringify(request)}`);\n\n\t\tconst endpoints = this.serviceInfo.operations;\n\t\tconst listTransactions = await endpoints.listTransactions;\n\t\tif (listTransactions === undefined) {\n\t\t\tthrow(new Error('Asset Movement service does not support listTransactions operation'));\n\t\t}\n\t\tconst listTransactionsURL = listTransactions();\n\t\tconst requestInformation = await fetch(listTransactionsURL, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Accept': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\t...request\n\t\t\t})\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from list persistent transactions request: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(new Error(`list persistent transactions request failed: ${requestInformationJSON.error}`));\n\t\t}\n\n\t\tthis.logger?.debug(`list persistent transactions request successful, ${requestInformationJSON.transactions}`);\n\n\t\treturn(requestInformationJSON);\n\t}\n}\n\nclass KeetaAssetMovementAnchorClient extends KeetaAssetMovementAnchorBase {\n\treadonly resolver: Resolver;\n\treadonly id: string;\n\t// eslint-disable-next-line no-unused-private-class-members\n\treadonly #signer: InstanceType<typeof KeetaNetLib.Account>;\n\t// eslint-disable-next-line no-unused-private-class-members\n\treadonly #account: InstanceType<typeof KeetaNetLib.Account>;\n\n\tconstructor(client: KeetaNetUserClient, config: KeetaAssetMovementClientConfig = {}) {\n\t\tsuper({ client, logger: config.logger });\n\t\tthis.resolver = config.resolver ?? getDefaultResolver(client, config);\n\t\tthis.id = config.id ?? crypto.randomUUID();\n\n\t\tif (config.signer) {\n\t\t\tthis.#signer = config.signer;\n\t\t} else if ('signer' in client && client.signer !== null) {\n\t\t\tthis.#signer = client.signer;\n\t\t} else if ('account' in client && client.account.hasPrivateKey) {\n\t\t\tthis.#signer = client.account;\n\t\t} else {\n\t\t\tthrow(new Error('KeetaAssetMovementAnchorClient requires a Signer or a UserClient with an associated Signer'));\n\t\t}\n\n\t\tif (config.account) {\n\t\t\tthis.#account = config.account;\n\t\t} else if ('account' in client) {\n\t\t\tthis.#account = client.account;\n\t\t} else {\n\t\t\tthrow(new Error('KeetaAssetMovementAnchorClient requires an Account or a UserClient with an associated Account'));\n\t\t}\n\t}\n\n\tasync getProvidersForTransfer(request: ProviderSearchInput): Promise<KeetaAssetMovementAnchorProvider[] | null> {\n\t\tconst endpoints = await getEndpoints(this.resolver, request);\n\t\tif (endpoints === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst providers = typedAssetMovementServiceEntries(endpoints).map(([id, serviceInfo]) => {\n\t\t\treturn(new KeetaAssetMovementAnchorProvider(serviceInfo, id, this));\n\t\t});\n\n\t\treturn(providers);\n\t}\n\n\t/** @internal */\n\t_internals(accessToken: symbol) {\n\t\tif (accessToken !== KeetaAssetMovementAnchorClientAccessToken) {\n\t\t\tthrow(new Error('invalid access token'));\n\t\t}\n\n\t\treturn({\n\t\t\tresolver: this.resolver,\n\t\t\tlogger: this.logger,\n\t\t\tclient: this.client\n\t\t});\n\t}\n}\n\nexport default KeetaAssetMovementAnchorClient;\n"]}
|