@keetanetwork/anchor 0.0.53 → 0.0.60
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/asset.d.ts +18 -4
- package/lib/asset.d.ts.map +1 -1
- package/lib/asset.js +18 -0
- package/lib/asset.js.map +1 -1
- package/lib/chaining-graph.cli.d.ts +2 -0
- package/lib/chaining-graph.cli.d.ts.map +1 -0
- package/lib/chaining-graph.cli.js +257 -0
- package/lib/chaining-graph.cli.js.map +1 -0
- package/lib/chaining.d.ts +247 -0
- package/lib/chaining.d.ts.map +1 -0
- package/lib/chaining.js +1187 -0
- package/lib/chaining.js.map +1 -0
- package/lib/metadata.types.d.ts +28 -0
- package/lib/metadata.types.d.ts.map +1 -0
- package/lib/metadata.types.generated.d.ts +3 -0
- package/lib/metadata.types.generated.d.ts.map +1 -0
- package/lib/metadata.types.generated.js +15 -0
- package/lib/metadata.types.generated.js.map +1 -0
- package/lib/metadata.types.js +50 -0
- package/lib/metadata.types.js.map +1 -0
- package/lib/queue/drivers/queue_postgres.d.ts +20 -3
- package/lib/queue/drivers/queue_postgres.d.ts.map +1 -1
- package/lib/queue/drivers/queue_postgres.js +152 -40
- package/lib/queue/drivers/queue_postgres.js.map +1 -1
- package/lib/resolver.d.ts +15 -19
- package/lib/resolver.d.ts.map +1 -1
- package/lib/resolver.js +1106 -504
- package/lib/resolver.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/services/asset-movement/client.d.ts +31 -12
- package/services/asset-movement/client.d.ts.map +1 -1
- package/services/asset-movement/client.js +247 -25
- package/services/asset-movement/client.js.map +1 -1
- package/services/asset-movement/common.d.ts +142 -62
- package/services/asset-movement/common.d.ts.map +1 -1
- package/services/asset-movement/common.generated.d.ts +51 -0
- package/services/asset-movement/common.generated.d.ts.map +1 -0
- package/services/asset-movement/common.generated.js +54492 -0
- package/services/asset-movement/common.generated.js.map +1 -0
- package/services/asset-movement/common.js +25 -35368
- package/services/asset-movement/common.js.map +1 -1
- package/services/asset-movement/lib/data/addresses/bank-account/ca.d.ts +4 -0
- package/services/asset-movement/lib/data/addresses/bank-account/ca.d.ts.map +1 -0
- package/services/asset-movement/lib/data/addresses/bank-account/ca.js +49 -0
- package/services/asset-movement/lib/data/addresses/bank-account/ca.js.map +1 -0
- package/services/asset-movement/lib/data/addresses/bank-account/index.generated.d.ts +4 -0
- package/services/asset-movement/lib/data/addresses/bank-account/index.generated.d.ts.map +1 -1
- package/services/asset-movement/lib/data/addresses/bank-account/index.generated.js +4 -0
- package/services/asset-movement/lib/data/addresses/bank-account/index.generated.js.map +1 -1
- package/services/asset-movement/lib/data/addresses/bank-account/interac.d.ts.map +1 -1
- package/services/asset-movement/lib/data/addresses/bank-account/interac.js +9 -20
- package/services/asset-movement/lib/data/addresses/bank-account/interac.js.map +1 -1
- package/services/asset-movement/lib/data/addresses/bank-account/pix.d.ts.map +1 -1
- package/services/asset-movement/lib/data/addresses/bank-account/pix.js +3 -2
- package/services/asset-movement/lib/data/addresses/bank-account/pix.js.map +1 -1
- package/services/asset-movement/lib/data/addresses/bank-account/uae.d.ts +4 -0
- package/services/asset-movement/lib/data/addresses/bank-account/uae.d.ts.map +1 -0
- package/services/asset-movement/lib/data/addresses/bank-account/uae.js +45 -0
- package/services/asset-movement/lib/data/addresses/bank-account/uae.js.map +1 -0
- package/services/asset-movement/lib/data/addresses/types.generated.d.ts +260 -52
- package/services/asset-movement/lib/data/addresses/types.generated.d.ts.map +1 -1
- package/services/asset-movement/lib/data/addresses/types.generated.js +252 -35
- package/services/asset-movement/lib/data/addresses/types.generated.js.map +1 -1
- package/services/asset-movement/lib/location.d.ts +10 -1
- package/services/asset-movement/lib/location.d.ts.map +1 -1
- package/services/asset-movement/lib/location.generated.d.ts +2 -1
- package/services/asset-movement/lib/location.generated.d.ts.map +1 -1
- package/services/asset-movement/lib/location.generated.js +25 -2
- package/services/asset-movement/lib/location.generated.js.map +1 -1
- package/services/asset-movement/lib/location.js +3 -0
- package/services/asset-movement/lib/location.js.map +1 -1
- package/services/asset-movement/server.d.ts +21 -6
- package/services/asset-movement/server.d.ts.map +1 -1
- package/services/asset-movement/server.js +69 -3
- package/services/asset-movement/server.js.map +1 -1
- package/services/fx/client.d.ts +3 -2
- package/services/fx/client.d.ts.map +1 -1
- package/services/fx/client.js +8 -3
- package/services/fx/client.js.map +1 -1
- package/services/fx/server.d.ts +2 -1
- package/services/fx/server.d.ts.map +1 -1
- package/services/fx/server.js +3 -0
- package/services/fx/server.js.map +1 -1
- package/services/storage/clients/contacts.generated.js +686 -310
- package/services/storage/clients/contacts.generated.js.map +1 -1
- package/services/storage/common.d.ts +7 -1
- package/services/storage/common.d.ts.map +1 -1
- package/services/storage/common.js.map +1 -1
- package/services/storage/server.js +1 -1
- package/services/storage/server.js.map +1 -1
- package/services/storage/test-utils.d.ts +1 -0
- package/services/storage/test-utils.d.ts.map +1 -1
- package/services/storage/test-utils.js +3 -0
- package/services/storage/test-utils.js.map +1 -1
|
@@ -59,7 +59,15 @@ export declare function isChainLocation<T extends ChainLocationType>(input: Asse
|
|
|
59
59
|
export type AssetLocation = ChainLocation | BankLocation | MobileWalletLocation;
|
|
60
60
|
export type BankAccountType = BankAccountAddressObfuscated['accountType'];
|
|
61
61
|
export type MobileWalletAccountType = MobileWalletAddressObfuscated['accountType'];
|
|
62
|
-
|
|
62
|
+
type ChainLocationIDType = {
|
|
63
|
+
[K in 'keeta' | 'evm']: bigint;
|
|
64
|
+
} & {
|
|
65
|
+
[K in 'solana' | 'bitcoin' | 'tron']: string;
|
|
66
|
+
};
|
|
67
|
+
export type ChainLocationString<T extends ChainLocationType = ChainLocationType> = {
|
|
68
|
+
[K in T]: `chain:${K}:${ChainLocationIDType[K]}`;
|
|
69
|
+
}[T];
|
|
70
|
+
export type AssetLocationString = ChainLocationString | `bank-account:${BankAccountType}` | `mobile-wallet:${MobileWalletAccountType}`;
|
|
63
71
|
export type AssetLocationLike = AssetLocation | AssetLocationString;
|
|
64
72
|
export type AssetLocationInput = AssetLocation | AssetLocationString;
|
|
65
73
|
export type AssetLocationCanonical = AssetLocationString;
|
|
@@ -67,5 +75,6 @@ export declare function convertAssetLocationToString(input: AssetLocationLike):
|
|
|
67
75
|
export declare function toAssetLocationFromString(input: string): AssetLocation;
|
|
68
76
|
export declare function convertAssetLocationInputToCanonical(input: AssetLocationInput): AssetLocationCanonical;
|
|
69
77
|
export declare function toAssetLocation(input: AssetLocationInput): AssetLocation;
|
|
78
|
+
export declare function isAssetLocationEqual(a: AssetLocationInput, b: AssetLocationInput): boolean;
|
|
70
79
|
export {};
|
|
71
80
|
//# sourceMappingURL=location.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../../../../src/services/asset-movement/lib/location.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,4BAA4B,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAGhG,UAAU,YAAY,CAAC,IAAI,SAAS,OAAO,GAAG,cAAc,GAAG,eAAe;IAC7E,IAAI,EAAE,IAAI,CAAC;CACX;AAED,MAAM,WAAW,YAAa,SAAQ,YAAY,CAAC,cAAc,CAAC;IACjE,OAAO,EAAE;QACR,IAAI,EAAE,eAAe,CAAC;KACtB,CAAA;CACD;AAED,MAAM,WAAW,oBAAqB,SAAQ,YAAY,CAAC,eAAe,CAAC;IAC1E,OAAO,EAAE;QACR,IAAI,EAAE,uBAAuB,CAAC;KAC9B,CAAA;CACD;AAED,UAAU,iBAAiB,CAAC,IAAI,CAAE,SAAQ,YAAY,CAAC,OAAO,CAAC;IAC9D,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,IAAI,CAAC;CACZ;AAED,MAAM,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE;QACN,IAAI,EAAE,OAAO,CAAC;QACd;;WAEG;QACH,SAAS,EAAE,MAAM,CAAC;KAClB,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EAAE,kBAAkB,GAAG,aAAa,CAMxE;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAE1F"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { BankAccountType, MobileWalletAccountType, PickChainLocation } from "./location.js";
|
|
1
|
+
import type { AssetLocationLike, BankAccountType, MobileWalletAccountType, PickChainLocation } from "./location.js";
|
|
2
2
|
export declare const isTronNetworkAlias: (input: unknown) => input is PickChainLocation<'tron'>['chain']['networkAlias'];
|
|
3
3
|
export declare const assertBankAccountType: (input: unknown) => BankAccountType;
|
|
4
4
|
export declare const assertMobileWalletAccountType: (input: unknown) => MobileWalletAccountType;
|
|
5
|
+
export declare const isAssetLocationLike: (input: unknown) => input is AssetLocationLike;
|
|
5
6
|
//# sourceMappingURL=location.generated.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location.generated.d.ts","sourceRoot":"","sources":["../../../../src/services/asset-movement/lib/location.generated.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"location.generated.d.ts","sourceRoot":"","sources":["../../../../src/services/asset-movement/lib/location.generated.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEpH,eAAO,MAAM,kBAAkB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,cAAc,CAAkE,CAAC;AAClL,eAAO,MAAM,qBAAqB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,eAAiD,CAAC;AAC1G,eAAO,MAAM,6BAA6B,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,uBAAiE,CAAC;AAClI,eAAO,MAAM,mBAAmB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,iBAAiD,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
|
|
2
2
|
import { createAssert, createIs } from "typia";
|
|
3
3
|
export const isTronNetworkAlias = (() => { return input => null !== input && undefined !== input && ("mainnet" === input || "shasta" === input || "nile" === input || "string" === typeof input && RegExp(/^custom:(.*)/).test(input)); })();
|
|
4
|
-
export const assertBankAccountType = (() => { const _iv1 = new Set(["bcr-pay", "card", "clabe", "duit-now", "fps", "hk-fps", "iban-swift", "interac", "pay-now", "pix", "upi", "us"]); const _av2 = new Set(["bcr-pay", "card", "clabe", "duit-now", "fps", "hk-fps", "iban-swift", "interac", "pay-now", "pix", "upi", "us"]); const __is = input => true === _iv1.has(input); let _errorFactory; return (input, errorFactory) => {
|
|
4
|
+
export const assertBankAccountType = (() => { const _iv1 = new Set(["bcr-pay", "ca", "card", "clabe", "duit-now", "fps", "hk-fps", "iban-swift", "interac", "pay-now", "pix", "uae", "upi", "us"]); const _av2 = new Set(["bcr-pay", "ca", "card", "clabe", "duit-now", "fps", "hk-fps", "iban-swift", "interac", "pay-now", "pix", "uae", "upi", "us"]); const __is = input => true === _iv1.has(input); let _errorFactory; return (input, errorFactory) => {
|
|
5
5
|
if (false === __is(input)) {
|
|
6
6
|
_errorFactory = errorFactory;
|
|
7
7
|
((input, _path, _exceptionable = true) => true === _av2.has(input) || __typia_transform__assertGuard._assertGuard(true, {
|
|
8
8
|
method: "createAssert",
|
|
9
9
|
path: _path + "",
|
|
10
|
-
expected: "(\"bcr-pay\" | \"card\" | \"clabe\" | \"duit-now\" | \"fps\" | \"hk-fps\" | \"iban-swift\" | \"interac\" | \"pay-now\" | \"pix\" | \"upi\" | \"us\")",
|
|
10
|
+
expected: "(\"bcr-pay\" | \"ca\" | \"card\" | \"clabe\" | \"duit-now\" | \"fps\" | \"hk-fps\" | \"iban-swift\" | \"interac\" | \"pay-now\" | \"pix\" | \"uae\" | \"upi\" | \"us\")",
|
|
11
11
|
value: input
|
|
12
12
|
}, _errorFactory))(input, "$input", true);
|
|
13
13
|
}
|
|
@@ -25,4 +25,27 @@ export const assertMobileWalletAccountType = (() => { const _iv1 = new Set(["air
|
|
|
25
25
|
}
|
|
26
26
|
return input;
|
|
27
27
|
}; })();
|
|
28
|
+
export const isAssetLocationLike = (() => { const _iv1 = new Set(["bank-account:bcr-pay", "bank-account:ca", "bank-account:card", "bank-account:clabe", "bank-account:duit-now", "bank-account:fps", "bank-account:hk-fps", "bank-account:iban-swift", "bank-account:interac", "bank-account:pay-now", "bank-account:pix", "bank-account:uae", "bank-account:upi", "bank-account:us", "mobile-wallet:airtel-money", "mobile-wallet:bkash", "mobile-wallet:easy-paisa", "mobile-wallet:finja-wallet", "mobile-wallet:jazz-cash", "mobile-wallet:mtn-mobile-money", "mobile-wallet:nagad", "mobile-wallet:naya-pay", "mobile-wallet:paypal", "mobile-wallet:rocket", "mobile-wallet:sada-pay", "mobile-wallet:venmo"]); const _iv2 = new Set(["bcr-pay", "ca", "card", "clabe", "duit-now", "fps", "hk-fps", "iban-swift", "interac", "pay-now", "pix", "uae", "upi", "us"]); const _iv3 = new Set(["airtel-money", "bkash", "easy-paisa", "finja-wallet", "jazz-cash", "mtn-mobile-money", "nagad", "naya-pay", "paypal", "rocket", "sada-pay", "venmo"]); const _io0 = input => "chain" === input.type && ("object" === typeof input.chain && null !== input.chain && _iu0(input.chain)); const _io1 = input => "keeta" === input.type && "bigint" === typeof input.networkId; const _io2 = input => "evm" === input.type && "bigint" === typeof input.chainId; const _io3 = input => "solana" === input.type && "string" === typeof input.genesisHash; const _io4 = input => "bitcoin" === input.type && "string" === typeof input.magicBytes; const _io5 = input => "tron" === input.type && (null !== input.networkAlias && undefined !== input.networkAlias && ("mainnet" === input.networkAlias || "shasta" === input.networkAlias || "nile" === input.networkAlias || "string" === typeof input.networkAlias && RegExp(/^custom:(.*)/).test(input.networkAlias))); const _io6 = input => "object" === typeof input.account && null !== input.account && _io7(input.account) && "bank-account" === input.type; const _io7 = input => true === _iv2.has(input.type); const _io8 = input => "object" === typeof input.account && null !== input.account && _io9(input.account) && "mobile-wallet" === input.type; const _io9 = input => true === _iv3.has(input.type); const _iu0 = input => (() => {
|
|
29
|
+
if ("keeta" === input.type)
|
|
30
|
+
return _io1(input);
|
|
31
|
+
else if ("evm" === input.type)
|
|
32
|
+
return _io2(input);
|
|
33
|
+
else if ("solana" === input.type)
|
|
34
|
+
return _io3(input);
|
|
35
|
+
else if ("bitcoin" === input.type)
|
|
36
|
+
return _io4(input);
|
|
37
|
+
else if ("tron" === input.type)
|
|
38
|
+
return _io5(input);
|
|
39
|
+
else
|
|
40
|
+
return false;
|
|
41
|
+
})(); const _iu1 = input => (() => {
|
|
42
|
+
if ("chain" === input.type)
|
|
43
|
+
return _io0(input);
|
|
44
|
+
else if ("mobile-wallet" === input.type)
|
|
45
|
+
return _io8(input);
|
|
46
|
+
else if ("bank-account" === input.type)
|
|
47
|
+
return _io6(input);
|
|
48
|
+
else
|
|
49
|
+
return false;
|
|
50
|
+
})(); return input => null !== input && undefined !== input && (true === _iv1.has(input) || "string" === typeof input && (RegExp(/^chain:keeta:[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?$/).test(input) || RegExp(/^chain:evm:[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?$/).test(input) || RegExp(/^chain:solana:(.*)/).test(input) || RegExp(/^chain:bitcoin:(.*)/).test(input) || RegExp(/^chain:tron:(.*)/).test(input)) || "object" === typeof input && null !== input && _iu1(input)); })();
|
|
28
51
|
//# sourceMappingURL=location.generated.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location.generated.js","sourceRoot":"","sources":["../../../../src/services/asset-movement/lib/location.generated.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG/C,MAAM,CAAC,MAAM,kBAAkB,6MAAkJ,CAAC;AAClL,MAAM,CAAC,MAAM,qBAAqB;;;;;;;;;;;OAAuE,CAAC;AAC1G,MAAM,CAAC,MAAM,6BAA6B;;;;;;;;;;;OAAuF,CAAC","sourcesContent":["import { createAssert, createIs } from \"typia\";\nimport type { BankAccountType, MobileWalletAccountType, PickChainLocation } from \"./location.js\";\n\nexport const isTronNetworkAlias: (input: unknown) => input is PickChainLocation<'tron'>['chain']['networkAlias'] = createIs<PickChainLocation<'tron'>['chain']['networkAlias']>();\nexport const assertBankAccountType: (input: unknown) => BankAccountType = createAssert<BankAccountType>();\nexport const assertMobileWalletAccountType: (input: unknown) => MobileWalletAccountType = createAssert<MobileWalletAccountType>();\n"]}
|
|
1
|
+
{"version":3,"file":"location.generated.js","sourceRoot":"","sources":["../../../../src/services/asset-movement/lib/location.generated.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG/C,MAAM,CAAC,MAAM,kBAAkB,6MAAkJ,CAAC;AAClL,MAAM,CAAC,MAAM,qBAAqB;;;;;;;;;;;OAAuE,CAAC;AAC1G,MAAM,CAAC,MAAM,6BAA6B;;;;;;;;;;;OAAuF,CAAC;AAClI,MAAM,CAAC,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;mdAAgF,CAAC","sourcesContent":["import { createAssert, createIs } from \"typia\";\nimport type { AssetLocationLike, BankAccountType, MobileWalletAccountType, PickChainLocation } from \"./location.js\";\n\nexport const isTronNetworkAlias: (input: unknown) => input is PickChainLocation<'tron'>['chain']['networkAlias'] = createIs<PickChainLocation<'tron'>['chain']['networkAlias']>();\nexport const assertBankAccountType: (input: unknown) => BankAccountType = createAssert<BankAccountType>();\nexport const assertMobileWalletAccountType: (input: unknown) => MobileWalletAccountType = createAssert<MobileWalletAccountType>();\nexport const isAssetLocationLike: (input: unknown) => input is AssetLocationLike = createIs<AssetLocationLike>();\n"]}
|
|
@@ -164,4 +164,7 @@ export function toAssetLocation(input) {
|
|
|
164
164
|
return (input);
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
+
export function isAssetLocationEqual(a, b) {
|
|
168
|
+
return (convertAssetLocationInputToCanonical(a) === convertAssetLocationInputToCanonical(b));
|
|
169
|
+
}
|
|
167
170
|
//# sourceMappingURL=location.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location.js","sourceRoot":"","sources":["../../../../src/services/asset-movement/lib/location.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAgEnH,MAAM,UAAU,eAAe,CAA8B,KAAoB,EAAE,SAAa;IAC/F,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;IAED,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IACxC,CAAC;IAED,OAAM,CAAC,IAAI,CAAC,CAAC;AACd,CAAC;AAiBD,MAAM,UAAU,4BAA4B,CAAC,KAAwB;IACpE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAClC,OAAM,CAAC,eAAe,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;QAChD,CAAC;aAAM,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,EA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IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACxD,OAAM,CAAC,4BAA4B,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED,MAAK,CAAC,IAAI,KAAK,CAAC,oCAAoC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC;AACtE,CAAC;AAGD,MAAM,UAAU,eAAe,CAAC,KAAyB;IACxD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1C,CAAC;SAAM,CAAC;QACP,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;AACF,CAAC","sourcesContent":["import { assertNever } from \"../../../lib/utils/never.js\";\nimport type { BankAccountAddressObfuscated, MobileWalletAddressObfuscated } from \"../common.js\";\nimport { assertBankAccountType, assertMobileWalletAccountType, isTronNetworkAlias } from \"./location.generated.js\";\n\ninterface BaseLocation<Type extends 'chain' | 'bank-account' | 'mobile-wallet'> {\n\ttype: Type;\n}\n\nexport interface BankLocation extends BaseLocation<'bank-account'> {\n\taccount: {\n\t\ttype: BankAccountType;\n\t}\n}\n\nexport interface MobileWalletLocation extends BaseLocation<'mobile-wallet'> {\n\taccount: {\n\t\ttype: MobileWalletAccountType;\n\t}\n}\n\ninterface BaseChainLocation<Data> extends BaseLocation<'chain'> {\n\ttype: 'chain';\n\tchain: Data;\n}\n\nexport type ChainLocation = {\n\ttype: 'chain';\n\tchain: {\n\t\ttype: 'keeta';\n\t\t/**\n\t\t * The network ID representing the Keeta network to interact with\n\t\t */\n\t\tnetworkId: bigint;\n\t} | {\n\t\ttype: 'evm';\n\t\t/**\n\t\t * The chain ID representing the EVM-based network to interact with\n\t\t */\n\t\tchainId: bigint;\n\t} | {\n\t\ttype: 'solana';\n\t\t/**\n\t\t * The genesis hash representing Solana network/cluster to interact with\n\t\t */\n\t\tgenesisHash: string;\n\t} | {\n\t\ttype: 'bitcoin';\n\t\t/**\n\t\t * The \"magic bytes\" representing the bitcoin network to interact with\n\t\t */\n\t\tmagicBytes: string;\n\t} | {\n\t\ttype: 'tron';\n\t\t/**\n\t\t * The network alias representing the Tron network to interact with\n\t\t * Note: this is not the chain ID, but a human-readable alias because tron does not use chain/network IDs or any similar way to differentiate networks\n\t\t */\n\t\tnetworkAlias: 'mainnet' | 'shasta' | 'nile' | `custom:${string}`;\n\t}\n};\n\n\nexport type ChainLocationType = ChainLocation['chain']['type'];\n\nexport type PickChainLocation<T extends ChainLocationType = ChainLocationType> = BaseChainLocation<Extract<ChainLocation['chain'], { type: T }>>;\n\nexport function isChainLocation<T extends ChainLocationType>(input: AssetLocation, chainType?: T): input is PickChainLocation<T> {\n\tif (input.type !== 'chain') {\n\t\treturn(false);\n\t}\n\n\tif (chainType !== undefined) {\n\t\treturn(input.chain.type === chainType);\n\t}\n\n\treturn(true);\n}\n\nexport type AssetLocation = ChainLocation | BankLocation | MobileWalletLocation;\n\nexport type BankAccountType = BankAccountAddressObfuscated['accountType'];\nexport type MobileWalletAccountType = MobileWalletAddressObfuscated['accountType'];\n\nexport type AssetLocationString =\n\t`chain:${'keeta' | 'evm'}:${bigint}` | `chain:${'solana' | 'bitcoin' | 'tron'}:${string}` |\n\t`bank-account:${BankAccountType}` |\n\t`mobile-wallet:${MobileWalletAccountType}`;\n\nexport type AssetLocationLike = AssetLocation | AssetLocationString;\n\nexport type AssetLocationInput = AssetLocation | AssetLocationString;\nexport type AssetLocationCanonical = AssetLocationString;\n\nexport function convertAssetLocationToString(input: AssetLocationLike): AssetLocationString {\n\tif (typeof input === 'string') {\n\t\treturn(input);\n\t}\n\n\tif (input.type === 'chain') {\n\t\tif (input.chain.type === 'keeta') {\n\t\t\treturn(`chain:keeta:${input.chain.networkId}`);\n\t\t} else if (input.chain.type === 'evm') {\n\t\t\treturn(`chain:evm:${input.chain.chainId}`);\n\t\t} else if (input.chain.type === 'solana') {\n\t\t\treturn(`chain:solana:${input.chain.genesisHash}`);\n\t\t} else if (input.chain.type === 'bitcoin') {\n\t\t\treturn(`chain:bitcoin:${input.chain.magicBytes}`);\n\t\t} else if (input.chain.type === 'tron') {\n\t\t\treturn(`chain:tron:${input.chain.networkAlias}`);\n\t\t} else {\n\t\t\tassertNever(input.chain);\n\t\t}\n\t} else if (input.type === 'bank-account') {\n\t\treturn(`bank-account:${assertBankAccountType(input.account.type)}`);\n\t} else if (input.type === 'mobile-wallet') {\n\t\treturn(`mobile-wallet:${assertMobileWalletAccountType(input.account.type)}`);\n\t} else {\n\t\tthrow(new Error(`Invalid AssetLocation type: ${JSON.stringify(input)}`));\n\t}\n}\n\nfunction validateSolanaGenesisHash(hash: string): boolean {\n\t// Basic validation: Solana genesis hashes are typically 44-character base58 strings\n\tconst genesisHashRegex = /^(?=.{43,44}$)[1-9A-HJ-NP-Za-km-z]+$/;\n\treturn(genesisHashRegex.test(hash));\n}\n\nfunction validateBitcoinMagicBytes(magicBytes: string): boolean {\n\tif (magicBytes.length !== 8) {\n\t\treturn(false);\n\t}\n\n\ttry {\n\t\tconst buffer = Buffer.from(magicBytes, 'hex');\n\t\treturn(buffer.length === 4);\n\t} catch {\n\t\treturn(false);\n\t}\n}\n\nexport function toAssetLocationFromString(input: string): AssetLocation {\n\tconst [ kind, ...parts ] = input.split(':');\n\n\tif (kind === 'chain') {\n\t\tif (parts.length !== 2) {\n\t\t\tthrow(new Error('Invalid AssetLocation chain string'));\n\t\t}\n\n\t\tconst chainType = parts[0];\n\t\tif (!parts[1] || typeof parts[1] !== 'string') {\n\t\t\tthrow(new Error('Invalid chain id in AssetLocation string'));\n\t\t}\n\n\n\t\treturn({\n\t\t\ttype: 'chain',\n\t\t\tchain: (() => {\n\t\t\t\tif (chainType === 'keeta' || chainType === 'evm') {\n\t\t\t\t\tconst chainId = BigInt(parts[1]);\n\n\t\t\t\t\tif (chainId < 0n) {\n\t\t\t\t\t\tthrow(new Error(`Invalid chain id in AssetLocation string: ${parts[1]}`));\n\t\t\t\t\t}\n\n\t\t\t\t\tif (chainType === 'keeta') {\n\t\t\t\t\t\treturn({\n\t\t\t\t\t\t\ttype: 'keeta',\n\t\t\t\t\t\t\tnetworkId: chainId\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (chainType === 'evm') {\n\t\t\t\t\t\treturn({\n\t\t\t\t\t\t\ttype: 'evm',\n\t\t\t\t\t\t\tchainId: chainId\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else if (chainType === 'solana') {\n\t\t\t\t\tconst genesisHash = parts[1];\n\t\t\t\t\tif (!validateSolanaGenesisHash(genesisHash)) {\n\t\t\t\t\t\tthrow(new Error(`Invalid Solana genesis hash in AssetLocation string: ${genesisHash}`));\n\t\t\t\t\t}\n\n\t\t\t\t\treturn({\n\t\t\t\t\t\ttype: 'solana',\n\t\t\t\t\t\tgenesisHash: genesisHash\n\t\t\t\t\t});\n\t\t\t\t} else if (chainType === 'bitcoin') {\n\t\t\t\t\tconst magicBytes = parts[1];\n\n\t\t\t\t\tif (!validateBitcoinMagicBytes(magicBytes)) {\n\t\t\t\t\t\tthrow(new Error(`Invalid Bitcoin magic bytes in AssetLocation string: ${magicBytes}`));\n\t\t\t\t\t}\n\n\t\t\t\t\treturn({\n\t\t\t\t\t\ttype: 'bitcoin',\n\t\t\t\t\t\tmagicBytes: magicBytes\n\t\t\t\t\t});\n\t\t\t\t} else if (chainType === 'tron') {\n\t\t\t\t\tconst networkAlias = parts[1];\n\t\t\t\t\tif (!isTronNetworkAlias(networkAlias)) {\n\t\t\t\t\t\tthrow(new Error(`Invalid Tron network alias in AssetLocation string: ${networkAlias}`));\n\t\t\t\t\t}\n\n\t\t\t\t\treturn({\n\t\t\t\t\t\ttype: 'tron',\n\t\t\t\t\t\tnetworkAlias: networkAlias\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tthrow(new Error(`Invalid chain type in AssetLocation string: ${chainType}`));\n\t\t\t})()\n\t\t});\n\t} else if (kind === 'bank-account') {\n\t\tif (parts.length !== 1) {\n\t\t\tthrow(new Error('Invalid AssetLocation bank-account string'));\n\t\t}\n\n\t\treturn({\n\t\t\ttype: 'bank-account',\n\t\t\taccount: { type: assertBankAccountType(parts[0]) }\n\t\t});\n\t} else if (kind === 'mobile-wallet') {\n\t\tif (parts.length !== 1) {\n\t\t\tthrow(new Error('Invalid AssetLocation mobile-wallet string'));\n\t\t}\n\n\t\treturn({\n\t\t\ttype: 'mobile-wallet',\n\t\t\taccount: { type: assertMobileWalletAccountType(parts[0]) }\n\t\t});\n\t} else {\n\t\tthrow(new Error('Invalid AssetLocation string'));\n\t}\n}\n\nexport function convertAssetLocationInputToCanonical(input: AssetLocationInput): AssetLocationCanonical {\n\tif (typeof input === 'string') {\n\t\treturn(input);\n\t} else if (typeof input === 'object' && input !== null) {\n\t\treturn(convertAssetLocationToString(input));\n\t}\n\n\tthrow(new Error(`Invalid AssetLocationInput type: ${typeof input}`));\n}\n\n\nexport function toAssetLocation(input: AssetLocationInput): AssetLocation {\n\tif (typeof input === 'string') {\n\t\treturn(toAssetLocationFromString(input));\n\t} else {\n\t\treturn(input);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"location.js","sourceRoot":"","sources":["../../../../src/services/asset-movement/lib/location.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAgEnH,MAAM,UAAU,eAAe,CAA8B,KAAoB,EAAE,SAAa;IAC/F,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;IAED,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IACxC,CAAC;IAED,OAAM,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CAA4C,CAAC,CAAC,CAAC;QAChE,CAAC;QAED,OAAM,CAAC;YACN,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,EAAE,IAAI,EAAE,6BAA6B,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;SAC1D,CAAC,CAAC;IACJ,CAAC;SAAM,CAAC;QACP,MAAK,CAAC,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC,CAAC;IAClD,CAAC;AACF,CAAC;AAED,MAAM,UAAU,oCAAoC,CAAC,KAAyB;IAC7E,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACxD,OAAM,CAAC,4BAA4B,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED,MAAK,CAAC,IAAI,KAAK,CAAC,oCAAoC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC;AACtE,CAAC;AAGD,MAAM,UAAU,eAAe,CAAC,KAAyB;IACxD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1C,CAAC;SAAM,CAAC;QACP,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;AACF,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,CAAqB,EAAE,CAAqB;IAChF,OAAM,CAAC,oCAAoC,CAAC,CAAC,CAAC,KAAK,oCAAoC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7F,CAAC","sourcesContent":["import { assertNever } from \"../../../lib/utils/never.js\";\nimport type { BankAccountAddressObfuscated, MobileWalletAddressObfuscated } from \"../common.js\";\nimport { assertBankAccountType, assertMobileWalletAccountType, isTronNetworkAlias } from \"./location.generated.js\";\n\ninterface BaseLocation<Type extends 'chain' | 'bank-account' | 'mobile-wallet'> {\n\ttype: Type;\n}\n\nexport interface BankLocation extends BaseLocation<'bank-account'> {\n\taccount: {\n\t\ttype: BankAccountType;\n\t}\n}\n\nexport interface MobileWalletLocation extends BaseLocation<'mobile-wallet'> {\n\taccount: {\n\t\ttype: MobileWalletAccountType;\n\t}\n}\n\ninterface BaseChainLocation<Data> extends BaseLocation<'chain'> {\n\ttype: 'chain';\n\tchain: Data;\n}\n\nexport type ChainLocation = {\n\ttype: 'chain';\n\tchain: {\n\t\ttype: 'keeta';\n\t\t/**\n\t\t * The network ID representing the Keeta network to interact with\n\t\t */\n\t\tnetworkId: bigint;\n\t} | {\n\t\ttype: 'evm';\n\t\t/**\n\t\t * The chain ID representing the EVM-based network to interact with\n\t\t */\n\t\tchainId: bigint;\n\t} | {\n\t\ttype: 'solana';\n\t\t/**\n\t\t * The genesis hash representing Solana network/cluster to interact with\n\t\t */\n\t\tgenesisHash: string;\n\t} | {\n\t\ttype: 'bitcoin';\n\t\t/**\n\t\t * The \"magic bytes\" representing the bitcoin network to interact with\n\t\t */\n\t\tmagicBytes: string;\n\t} | {\n\t\ttype: 'tron';\n\t\t/**\n\t\t * The network alias representing the Tron network to interact with\n\t\t * Note: this is not the chain ID, but a human-readable alias because tron does not use chain/network IDs or any similar way to differentiate networks\n\t\t */\n\t\tnetworkAlias: 'mainnet' | 'shasta' | 'nile' | `custom:${string}`;\n\t}\n};\n\n\nexport type ChainLocationType = ChainLocation['chain']['type'];\n\nexport type PickChainLocation<T extends ChainLocationType = ChainLocationType> = BaseChainLocation<Extract<ChainLocation['chain'], { type: T }>>;\n\nexport function isChainLocation<T extends ChainLocationType>(input: AssetLocation, chainType?: T): input is PickChainLocation<T> {\n\tif (input.type !== 'chain') {\n\t\treturn(false);\n\t}\n\n\tif (chainType !== undefined) {\n\t\treturn(input.chain.type === chainType);\n\t}\n\n\treturn(true);\n}\n\nexport type AssetLocation = ChainLocation | BankLocation | MobileWalletLocation;\n\nexport type BankAccountType = BankAccountAddressObfuscated['accountType'];\nexport type MobileWalletAccountType = MobileWalletAddressObfuscated['accountType'];\n\ntype ChainLocationIDType = {\n\t[K in 'keeta' | 'evm']: bigint;\n} & {\n\t[K in 'solana' | 'bitcoin' | 'tron']: string;\n};\n\nexport type ChainLocationString<T extends ChainLocationType = ChainLocationType> = {\n\t[K in T]: `chain:${K}:${ChainLocationIDType[K]}`\n}[T];\n\nexport type AssetLocationString =\n\tChainLocationString |\n\t`bank-account:${BankAccountType}` |\n\t`mobile-wallet:${MobileWalletAccountType}`;\n\nexport type AssetLocationLike = AssetLocation | AssetLocationString;\n\nexport type AssetLocationInput = AssetLocation | AssetLocationString;\nexport type AssetLocationCanonical = AssetLocationString;\n\nexport function convertAssetLocationToString(input: AssetLocationLike): AssetLocationString {\n\tif (typeof input === 'string') {\n\t\treturn(input);\n\t}\n\n\tif (input.type === 'chain') {\n\t\tif (input.chain.type === 'keeta') {\n\t\t\treturn(`chain:keeta:${input.chain.networkId}`);\n\t\t} else if (input.chain.type === 'evm') {\n\t\t\treturn(`chain:evm:${input.chain.chainId}`);\n\t\t} else if (input.chain.type === 'solana') {\n\t\t\treturn(`chain:solana:${input.chain.genesisHash}`);\n\t\t} else if (input.chain.type === 'bitcoin') {\n\t\t\treturn(`chain:bitcoin:${input.chain.magicBytes}`);\n\t\t} else if (input.chain.type === 'tron') {\n\t\t\treturn(`chain:tron:${input.chain.networkAlias}`);\n\t\t} else {\n\t\t\tassertNever(input.chain);\n\t\t}\n\t} else if (input.type === 'bank-account') {\n\t\treturn(`bank-account:${assertBankAccountType(input.account.type)}`);\n\t} else if (input.type === 'mobile-wallet') {\n\t\treturn(`mobile-wallet:${assertMobileWalletAccountType(input.account.type)}`);\n\t} else {\n\t\tthrow(new Error(`Invalid AssetLocation type: ${JSON.stringify(input)}`));\n\t}\n}\n\nfunction validateSolanaGenesisHash(hash: string): boolean {\n\t// Basic validation: Solana genesis hashes are typically 44-character base58 strings\n\tconst genesisHashRegex = /^(?=.{43,44}$)[1-9A-HJ-NP-Za-km-z]+$/;\n\treturn(genesisHashRegex.test(hash));\n}\n\nfunction validateBitcoinMagicBytes(magicBytes: string): boolean {\n\tif (magicBytes.length !== 8) {\n\t\treturn(false);\n\t}\n\n\ttry {\n\t\tconst buffer = Buffer.from(magicBytes, 'hex');\n\t\treturn(buffer.length === 4);\n\t} catch {\n\t\treturn(false);\n\t}\n}\n\nexport function toAssetLocationFromString(input: string): AssetLocation {\n\tconst [ kind, ...parts ] = input.split(':');\n\n\tif (kind === 'chain') {\n\t\tif (parts.length !== 2) {\n\t\t\tthrow(new Error('Invalid AssetLocation chain string'));\n\t\t}\n\n\t\tconst chainType = parts[0];\n\t\tif (!parts[1] || typeof parts[1] !== 'string') {\n\t\t\tthrow(new Error('Invalid chain id in AssetLocation string'));\n\t\t}\n\n\n\t\treturn({\n\t\t\ttype: 'chain',\n\t\t\tchain: (() => {\n\t\t\t\tif (chainType === 'keeta' || chainType === 'evm') {\n\t\t\t\t\tconst chainId = BigInt(parts[1]);\n\n\t\t\t\t\tif (chainId < 0n) {\n\t\t\t\t\t\tthrow(new Error(`Invalid chain id in AssetLocation string: ${parts[1]}`));\n\t\t\t\t\t}\n\n\t\t\t\t\tif (chainType === 'keeta') {\n\t\t\t\t\t\treturn({\n\t\t\t\t\t\t\ttype: 'keeta',\n\t\t\t\t\t\t\tnetworkId: chainId\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (chainType === 'evm') {\n\t\t\t\t\t\treturn({\n\t\t\t\t\t\t\ttype: 'evm',\n\t\t\t\t\t\t\tchainId: chainId\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else if (chainType === 'solana') {\n\t\t\t\t\tconst genesisHash = parts[1];\n\t\t\t\t\tif (!validateSolanaGenesisHash(genesisHash)) {\n\t\t\t\t\t\tthrow(new Error(`Invalid Solana genesis hash in AssetLocation string: ${genesisHash}`));\n\t\t\t\t\t}\n\n\t\t\t\t\treturn({\n\t\t\t\t\t\ttype: 'solana',\n\t\t\t\t\t\tgenesisHash: genesisHash\n\t\t\t\t\t});\n\t\t\t\t} else if (chainType === 'bitcoin') {\n\t\t\t\t\tconst magicBytes = parts[1];\n\n\t\t\t\t\tif (!validateBitcoinMagicBytes(magicBytes)) {\n\t\t\t\t\t\tthrow(new Error(`Invalid Bitcoin magic bytes in AssetLocation string: ${magicBytes}`));\n\t\t\t\t\t}\n\n\t\t\t\t\treturn({\n\t\t\t\t\t\ttype: 'bitcoin',\n\t\t\t\t\t\tmagicBytes: magicBytes\n\t\t\t\t\t});\n\t\t\t\t} else if (chainType === 'tron') {\n\t\t\t\t\tconst networkAlias = parts[1];\n\t\t\t\t\tif (!isTronNetworkAlias(networkAlias)) {\n\t\t\t\t\t\tthrow(new Error(`Invalid Tron network alias in AssetLocation string: ${networkAlias}`));\n\t\t\t\t\t}\n\n\t\t\t\t\treturn({\n\t\t\t\t\t\ttype: 'tron',\n\t\t\t\t\t\tnetworkAlias: networkAlias\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tthrow(new Error(`Invalid chain type in AssetLocation string: ${chainType}`));\n\t\t\t})()\n\t\t});\n\t} else if (kind === 'bank-account') {\n\t\tif (parts.length !== 1) {\n\t\t\tthrow(new Error('Invalid AssetLocation bank-account string'));\n\t\t}\n\n\t\treturn({\n\t\t\ttype: 'bank-account',\n\t\t\taccount: { type: assertBankAccountType(parts[0]) }\n\t\t});\n\t} else if (kind === 'mobile-wallet') {\n\t\tif (parts.length !== 1) {\n\t\t\tthrow(new Error('Invalid AssetLocation mobile-wallet string'));\n\t\t}\n\n\t\treturn({\n\t\t\ttype: 'mobile-wallet',\n\t\t\taccount: { type: assertMobileWalletAccountType(parts[0]) }\n\t\t});\n\t} else {\n\t\tthrow(new Error('Invalid AssetLocation string'));\n\t}\n}\n\nexport function convertAssetLocationInputToCanonical(input: AssetLocationInput): AssetLocationCanonical {\n\tif (typeof input === 'string') {\n\t\treturn(input);\n\t} else if (typeof input === 'object' && input !== null) {\n\t\treturn(convertAssetLocationToString(input));\n\t}\n\n\tthrow(new Error(`Invalid AssetLocationInput type: ${typeof input}`));\n}\n\n\nexport function toAssetLocation(input: AssetLocationInput): AssetLocation {\n\tif (typeof input === 'string') {\n\t\treturn(toAssetLocationFromString(input));\n\t} else {\n\t\treturn(input);\n\t}\n}\n\nexport function isAssetLocationEqual(a: AssetLocationInput, b: AssetLocationInput): boolean {\n\treturn(convertAssetLocationInputToCanonical(a) === convertAssetLocationInputToCanonical(b));\n}\n"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as KeetaAnchorHTTPServer from '../../lib/http-server/index.js';
|
|
2
|
-
import type { KeetaAssetMovementAnchorCreatePersistentForwardingRequest, KeetaAssetMovementAnchorCreatePersistentForwardingResponse, KeetaAssetMovementAnchorInitiateTransferRequest, KeetaAssetMovementAnchorInitiateTransferResponse, KeetaAssetMovementAnchorGetTransferStatusResponse, KeetaAssetMovementAnchorlistTransactionsRequest, KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse, KeetaAssetMovementAnchorListPersistentForwardingRequest, KeetaAssetMovementAnchorListPersistentForwardingResponse, KeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse, KeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest, KeetaAssetMovementAnchorListForwardingAddressTemplateRequest, KeetaAssetMovementAnchorListForwardingAddressTemplateResponse, KeetaAssetMovementAnchorShareKYCRequest, KeetaAssetMovementAnchorShareKYCResponse } from './common.ts';
|
|
2
|
+
import type { KeetaAssetMovementAnchorCreatePersistentForwardingRequest, KeetaAssetMovementAnchorCreatePersistentForwardingResponse, KeetaAssetMovementAnchorInitiateTransferRequest, KeetaAssetMovementAnchorInitiateTransferResponse, KeetaAssetMovementAnchorGetTransferStatusResponse, KeetaAssetMovementAnchorlistTransactionsRequest, KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse, KeetaAssetMovementAnchorListPersistentForwardingRequest, KeetaAssetMovementAnchorListPersistentForwardingResponse, KeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateRequest, KeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateResponse, KeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse, KeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest, KeetaAssetMovementAnchorListForwardingAddressTemplateRequest, KeetaAssetMovementAnchorListForwardingAddressTemplateResponse, KeetaAssetMovementAnchorShareKYCRequest, KeetaAssetMovementAnchorShareKYCResponse, KeetaAssetMovementAnchorExecuteTransferRequest, KeetaAssetMovementAnchorExecuteTransferResponse, KeetaAssetMovementAnchorSimulateTransferRequest, KeetaAssetMovementAnchorSimulateTransferResponse } from './common.ts';
|
|
3
3
|
import type { ServiceMetadata } from '../../lib/resolver.ts';
|
|
4
4
|
import type Account from '@keetanetwork/keetanet-client/lib/account.js';
|
|
5
5
|
import type { ExtractOk } from '../../lib/http-server/common.js';
|
|
6
|
+
import type { SharedAnchorMetadataLegalExtension } from '../../lib/metadata.types.js';
|
|
7
|
+
type AssetMovementServiceMetadata = NonNullable<ServiceMetadata['services']['assetMovement']>[string];
|
|
6
8
|
export interface KeetaAnchorAssetMovementServerConfig extends KeetaAnchorHTTPServer.KeetaAnchorHTTPServerConfig {
|
|
7
9
|
/**
|
|
8
10
|
* The data to use for the index page (optional)
|
|
@@ -11,14 +13,16 @@ export interface KeetaAnchorAssetMovementServerConfig extends KeetaAnchorHTTPSer
|
|
|
11
13
|
/**
|
|
12
14
|
* Configuration for asset movement operations
|
|
13
15
|
*/
|
|
14
|
-
assetMovement: {
|
|
16
|
+
assetMovement: SharedAnchorMetadataLegalExtension & Pick<AssetMovementServiceMetadata, 'supportedAssets' | 'locationMetadata'> & {
|
|
17
|
+
authenticationRequired?: boolean;
|
|
15
18
|
/**
|
|
16
|
-
*
|
|
19
|
+
* Method to initiate the two-step creation of a persistent forwarding address template.
|
|
20
|
+
* Returns a session ID and provider-specific data (e.g. a Plaid link token) for the client to complete.
|
|
17
21
|
*/
|
|
18
|
-
|
|
19
|
-
authenticationRequired?: boolean;
|
|
22
|
+
initiatePersistentForwardingTemplate?: (request: KeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateResponse>>;
|
|
20
23
|
/**
|
|
21
|
-
* Method to create a persistent forwarding address template
|
|
24
|
+
* Method to create a persistent forwarding address template.
|
|
25
|
+
* Accepts either a direct resolved address or a session completion payload (e.g. Plaid public token).
|
|
22
26
|
*/
|
|
23
27
|
createPersistentForwardingTemplate?: (request: KeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse>>;
|
|
24
28
|
/**
|
|
@@ -37,6 +41,10 @@ export interface KeetaAnchorAssetMovementServerConfig extends KeetaAnchorHTTPSer
|
|
|
37
41
|
* Method to initiate a transfer
|
|
38
42
|
*/
|
|
39
43
|
initiateTransfer?: (request: KeetaAssetMovementAnchorInitiateTransferRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorInitiateTransferResponse>>;
|
|
44
|
+
/**
|
|
45
|
+
* Method to initiate a transfer
|
|
46
|
+
*/
|
|
47
|
+
simulateTransfer?: (request: KeetaAssetMovementAnchorSimulateTransferRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorSimulateTransferResponse>>;
|
|
40
48
|
/**
|
|
41
49
|
* Method to get the status of a transfer
|
|
42
50
|
*/
|
|
@@ -49,6 +57,12 @@ export interface KeetaAnchorAssetMovementServerConfig extends KeetaAnchorHTTPSer
|
|
|
49
57
|
* Method to share KYC (Know Your Customer) information
|
|
50
58
|
*/
|
|
51
59
|
shareKYC?: (request: KeetaAssetMovementAnchorShareKYCRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorShareKYCResponse>>;
|
|
60
|
+
/**
|
|
61
|
+
* Method to execute a transfer instruction, used for pull based transactions
|
|
62
|
+
*/
|
|
63
|
+
executeTransfer?: (request: KeetaAssetMovementAnchorExecuteTransferRequest & {
|
|
64
|
+
id: string;
|
|
65
|
+
}) => Promise<ExtractOk<KeetaAssetMovementAnchorExecuteTransferResponse>>;
|
|
52
66
|
};
|
|
53
67
|
}
|
|
54
68
|
export declare class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHTTPServer.KeetaNetAnchorHTTPServer<KeetaAnchorAssetMovementServerConfig> implements Required<KeetaAnchorAssetMovementServerConfig> {
|
|
@@ -58,4 +72,5 @@ export declare class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHT
|
|
|
58
72
|
protected initRoutes(config: KeetaAnchorAssetMovementServerConfig): Promise<KeetaAnchorHTTPServer.Routes>;
|
|
59
73
|
serviceMetadata(): Promise<NonNullable<ServiceMetadata['services']['assetMovement']>[string]>;
|
|
60
74
|
}
|
|
75
|
+
export {};
|
|
61
76
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/services/asset-movement/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,qBAAqB,MAAM,gCAAgC,CAAC;AAKxE,OAAO,KAAK,EACX,yDAAyD,EACzD,0DAA0D,EAC1D,+CAA+C,EAC/C,gDAAgD,EAChD,iDAAiD,EACjD,+CAA+C,EAC/C,oEAAoE,EACpE,uDAAuD,EACvD,wDAAwD,EACxD,yEAAyE,EACzE,wEAAwE,EACxE,4DAA4D,EAC5D,6DAA6D,EAC7D,uCAAuC,EACvC,wCAAwC,EACxC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/services/asset-movement/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,qBAAqB,MAAM,gCAAgC,CAAC;AAKxE,OAAO,KAAK,EACX,yDAAyD,EACzD,0DAA0D,EAC1D,+CAA+C,EAC/C,gDAAgD,EAChD,iDAAiD,EACjD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CAAC;IACxM,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,oCAAoC,CAAC,UAAU,CAAC,CAAC,CAAC;IACjF,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,oCAAoC,CAAC,eAAe,CAAC,CAAC,CAAC;gBAE/E,MAAM,EAAE,oCAAoC;cAOxC,UAAU,CAAC,MAAM,EAAE,oCAAoC,GAAG,OAAO,CAAC,qBAAqB,CAAC,MAAM,CAAC;IA+VzG,eAAe,IAAI,OAAO,CAAC,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;CAmDnG"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as KeetaAnchorHTTPServer from '../../lib/http-server/index.js';
|
|
2
2
|
import { KeetaNet } from '../../client/index.js';
|
|
3
3
|
import { KeetaAnchorUserError } from '../../lib/error.js';
|
|
4
|
-
import { assertKeetaAssetMovementAnchorCreatePersistentForwardingRequest, assertKeetaAssetMovementAnchorCreatePersistentForwardingResponse, assertKeetaAssetMovementAnchorInitiateTransferRequest, assertKeetaAssetMovementAnchorInitiateTransferResponse, assertKeetaAssetMovementAnchorGetTransferStatusResponse, assertKeetaAssetMovementAnchorlistTransactionsRequest, assertKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse, assertKeetaAssetMovementAnchorListPersistentForwardingRequest, assertKeetaAssetMovementAnchorListPersistentForwardingResponse, assertKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest, assertKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse, getKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequestSigningData, assertKeetaAssetMovementAnchorListForwardingAddressTemplateRequest, assertKeetaAssetMovementAnchorListForwardingAddressTemplateResponse, getKeetaAssetMovementAnchorListForwardingAddressTemplateRequestSigningData, getKeetaAssetMovementAnchorGetTransferStatusRequestSigningData, getKeetaAssetMovementAnchorInitiateTransferRequestSigningData, assertKeetaAssetMovementAnchorShareKYCResponse, assertKeetaAssetMovementAnchorShareKYCRequest, getKeetaAssetMovementAnchorShareKYCRequestSigningData, convertAssetLocationToString, commonJSONStringify, getKeetaAssetMovementAnchorCreatePersistentForwardingRequestSigningData, getKeetaAssetMovementAnchorlistTransactionsRequestSigningData, getKeetaAssetMovementAnchorListPersistentForwardingRequestSigningData } from './common.js';
|
|
4
|
+
import { assertKeetaAssetMovementAnchorCreatePersistentForwardingRequest, assertKeetaAssetMovementAnchorCreatePersistentForwardingResponse, assertKeetaAssetMovementAnchorInitiateTransferRequest, assertKeetaAssetMovementAnchorInitiateTransferResponse, assertKeetaAssetMovementAnchorGetTransferStatusResponse, assertKeetaAssetMovementAnchorlistTransactionsRequest, assertKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse, assertKeetaAssetMovementAnchorListPersistentForwardingRequest, assertKeetaAssetMovementAnchorListPersistentForwardingResponse, assertKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateRequest, assertKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateResponse, getKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateRequestSigningData, assertKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest, assertKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse, getKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequestSigningData, assertKeetaAssetMovementAnchorListForwardingAddressTemplateRequest, assertKeetaAssetMovementAnchorListForwardingAddressTemplateResponse, getKeetaAssetMovementAnchorListForwardingAddressTemplateRequestSigningData, getKeetaAssetMovementAnchorGetTransferStatusRequestSigningData, getKeetaAssetMovementAnchorInitiateTransferRequestSigningData, assertKeetaAssetMovementAnchorShareKYCResponse, assertKeetaAssetMovementAnchorShareKYCRequest, getKeetaAssetMovementAnchorShareKYCRequestSigningData, convertAssetLocationToString, commonJSONStringify, getKeetaAssetMovementAnchorCreatePersistentForwardingRequestSigningData, getKeetaAssetMovementAnchorlistTransactionsRequestSigningData, getKeetaAssetMovementAnchorListPersistentForwardingRequestSigningData, getKeetaAssetMovementAnchorExecuteTransferRequestSigningData, assertKeetaAssetMovementAnchorExecuteTransferRequest, assertKeetaAssetMovementAnchorExecuteTransferResponse, getKeetaAssetMovementAnchorSimulateTransferRequestSigningData, assertKeetaAssetMovementAnchorSimulateTransferRequest, assertKeetaAssetMovementAnchorSimulateTransferResponse } from './common.js';
|
|
5
5
|
import { VerifySignedData } from '../../lib/utils/signing.js';
|
|
6
6
|
import { assertHTTPSignedField, parseSignatureFromURL } from '../../lib/http-server/common.js';
|
|
7
7
|
;
|
|
@@ -63,7 +63,7 @@ export class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHTTPServer
|
|
|
63
63
|
if (typeof handler !== 'function') {
|
|
64
64
|
throw (new Error(`internal error: handler for ${String(input.handlerName)} is not a function`));
|
|
65
65
|
}
|
|
66
|
-
const authenticationRequired = config.assetMovement.authenticationRequired === true;
|
|
66
|
+
const authenticationRequired = config.assetMovement.authenticationRequired === true && (input.overrideAllowUnauthenticated !== true);
|
|
67
67
|
routes[`${input.method} /api/${input.pathName ?? input.handlerName}`] = async function (params, postData, _ignore_headers, url) {
|
|
68
68
|
let request;
|
|
69
69
|
if (input.method === 'GET') {
|
|
@@ -115,6 +115,7 @@ export class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHTTPServer
|
|
|
115
115
|
else {
|
|
116
116
|
parsedRequest = [request, account];
|
|
117
117
|
}
|
|
118
|
+
// @ts-ignore
|
|
118
119
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
119
120
|
const result = await handler(...parsedRequest);
|
|
120
121
|
if ('ok' in result && (result.ok !== undefined && result.ok !== true)) {
|
|
@@ -184,6 +185,59 @@ export class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHTTPServer
|
|
|
184
185
|
});
|
|
185
186
|
}
|
|
186
187
|
});
|
|
188
|
+
addRoute({
|
|
189
|
+
method: 'POST',
|
|
190
|
+
handlerName: 'simulateTransfer',
|
|
191
|
+
overrideAllowUnauthenticated: true,
|
|
192
|
+
getSigningData: getKeetaAssetMovementAnchorSimulateTransferRequestSigningData,
|
|
193
|
+
assertRequest: assertKeetaAssetMovementAnchorSimulateTransferRequest,
|
|
194
|
+
assertResponse: assertKeetaAssetMovementAnchorSimulateTransferResponse,
|
|
195
|
+
serializeResponse(data) {
|
|
196
|
+
return ({
|
|
197
|
+
...data,
|
|
198
|
+
instructionChoices: data.instructionChoices.map(function (choice) {
|
|
199
|
+
const ret = { ...choice };
|
|
200
|
+
if ('location' in ret) {
|
|
201
|
+
ret.location = convertAssetLocationToString(ret.location);
|
|
202
|
+
}
|
|
203
|
+
return (ret);
|
|
204
|
+
})
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
addRoute({
|
|
209
|
+
method: 'POST',
|
|
210
|
+
handlerName: 'executeTransfer',
|
|
211
|
+
pathName: 'executeTransfer/:id',
|
|
212
|
+
getSigningData: function (data, params) {
|
|
213
|
+
const id = params.get('id');
|
|
214
|
+
if (typeof id !== 'string' || id.length === 0) {
|
|
215
|
+
throw (new KeetaAnchorUserError('Missing or invalid id parameter'));
|
|
216
|
+
}
|
|
217
|
+
return (getKeetaAssetMovementAnchorExecuteTransferRequestSigningData({
|
|
218
|
+
id: id,
|
|
219
|
+
...data
|
|
220
|
+
}));
|
|
221
|
+
},
|
|
222
|
+
parseRequestToArgs: ({ body, params }) => {
|
|
223
|
+
const id = params.get('id');
|
|
224
|
+
if (typeof id !== 'string' || id.length === 0) {
|
|
225
|
+
throw (new KeetaAnchorUserError('Missing or invalid id parameter'));
|
|
226
|
+
}
|
|
227
|
+
if (!body) {
|
|
228
|
+
throw (new KeetaAnchorUserError('Missing or invalid request body'));
|
|
229
|
+
}
|
|
230
|
+
return [{ id, ...body }];
|
|
231
|
+
},
|
|
232
|
+
assertRequest: assertKeetaAssetMovementAnchorExecuteTransferRequest,
|
|
233
|
+
assertResponse: assertKeetaAssetMovementAnchorExecuteTransferResponse,
|
|
234
|
+
serializeResponse(data) {
|
|
235
|
+
return ({
|
|
236
|
+
...data,
|
|
237
|
+
transaction: serializeTransactionResponse(data.transaction)
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
});
|
|
187
241
|
addRoute({
|
|
188
242
|
method: 'GET',
|
|
189
243
|
handlerName: 'getTransferStatus',
|
|
@@ -230,6 +284,13 @@ export class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHTTPServer
|
|
|
230
284
|
});
|
|
231
285
|
}
|
|
232
286
|
});
|
|
287
|
+
addRoute({
|
|
288
|
+
method: 'POST',
|
|
289
|
+
handlerName: 'initiatePersistentForwardingTemplate',
|
|
290
|
+
assertRequest: assertKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateRequest,
|
|
291
|
+
assertResponse: assertKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateResponse,
|
|
292
|
+
getSigningData: getKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateRequestSigningData
|
|
293
|
+
});
|
|
233
294
|
addRoute({
|
|
234
295
|
method: 'POST',
|
|
235
296
|
handlerName: 'createPersistentForwardingTemplate',
|
|
@@ -269,13 +330,16 @@ export class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHTTPServer
|
|
|
269
330
|
const operations = {};
|
|
270
331
|
const routes = [
|
|
271
332
|
'initiateTransfer',
|
|
333
|
+
'simulateTransfer',
|
|
272
334
|
'listTransactions',
|
|
335
|
+
'initiatePersistentForwardingTemplate',
|
|
273
336
|
'createPersistentForwardingTemplate',
|
|
274
337
|
'listPersistentForwardingTemplate',
|
|
275
338
|
'createPersistentForwarding',
|
|
276
339
|
'listPersistentForwarding',
|
|
277
340
|
'shareKYC',
|
|
278
|
-
['getTransferStatus', 'getTransferStatus/{id}']
|
|
341
|
+
['getTransferStatus', 'getTransferStatus/{id}'],
|
|
342
|
+
['executeTransfer', 'executeTransfer/{id}']
|
|
279
343
|
];
|
|
280
344
|
for (const routeInput of routes) {
|
|
281
345
|
let op;
|
|
@@ -305,6 +369,8 @@ export class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHTTPServer
|
|
|
305
369
|
throw (new KeetaAnchorUserError('No operations are supported on this server'));
|
|
306
370
|
}
|
|
307
371
|
return ({
|
|
372
|
+
...(this.assetMovement.legal ? { legal: this.assetMovement.legal } : {}),
|
|
373
|
+
...(this.assetMovement.locationMetadata ? { locationMetadata: this.assetMovement.locationMetadata } : {}),
|
|
308
374
|
operations: operations,
|
|
309
375
|
supportedAssets: this.assetMovement.supportedAssets
|
|
310
376
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/services/asset-movement/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,qBAAqB,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EACN,oBAAoB,EACpB,MAAM,oBAAoB,CAAC;AAkB5B,OAAO,EACN,+DAA+D,EAC/D,gEAAgE,EAChE,qDAAqD,EACrD,sDAAsD,EACtD,uDAAuD,EACvD,qDAAqD,EACrD,0EAA0E,EAC1E,6DAA6D,EAC7D,8DAA8D,EAC9D,8EAA8E,EAC9E,+EAA+E,EAC/E,sFAAsF,EACtF,kEAAkE,EAClE,mEAAmE,EACnE,0EAA0E,EAC1E,8DAA8D,EAC9D,6DAA6D,EAC7D,8CAA8C,EAC9C,6CAA6C,EAC7C,qDAAqD,EACrD,4BAA4B,EAC5B,mBAAmB,EACnB,uEAAuE,EACvE,6DAA6D,EAC7D,qEAAqE,EACrE,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AA4D9F,CAAC;AAEF,SAAS,4BAA4B,CA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B,GAAG,GAAG,UAAU,CAAC;YAClB,CAAC;YAED,IAAI,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,KAAK,SAAS,EAAE,CAAC;gBAC1C,MAAM,WAAW,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,GAAG,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;gBAClE,IAAI,IAAI,CAAC,aAAa,CAAC,sBAAsB,EAAE,CAAC;oBAC/C,UAAU,CAAC,EAAE,CAAC,GAAG;wBAChB,GAAG,EAAE,WAAW;wBAChB,OAAO,EAAE,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,UAAU,EAAE,EAAC;qBACzE,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACP,UAAU,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC;gBAC9B,CAAC;YACF,CAAC;QACF,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1C,MAAK,CAAC,IAAI,oBAAoB,CAAC,4CAA4C,CAAC,CAAC,CAAC;QAC/E,CAAC;QACD,OAAM,CAAC;YACN,UAAU,EAAE,UAAU;YACtB,eAAe,EAAE,IAAI,CAAC,aAAa,CAAC,eAAe;SACnD,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import * as KeetaAnchorHTTPServer from '../../lib/http-server/index.js';\nimport { KeetaNet } from '../../client/index.js';\nimport {\n\tKeetaAnchorUserError\n} from '../../lib/error.js';\nimport type {\n\tKeetaAssetMovementAnchorCreatePersistentForwardingRequest,\n\tKeetaAssetMovementAnchorCreatePersistentForwardingResponse,\n\tKeetaAssetMovementAnchorInitiateTransferRequest,\n\tKeetaAssetMovementAnchorInitiateTransferResponse,\n\tKeetaAssetMovementAnchorGetTransferStatusResponse,\n\tKeetaAssetMovementAnchorlistTransactionsRequest,\n\tKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse,\n\tKeetaAssetMovementAnchorListPersistentForwardingRequest,\n\tKeetaAssetMovementAnchorListPersistentForwardingResponse,\n\tKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse,\n\tKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest,\n\tKeetaAssetMovementAnchorListForwardingAddressTemplateRequest,\n\tKeetaAssetMovementAnchorListForwardingAddressTemplateResponse,\n\tKeetaAssetMovementAnchorShareKYCRequest,\n\tKeetaAssetMovementAnchorShareKYCResponse\n} from './common.ts';\nimport {\n\tassertKeetaAssetMovementAnchorCreatePersistentForwardingRequest,\n\tassertKeetaAssetMovementAnchorCreatePersistentForwardingResponse,\n\tassertKeetaAssetMovementAnchorInitiateTransferRequest,\n\tassertKeetaAssetMovementAnchorInitiateTransferResponse,\n\tassertKeetaAssetMovementAnchorGetTransferStatusResponse,\n\tassertKeetaAssetMovementAnchorlistTransactionsRequest,\n\tassertKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse,\n\tassertKeetaAssetMovementAnchorListPersistentForwardingRequest,\n\tassertKeetaAssetMovementAnchorListPersistentForwardingResponse,\n\tassertKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest,\n\tassertKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse,\n\tgetKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequestSigningData,\n\tassertKeetaAssetMovementAnchorListForwardingAddressTemplateRequest,\n\tassertKeetaAssetMovementAnchorListForwardingAddressTemplateResponse,\n\tgetKeetaAssetMovementAnchorListForwardingAddressTemplateRequestSigningData,\n\tgetKeetaAssetMovementAnchorGetTransferStatusRequestSigningData,\n\tgetKeetaAssetMovementAnchorInitiateTransferRequestSigningData,\n\tassertKeetaAssetMovementAnchorShareKYCResponse,\n\tassertKeetaAssetMovementAnchorShareKYCRequest,\n\tgetKeetaAssetMovementAnchorShareKYCRequestSigningData,\n\tconvertAssetLocationToString,\n\tcommonJSONStringify,\n\tgetKeetaAssetMovementAnchorCreatePersistentForwardingRequestSigningData,\n\tgetKeetaAssetMovementAnchorlistTransactionsRequestSigningData,\n\tgetKeetaAssetMovementAnchorListPersistentForwardingRequestSigningData\n} from './common.js';\nimport type { ServiceMetadata } from '../../lib/resolver.ts';\nimport type { Signable } from '../../lib/utils/signing.js';\nimport { VerifySignedData } from '../../lib/utils/signing.js';\nimport type Account from '@keetanetwork/keetanet-client/lib/account.js';\nimport type { ExtractOk, HTTPSignedFieldURLParameters } from '../../lib/http-server/common.js';\nimport { assertHTTPSignedField, parseSignatureFromURL } from '../../lib/http-server/common.js';\nimport type { JSONSerializable } from '@keetanetwork/keetanet-client/lib/utils/conversion.js';\n\nexport interface KeetaAnchorAssetMovementServerConfig extends KeetaAnchorHTTPServer.KeetaAnchorHTTPServerConfig {\n\t/**\n\t * The data to use for the index page (optional)\n\t */\n\thomepage?: string | (() => Promise<string> | string);\n\n\t/**\n\t * Configuration for asset movement operations\n\t */\n\tassetMovement: {\n\t\t/**\n\t\t * Supported assets and their configurations\n\t\t */\n\t\tsupportedAssets: NonNullable<ServiceMetadata['services']['assetMovement']>[string]['supportedAssets'];\n\n\t\tauthenticationRequired?: boolean;\n\n\t\t/**\n\t\t * Method to create a persistent forwarding address template\n\t\t */\n\t\tcreatePersistentForwardingTemplate?: (request: KeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse>>;\n\n\t\t/**\n\t\t * Method to list persistent forwarding address templates\n\t\t */\n\t\tlistPersistentForwardingTemplate?: (request: KeetaAssetMovementAnchorListForwardingAddressTemplateRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorListForwardingAddressTemplateResponse>>;\n\n\t\t/**\n\t\t * Method to create a persistent forwarding address\n\t\t */\n\t\tcreatePersistentForwarding?: (request: KeetaAssetMovementAnchorCreatePersistentForwardingRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorCreatePersistentForwardingResponse>>;\n\n\t\t/**\n\t\t * Method to list persistent forwarding addresses\n\t\t */\n\t\tlistPersistentForwarding?: (request: KeetaAssetMovementAnchorListPersistentForwardingRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorListPersistentForwardingResponse>>;\n\n\t\t/**\n\t\t * Method to initiate a transfer\n\t\t */\n\t\tinitiateTransfer?: (request: KeetaAssetMovementAnchorInitiateTransferRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorInitiateTransferResponse>>;\n\n\t\t/**\n\t\t * Method to get the status of a transfer\n\t\t */\n\t\tgetTransferStatus?: (id: string, account: Account.Account | null) => Promise<ExtractOk<KeetaAssetMovementAnchorGetTransferStatusResponse>>;\n\n\t\t/**\n\t\t * Method to list transactions\n\t\t */\n\t\tlistTransactions?: (request: KeetaAssetMovementAnchorlistTransactionsRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse>>;\n\n\t\t/**\n\t\t * Method to share KYC (Know Your Customer) information\n\t\t */\n\t\tshareKYC?: (request: KeetaAssetMovementAnchorShareKYCRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorShareKYCResponse>>;\n\t}\n};\n\nfunction serializeTransactionResponse(transaction: ExtractOk<KeetaAssetMovementAnchorGetTransferStatusResponse>['transaction']): ExtractOk<KeetaAssetMovementAnchorGetTransferStatusResponse>['transaction'] {\n\treturn({\n\t\t...transaction,\n\t\tfrom: {\n\t\t\t...transaction.from,\n\t\t\tlocation: convertAssetLocationToString(transaction.from.location)\n\t\t},\n\t\tto: {\n\t\t\t...transaction.to,\n\t\t\tlocation: convertAssetLocationToString(transaction.to.location)\n\t\t}\n\t});\n}\n\nfunction serializePersistentAddressTemplateResponse(template: ExtractOk<KeetaAssetMovementAnchorListForwardingAddressTemplateResponse>['templates'][number]): ExtractOk<KeetaAssetMovementAnchorListForwardingAddressTemplateResponse>['templates'][number] {\n\treturn({\n\t\t...template,\n\t\tlocation: convertAssetLocationToString(template.location)\n\t});\n}\n\nexport class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHTTPServer.KeetaNetAnchorHTTPServer<KeetaAnchorAssetMovementServerConfig> implements Required<KeetaAnchorAssetMovementServerConfig> {\n\treadonly homepage: NonNullable<KeetaAnchorAssetMovementServerConfig['homepage']>;\n\treadonly assetMovement: NonNullable<KeetaAnchorAssetMovementServerConfig['assetMovement']>;\n\n\tconstructor(config: KeetaAnchorAssetMovementServerConfig) {\n\t\tsuper(config);\n\n\t\tthis.homepage = config.homepage ?? '';\n\t\tthis.assetMovement = config.assetMovement;\n\t}\n\n\tprotected async initRoutes(config: KeetaAnchorAssetMovementServerConfig): Promise<KeetaAnchorHTTPServer.Routes> {\n\t\tconst routes: KeetaAnchorHTTPServer.Routes = {};\n\n\t\t/**\n\t\t * If a homepage is provided, setup the route for it\n\t\t */\n\t\tif ('homepage' in config) {\n\t\t\troutes['GET /'] = async function() {\n\t\t\t\tlet homepageData: string;\n\t\t\t\tif (typeof config.homepage === 'string') {\n\t\t\t\t\thomepageData = config.homepage;\n\t\t\t\t} else {\n\t\t\t\t\tif (!config.homepage) {\n\t\t\t\t\t\tthrow(new Error('internal error: No homepage function provided'));\n\t\t\t\t\t}\n\n\t\t\t\t\thomepageData = await config.homepage();\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: homepageData,\n\t\t\t\t\tcontentType: 'text/html'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tfunction addRoute<\n\t\t\tHandlerName extends keyof KeetaAnchorAssetMovementServerConfig['assetMovement'],\n\t\t\tSerializedRequest extends { [key: string]: unknown } | undefined,\n\t\t\tResponse\n\t\t>(input: {\n\t\t\tmethod: 'GET' | 'POST';\n\t\t\thandlerName: HandlerName;\n\t\t\tpathName?: string;\n\t\t\tassertRequest?: (data: unknown) => SerializedRequest;\n\t\t\tserializeResponse?: (data: ExtractOk<Response>) => unknown;\n\t\t\tassertResponse: (data: unknown) => Response;\n\t\t\tgetSigningData?: (data: SerializedRequest, params: Map<string, string>) => Signable;\n\t\t\tparseRequestToArgs?: (params: {\n\t\t\t\tparams: Map<string, string>;\n\t\t\t\tbody: JSONSerializable | SerializedRequest | undefined,\n\t\t\t\turl: URL,\n\t\t\t\taccount: Account.Account | null\n\t\t\t\t// Typescript needs any here, but eslint does not like it\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t}) => NonNullable<KeetaAnchorAssetMovementServerConfig['assetMovement'][HandlerName]> extends (...args: infer R extends [ any, Account.Account | null ]) => any ? R : never;\n\t\t\tgetSignatureFieldAccountFromRequest?: (params: { body: JSONSerializable | undefined, url: URL }) => Partial<HTTPSignedFieldURLParameters>;\n\t\t}) {\n\t\t\tconst handler = config.assetMovement[input.handlerName];\n\t\t\tif (handler === undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (typeof handler !== 'function') {\n\t\t\t\tthrow(new Error(`internal error: handler for ${String(input.handlerName)} is not a function`));\n\t\t\t}\n\n\t\t\tconst authenticationRequired = config.assetMovement.authenticationRequired === true;\n\n\t\t\troutes[`${input.method} /api/${input.pathName ?? input.handlerName}`] = async function(params, postData, _ignore_headers, url) {\n\t\t\t\tlet request: SerializedRequest;\n\t\t\t\tif (input.method === 'GET') {\n\t\t\t\t\t// For GET requests, we do not expect a body\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\trequest = undefined as SerializedRequest;\n\t\t\t\t} else {\n\t\t\t\t\tif (!input.assertRequest) {\n\t\t\t\t\t\tthrow(new Error('input.assertRequest is required when method = POST'));\n\t\t\t\t\t}\n\t\t\t\t\trequest = input.assertRequest(postData);\n\t\t\t\t}\n\n\t\t\t\tlet account: Account.Account | null = null;\n\t\t\t\tif (authenticationRequired || (request !== undefined && 'signed' in request)) {\n\t\t\t\t\tlet signed;\n\t\t\t\t\tif (input.getSignatureFieldAccountFromRequest !== undefined) {\n\t\t\t\t\t\tconst parsed = input.getSignatureFieldAccountFromRequest({ body: postData, url });\n\n\t\t\t\t\t\tif (!parsed.account || !parsed.signedField) {\n\t\t\t\t\t\t\tthrow(new KeetaAnchorUserError('Missing authentication information'));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\taccount = parsed.account;\n\t\t\t\t\t\tsigned = parsed.signedField;\n\t\t\t\t\t} else if (request) {\n\t\t\t\t\t\tif (!('account' in request) || !('signed' in request)) {\n\t\t\t\t\t\t\tthrow(new KeetaAnchorUserError('Missing authentication information'));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (typeof request.account !== 'string') {\n\t\t\t\t\t\t\tthrow(new KeetaAnchorUserError('Invalid account public key'));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\taccount = KeetaNet.lib.Account.fromPublicKeyString(request.account).assertAccount();\n\t\t\t\t\t\tsigned = assertHTTPSignedField(request.signed);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow(new Error('when request is not defined, getSignatureFieldAccountFromRequest must be provided'));\n\t\t\t\t\t}\n\n\t\t\t\t\tconst signable = input.getSigningData ? input.getSigningData(request, params) : [];\n\n\t\t\t\t\tconst valid = await VerifySignedData(account, signable, signed);\n\n\t\t\t\t\tif (!valid) {\n\t\t\t\t\t\tthrow(new KeetaAnchorUserError('Invalid signature'));\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\tlet parsedRequest: [ any, Account.Account | null ];\n\t\t\t\tif (input.parseRequestToArgs) {\n\t\t\t\t\tparsedRequest = input.parseRequestToArgs({ body: request, params, url, account: account ?? null });\n\t\t\t\t} else {\n\t\t\t\t\tparsedRequest = [ request, account ];\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\t\tconst result = await handler(...parsedRequest);\n\n\t\t\t\tif ('ok' in result && (result.ok !== undefined && result.ok !== true)) {\n\t\t\t\t\tthrow(new Error('internal error: response serialization must not have ok field'));\n\t\t\t\t}\n\n\t\t\t\tconst resp = input.assertResponse({ ...result, ok: true });\n\n\t\t\t\tlet serialized;\n\t\t\t\tif (input.serializeResponse) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\tserialized = input.serializeResponse(resp as ExtractOk<Response>);\n\t\t\t\t} else {\n\t\t\t\t\tserialized = resp;\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: commonJSONStringify(serialized)\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'createPersistentForwarding',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorCreatePersistentForwardingRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorCreatePersistentForwardingResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorCreatePersistentForwardingRequestSigningData,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\tsourceLocation: data.sourceLocation ? convertAssetLocationToString(data.sourceLocation) : undefined,\n\t\t\t\t\tdestinationLocation: data.destinationLocation ? convertAssetLocationToString(data.destinationLocation) : undefined\n\t\t\t\t})\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'listPersistentForwarding',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorListPersistentForwardingRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorListPersistentForwardingResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorListPersistentForwardingRequestSigningData,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\taddresses: data.addresses.map(addr => ({\n\t\t\t\t\t\t...addr,\n\t\t\t\t\t\tsourceLocation: addr.sourceLocation ? convertAssetLocationToString(addr.sourceLocation) : undefined,\n\t\t\t\t\t\tdestinationLocation: addr.destinationLocation ? convertAssetLocationToString(addr.destinationLocation) : undefined\n\t\t\t\t\t}))\n\t\t\t\t})\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'initiateTransfer',\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorInitiateTransferRequestSigningData,\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorInitiateTransferRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorInitiateTransferResponse,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\tinstructionChoices: data.instructionChoices.map(function(choice) {\n\t\t\t\t\t\tconst ret = { ...choice };\n\t\t\t\t\t\tif ('location' in ret) {\n\t\t\t\t\t\t\tret.location = convertAssetLocationToString(ret.location);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn(ret);\n\t\t\t\t\t})\n\t\t\t\t})\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'GET',\n\t\t\thandlerName: 'getTransferStatus',\n\t\t\tpathName: 'getTransferStatus/:id',\n\t\t\tassertRequest: (input) => {\n\t\t\t\tif (input !== undefined) {\n\t\t\t\t\tthrow(new KeetaAnchorUserError('No body expected for getTransferStatus'));\n\t\t\t\t}\n\n\t\t\t\treturn(undefined);\n\t\t\t},\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorGetTransferStatusResponse,\n\t\t\tgetSignatureFieldAccountFromRequest: ({ url }) => parseSignatureFromURL(url),\n\t\t\tparseRequestToArgs: ({ params, account }) => {\n\t\t\t\tconst id = params.get('id');\n\t\t\t\tif (typeof id !== 'string' || id.length === 0) {\n\t\t\t\t\tthrow(new KeetaAnchorUserError('Missing or invalid id parameter'));\n\t\t\t\t}\n\n\t\t\t\treturn([ id, account ] as const);\n\t\t\t},\n\t\t\tgetSigningData(_ignore_request, params) {\n\t\t\t\tconst id = params.get('id');\n\t\t\t\tif (typeof id !== 'string' || id.length === 0) {\n\t\t\t\t\tthrow(new KeetaAnchorUserError('Missing or invalid id parameter'));\n\t\t\t\t}\n\n\t\t\t\treturn(getKeetaAssetMovementAnchorGetTransferStatusRequestSigningData({ id }));\n\t\t\t},\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\ttransaction: serializeTransactionResponse(data.transaction)\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'listTransactions',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorlistTransactionsRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorlistTransactionsRequestSigningData,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\ttransactions: data.transactions.map(tx => serializeTransactionResponse(tx))\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'createPersistentForwardingTemplate',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequestSigningData,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\t...(serializePersistentAddressTemplateResponse(data))\n\t\t\t\t})\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'listPersistentForwardingTemplate',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorListForwardingAddressTemplateRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorListForwardingAddressTemplateResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorListForwardingAddressTemplateRequestSigningData,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\ttemplates: data.templates.map(template => serializePersistentAddressTemplateResponse(template))\n\t\t\t\t})\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'shareKYC',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorShareKYCRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorShareKYCResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorShareKYCRequestSigningData\n\t\t});\n\n\t\treturn(routes);\n\t}\n\n\tasync serviceMetadata(): Promise<NonNullable<ServiceMetadata['services']['assetMovement']>[string]> {\n\t\tconst operations: NonNullable<ServiceMetadata['services']['assetMovement']>[string]['operations'] = {};\n\n\t\tconst routes = [\n\t\t\t'initiateTransfer',\n\t\t\t'listTransactions',\n\t\t\t'createPersistentForwardingTemplate',\n\t\t\t'listPersistentForwardingTemplate',\n\t\t\t'createPersistentForwarding',\n\t\t\t'listPersistentForwarding',\n\t\t\t'shareKYC',\n\t\t\t[ 'getTransferStatus', 'getTransferStatus/{id}' ]\n\t\t] as const satisfies ((keyof typeof operations) | [ keyof typeof operations, string ])[];\n\n\t\tfor (const routeInput of routes) {\n\t\t\tlet op;\n\t\t\tlet url;\n\t\t\tif (Array.isArray(routeInput)) {\n\t\t\t\top = routeInput[0];\n\t\t\t\turl = routeInput[1];\n\t\t\t} else {\n\t\t\t\top = routeInput;\n\t\t\t\turl = routeInput;\n\t\t\t}\n\n\t\t\tif (this.assetMovement[op] !== undefined) {\n\t\t\t\tconst computedURL = (new URL(`/api/${url}`, this.url)).toString();\n\t\t\t\tif (this.assetMovement.authenticationRequired) {\n\t\t\t\t\toperations[op] = {\n\t\t\t\t\t\turl: computedURL,\n\t\t\t\t\t\toptions: { authentication: { method: 'keeta-account', type: 'required' }}\n\t\t\t\t\t};\n\t\t\t\t} else {\n\t\t\t\t\toperations[op] = computedURL;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (Object.keys(operations).length === 0) {\n\t\t\tthrow(new KeetaAnchorUserError('No operations are supported on this server'));\n\t\t}\n\t\treturn({\n\t\t\toperations: operations,\n\t\t\tsupportedAssets: this.assetMovement.supportedAssets\n\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/services/asset-movement/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,qBAAqB,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EACN,oBAAoB,EACpB,MAAM,oBAAoB,CAAC;AAwB5B,OAAO,EACN,+DAA+D,EAC/D,gEAAgE,EAChE,qDAAqD,EACrD,sDAAsD,EACtD,uDAAuD,EACvD,qDAAqD,EACrD,0EAA0E,EAC1E,6DAA6D,EAC7D,8DAA8D,EAC9D,gFAAgF,EAChF,iFAAiF,EACjF,wFAAwF,EACxF,8EAA8E,EAC9E,+EAA+E,EAC/E,sFAAsF,EACtF,kEAAkE,EAClE,mEAAmE,EACnE,0EAA0E,EAC1E,8DAA8D,EAC9D,6DAA6D,EAC7D,8CAA8C,EAC9C,6CAA6C,EAC7C,qDAAqD,EACrD,4BAA4B,EAC5B,mBAAmB,EACnB,uEAAuE,EACvE,6DAA6D,EAC7D,qEAAqE,EACrE,4DAA4D,EAC5D,oDAAoD,EACpD,qDAAqD,EACrD,6DAA6D,EAC7D,qDAAqD,EACrD,sDAAsD,EACtD,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AA2E9F,CAAC;AAEF,SAAS,4BAA4B,CAAC,WAAwF;IAC7H,OAAM,CAAC;QACN,GAAG,WAAW;QACd,IAAI,EAA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Ae,EAAE,IAAI,EAAE,UAAU,EAAE,EAAC;qBACzE,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACP,UAAU,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC;gBAC9B,CAAC;YACF,CAAC;QACF,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1C,MAAK,CAAC,IAAI,oBAAoB,CAAC,4CAA4C,CAAC,CAAC,CAAC;QAC/E,CAAC;QACD,OAAM,CAAC;YACN,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACxE,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACzG,UAAU,EAAE,UAAU;YACtB,eAAe,EAAE,IAAI,CAAC,aAAa,CAAC,eAAe;SACnD,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import * as KeetaAnchorHTTPServer from '../../lib/http-server/index.js';\nimport { KeetaNet } from '../../client/index.js';\nimport {\n\tKeetaAnchorUserError\n} from '../../lib/error.js';\nimport type {\n\tKeetaAssetMovementAnchorCreatePersistentForwardingRequest,\n\tKeetaAssetMovementAnchorCreatePersistentForwardingResponse,\n\tKeetaAssetMovementAnchorInitiateTransferRequest,\n\tKeetaAssetMovementAnchorInitiateTransferResponse,\n\tKeetaAssetMovementAnchorGetTransferStatusResponse,\n\tKeetaAssetMovementAnchorlistTransactionsRequest,\n\tKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse,\n\tKeetaAssetMovementAnchorListPersistentForwardingRequest,\n\tKeetaAssetMovementAnchorListPersistentForwardingResponse,\n\tKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateRequest,\n\tKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateResponse,\n\tKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse,\n\tKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest,\n\tKeetaAssetMovementAnchorListForwardingAddressTemplateRequest,\n\tKeetaAssetMovementAnchorListForwardingAddressTemplateResponse,\n\tKeetaAssetMovementAnchorShareKYCRequest,\n\tKeetaAssetMovementAnchorShareKYCResponse,\n\tKeetaAssetMovementAnchorExecuteTransferRequest,\n\tKeetaAssetMovementAnchorExecuteTransferResponse,\n\tKeetaAssetMovementAnchorSimulateTransferRequest,\n\tKeetaAssetMovementAnchorSimulateTransferResponse\n} from './common.ts';\nimport {\n\tassertKeetaAssetMovementAnchorCreatePersistentForwardingRequest,\n\tassertKeetaAssetMovementAnchorCreatePersistentForwardingResponse,\n\tassertKeetaAssetMovementAnchorInitiateTransferRequest,\n\tassertKeetaAssetMovementAnchorInitiateTransferResponse,\n\tassertKeetaAssetMovementAnchorGetTransferStatusResponse,\n\tassertKeetaAssetMovementAnchorlistTransactionsRequest,\n\tassertKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse,\n\tassertKeetaAssetMovementAnchorListPersistentForwardingRequest,\n\tassertKeetaAssetMovementAnchorListPersistentForwardingResponse,\n\tassertKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateRequest,\n\tassertKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateResponse,\n\tgetKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateRequestSigningData,\n\tassertKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest,\n\tassertKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse,\n\tgetKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequestSigningData,\n\tassertKeetaAssetMovementAnchorListForwardingAddressTemplateRequest,\n\tassertKeetaAssetMovementAnchorListForwardingAddressTemplateResponse,\n\tgetKeetaAssetMovementAnchorListForwardingAddressTemplateRequestSigningData,\n\tgetKeetaAssetMovementAnchorGetTransferStatusRequestSigningData,\n\tgetKeetaAssetMovementAnchorInitiateTransferRequestSigningData,\n\tassertKeetaAssetMovementAnchorShareKYCResponse,\n\tassertKeetaAssetMovementAnchorShareKYCRequest,\n\tgetKeetaAssetMovementAnchorShareKYCRequestSigningData,\n\tconvertAssetLocationToString,\n\tcommonJSONStringify,\n\tgetKeetaAssetMovementAnchorCreatePersistentForwardingRequestSigningData,\n\tgetKeetaAssetMovementAnchorlistTransactionsRequestSigningData,\n\tgetKeetaAssetMovementAnchorListPersistentForwardingRequestSigningData,\n\tgetKeetaAssetMovementAnchorExecuteTransferRequestSigningData,\n\tassertKeetaAssetMovementAnchorExecuteTransferRequest,\n\tassertKeetaAssetMovementAnchorExecuteTransferResponse,\n\tgetKeetaAssetMovementAnchorSimulateTransferRequestSigningData,\n\tassertKeetaAssetMovementAnchorSimulateTransferRequest,\n\tassertKeetaAssetMovementAnchorSimulateTransferResponse\n} from './common.js';\nimport type { ServiceMetadata } from '../../lib/resolver.ts';\nimport type { Signable } from '../../lib/utils/signing.js';\nimport { VerifySignedData } from '../../lib/utils/signing.js';\nimport type Account from '@keetanetwork/keetanet-client/lib/account.js';\nimport type { ExtractOk, HTTPSignedFieldURLParameters } from '../../lib/http-server/common.js';\nimport { assertHTTPSignedField, parseSignatureFromURL } from '../../lib/http-server/common.js';\nimport type { JSONSerializable } from '@keetanetwork/keetanet-client/lib/utils/conversion.js';\nimport type { SharedAnchorMetadataLegalExtension } from '../../lib/metadata.types.js';\n\ntype AssetMovementServiceMetadata = NonNullable<ServiceMetadata['services']['assetMovement']>[string];\n\nexport interface KeetaAnchorAssetMovementServerConfig extends KeetaAnchorHTTPServer.KeetaAnchorHTTPServerConfig {\n\t/**\n\t * The data to use for the index page (optional)\n\t */\n\thomepage?: string | (() => Promise<string> | string);\n\n\t/**\n\t * Configuration for asset movement operations\n\t */\n\tassetMovement: SharedAnchorMetadataLegalExtension & Pick<AssetMovementServiceMetadata, 'supportedAssets' | 'locationMetadata'> & {\n\t\tauthenticationRequired?: boolean;\n\n\t\t/**\n\t\t * Method to initiate the two-step creation of a persistent forwarding address template.\n\t\t * Returns a session ID and provider-specific data (e.g. a Plaid link token) for the client to complete.\n\t\t */\n\t\tinitiatePersistentForwardingTemplate?: (request: KeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateResponse>>;\n\n\t\t/**\n\t\t * Method to create a persistent forwarding address template.\n\t\t * Accepts either a direct resolved address or a session completion payload (e.g. Plaid public token).\n\t\t */\n\t\tcreatePersistentForwardingTemplate?: (request: KeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse>>;\n\n\t\t/**\n\t\t * Method to list persistent forwarding address templates\n\t\t */\n\t\tlistPersistentForwardingTemplate?: (request: KeetaAssetMovementAnchorListForwardingAddressTemplateRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorListForwardingAddressTemplateResponse>>;\n\n\t\t/**\n\t\t * Method to create a persistent forwarding address\n\t\t */\n\t\tcreatePersistentForwarding?: (request: KeetaAssetMovementAnchorCreatePersistentForwardingRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorCreatePersistentForwardingResponse>>;\n\n\t\t/**\n\t\t * Method to list persistent forwarding addresses\n\t\t */\n\t\tlistPersistentForwarding?: (request: KeetaAssetMovementAnchorListPersistentForwardingRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorListPersistentForwardingResponse>>;\n\n\t\t/**\n\t\t * Method to initiate a transfer\n\t\t */\n\t\tinitiateTransfer?: (request: KeetaAssetMovementAnchorInitiateTransferRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorInitiateTransferResponse>>;\n\n\t\t/**\n\t\t * Method to initiate a transfer\n\t\t */\n\t\tsimulateTransfer?: (request: KeetaAssetMovementAnchorSimulateTransferRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorSimulateTransferResponse>>;\n\n\t\t/**\n\t\t * Method to get the status of a transfer\n\t\t */\n\t\tgetTransferStatus?: (id: string, account: Account.Account | null) => Promise<ExtractOk<KeetaAssetMovementAnchorGetTransferStatusResponse>>;\n\n\t\t/**\n\t\t * Method to list transactions\n\t\t */\n\t\tlistTransactions?: (request: KeetaAssetMovementAnchorlistTransactionsRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse>>;\n\n\t\t/**\n\t\t * Method to share KYC (Know Your Customer) information\n\t\t */\n\t\tshareKYC?: (request: KeetaAssetMovementAnchorShareKYCRequest) => Promise<ExtractOk<KeetaAssetMovementAnchorShareKYCResponse>>;\n\n\t\t/**\n\t\t * Method to execute a transfer instruction, used for pull based transactions\n\t\t */\n\t\texecuteTransfer?: (request: KeetaAssetMovementAnchorExecuteTransferRequest & { id: string; }) => Promise<ExtractOk<KeetaAssetMovementAnchorExecuteTransferResponse>>;\n\t}\n};\n\nfunction serializeTransactionResponse(transaction: ExtractOk<KeetaAssetMovementAnchorGetTransferStatusResponse>['transaction']): ExtractOk<KeetaAssetMovementAnchorGetTransferStatusResponse>['transaction'] {\n\treturn({\n\t\t...transaction,\n\t\tfrom: {\n\t\t\t...transaction.from,\n\t\t\tlocation: convertAssetLocationToString(transaction.from.location)\n\t\t},\n\t\tto: {\n\t\t\t...transaction.to,\n\t\t\tlocation: convertAssetLocationToString(transaction.to.location)\n\t\t}\n\t});\n}\n\nfunction serializePersistentAddressTemplateResponse(template: ExtractOk<KeetaAssetMovementAnchorListForwardingAddressTemplateResponse>['templates'][number]): ExtractOk<KeetaAssetMovementAnchorListForwardingAddressTemplateResponse>['templates'][number] {\n\treturn({\n\t\t...template,\n\t\tlocation: convertAssetLocationToString(template.location)\n\t});\n}\n\nexport class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHTTPServer.KeetaNetAnchorHTTPServer<KeetaAnchorAssetMovementServerConfig> implements Required<KeetaAnchorAssetMovementServerConfig> {\n\treadonly homepage: NonNullable<KeetaAnchorAssetMovementServerConfig['homepage']>;\n\treadonly assetMovement: NonNullable<KeetaAnchorAssetMovementServerConfig['assetMovement']>;\n\n\tconstructor(config: KeetaAnchorAssetMovementServerConfig) {\n\t\tsuper(config);\n\n\t\tthis.homepage = config.homepage ?? '';\n\t\tthis.assetMovement = config.assetMovement;\n\t}\n\n\tprotected async initRoutes(config: KeetaAnchorAssetMovementServerConfig): Promise<KeetaAnchorHTTPServer.Routes> {\n\t\tconst routes: KeetaAnchorHTTPServer.Routes = {};\n\n\t\t/**\n\t\t * If a homepage is provided, setup the route for it\n\t\t */\n\t\tif ('homepage' in config) {\n\t\t\troutes['GET /'] = async function() {\n\t\t\t\tlet homepageData: string;\n\t\t\t\tif (typeof config.homepage === 'string') {\n\t\t\t\t\thomepageData = config.homepage;\n\t\t\t\t} else {\n\t\t\t\t\tif (!config.homepage) {\n\t\t\t\t\t\tthrow(new Error('internal error: No homepage function provided'));\n\t\t\t\t\t}\n\n\t\t\t\t\thomepageData = await config.homepage();\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: homepageData,\n\t\t\t\t\tcontentType: 'text/html'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\tfunction addRoute<\n\t\t\tHandlerName extends keyof KeetaAnchorAssetMovementServerConfig['assetMovement'],\n\t\t\tSerializedRequest extends { [key: string]: unknown } | undefined,\n\t\t\tResponse\n\t\t>(input: {\n\t\t\tmethod: 'GET' | 'POST';\n\t\t\thandlerName: HandlerName;\n\t\t\tpathName?: string;\n\t\t\toverrideAllowUnauthenticated?: boolean;\n\t\t\tassertRequest?: (data: unknown) => SerializedRequest;\n\t\t\tserializeResponse?: (data: ExtractOk<Response>) => unknown;\n\t\t\tassertResponse: (data: unknown) => Response;\n\t\t\tgetSigningData?: (data: SerializedRequest, params: Map<string, string>) => Signable;\n\t\t\tparseRequestToArgs?: (params: {\n\t\t\t\tparams: Map<string, string>;\n\t\t\t\tbody: SerializedRequest | undefined,\n\t\t\t\turl: URL,\n\t\t\t\taccount: Account.Account | null\n\t\t\t\t// Typescript needs any here, but eslint does not like it\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t}) => NonNullable<KeetaAnchorAssetMovementServerConfig['assetMovement'][HandlerName]> extends (...args: infer R extends any[]) => any ? R : never;\n\t\t\tgetSignatureFieldAccountFromRequest?: (params: { body: JSONSerializable | undefined, url: URL }) => Partial<HTTPSignedFieldURLParameters>;\n\t\t}) {\n\t\t\tconst handler = config.assetMovement[input.handlerName];\n\t\t\tif (handler === undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (typeof handler !== 'function') {\n\t\t\t\tthrow(new Error(`internal error: handler for ${String(input.handlerName)} is not a function`));\n\t\t\t}\n\n\t\t\tconst authenticationRequired = config.assetMovement.authenticationRequired === true && (input.overrideAllowUnauthenticated !== true);\n\n\t\t\troutes[`${input.method} /api/${input.pathName ?? input.handlerName}`] = async function(params, postData, _ignore_headers, url) {\n\t\t\t\tlet request: SerializedRequest;\n\t\t\t\tif (input.method === 'GET') {\n\t\t\t\t\t// For GET requests, we do not expect a body\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\trequest = undefined as SerializedRequest;\n\t\t\t\t} else {\n\t\t\t\t\tif (!input.assertRequest) {\n\t\t\t\t\t\tthrow(new Error('input.assertRequest is required when method = POST'));\n\t\t\t\t\t}\n\t\t\t\t\trequest = input.assertRequest(postData);\n\t\t\t\t}\n\n\t\t\t\tlet account: Account.Account | null = null;\n\t\t\t\tif (authenticationRequired || (request !== undefined && 'signed' in request)) {\n\t\t\t\t\tlet signed;\n\t\t\t\t\tif (input.getSignatureFieldAccountFromRequest !== undefined) {\n\t\t\t\t\t\tconst parsed = input.getSignatureFieldAccountFromRequest({ body: postData, url });\n\n\t\t\t\t\t\tif (!parsed.account || !parsed.signedField) {\n\t\t\t\t\t\t\tthrow(new KeetaAnchorUserError('Missing authentication information'));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\taccount = parsed.account;\n\t\t\t\t\t\tsigned = parsed.signedField;\n\t\t\t\t\t} else if (request) {\n\t\t\t\t\t\tif (!('account' in request) || !('signed' in request)) {\n\t\t\t\t\t\t\tthrow(new KeetaAnchorUserError('Missing authentication information'));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (typeof request.account !== 'string') {\n\t\t\t\t\t\t\tthrow(new KeetaAnchorUserError('Invalid account public key'));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\taccount = KeetaNet.lib.Account.fromPublicKeyString(request.account).assertAccount();\n\t\t\t\t\t\tsigned = assertHTTPSignedField(request.signed);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow(new Error('when request is not defined, getSignatureFieldAccountFromRequest must be provided'));\n\t\t\t\t\t}\n\n\t\t\t\t\tconst signable = input.getSigningData ? input.getSigningData(request, params) : [];\n\n\t\t\t\t\tconst valid = await VerifySignedData(account, signable, signed);\n\n\t\t\t\t\tif (!valid) {\n\t\t\t\t\t\tthrow(new KeetaAnchorUserError('Invalid signature'));\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\tlet parsedRequest: any[];\n\t\t\t\tif (input.parseRequestToArgs) {\n\t\t\t\t\tparsedRequest = input.parseRequestToArgs({ body: request, params, url, account: account ?? null });\n\t\t\t\t} else {\n\t\t\t\t\tparsedRequest = [ request, account ];\n\t\t\t\t}\n\n\t\t\t\t// @ts-ignore\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\t\tconst result = await handler(...parsedRequest);\n\n\t\t\t\tif ('ok' in result && (result.ok !== undefined && result.ok !== true)) {\n\t\t\t\t\tthrow(new Error('internal error: response serialization must not have ok field'));\n\t\t\t\t}\n\n\t\t\t\tconst resp = input.assertResponse({ ...result, ok: true });\n\n\t\t\t\tlet serialized;\n\t\t\t\tif (input.serializeResponse) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\tserialized = input.serializeResponse(resp as ExtractOk<Response>);\n\t\t\t\t} else {\n\t\t\t\t\tserialized = resp;\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: commonJSONStringify(serialized)\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'createPersistentForwarding',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorCreatePersistentForwardingRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorCreatePersistentForwardingResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorCreatePersistentForwardingRequestSigningData,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\tsourceLocation: data.sourceLocation ? convertAssetLocationToString(data.sourceLocation) : undefined,\n\t\t\t\t\tdestinationLocation: data.destinationLocation ? convertAssetLocationToString(data.destinationLocation) : undefined\n\t\t\t\t})\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'listPersistentForwarding',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorListPersistentForwardingRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorListPersistentForwardingResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorListPersistentForwardingRequestSigningData,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\taddresses: data.addresses.map(addr => ({\n\t\t\t\t\t\t...addr,\n\t\t\t\t\t\tsourceLocation: addr.sourceLocation ? convertAssetLocationToString(addr.sourceLocation) : undefined,\n\t\t\t\t\t\tdestinationLocation: addr.destinationLocation ? convertAssetLocationToString(addr.destinationLocation) : undefined\n\t\t\t\t\t}))\n\t\t\t\t})\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'initiateTransfer',\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorInitiateTransferRequestSigningData,\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorInitiateTransferRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorInitiateTransferResponse,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\tinstructionChoices: data.instructionChoices.map(function(choice) {\n\t\t\t\t\t\tconst ret = { ...choice };\n\t\t\t\t\t\tif ('location' in ret) {\n\t\t\t\t\t\t\tret.location = convertAssetLocationToString(ret.location);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn(ret);\n\t\t\t\t\t})\n\t\t\t\t})\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'simulateTransfer',\n\t\t\toverrideAllowUnauthenticated: true,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorSimulateTransferRequestSigningData,\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorSimulateTransferRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorSimulateTransferResponse,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\tinstructionChoices: data.instructionChoices.map(function(choice) {\n\t\t\t\t\t\tconst ret = { ...choice };\n\t\t\t\t\t\tif ('location' in ret) {\n\t\t\t\t\t\t\tret.location = convertAssetLocationToString(ret.location);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn(ret);\n\t\t\t\t\t})\n\t\t\t\t})\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'executeTransfer',\n\t\t\tpathName: 'executeTransfer/:id',\n\t\t\tgetSigningData: function(data, params) {\n\t\t\t\tconst id = params.get('id');\n\t\t\t\tif (typeof id !== 'string' || id.length === 0) {\n\t\t\t\t\tthrow(new KeetaAnchorUserError('Missing or invalid id parameter'));\n\t\t\t\t}\n\t\t\t\treturn(getKeetaAssetMovementAnchorExecuteTransferRequestSigningData({\n\t\t\t\t\tid: id,\n\t\t\t\t\t...data\n\t\t\t\t}));\n\t\t\t},\n\t\t\tparseRequestToArgs: ({ body, params }) => {\n\t\t\t\tconst id = params.get('id');\n\t\t\t\tif (typeof id !== 'string' || id.length === 0) {\n\t\t\t\t\tthrow(new KeetaAnchorUserError('Missing or invalid id parameter'));\n\t\t\t\t}\n\n\t\t\t\tif (!body) {\n\t\t\t\t\tthrow(new KeetaAnchorUserError('Missing or invalid request body'));\n\t\t\t\t}\n\n\t\t\t\treturn([ { id, ...body } ] as const);\n\t\t\t},\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorExecuteTransferRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorExecuteTransferResponse,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\ttransaction: serializeTransactionResponse(data.transaction)\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'GET',\n\t\t\thandlerName: 'getTransferStatus',\n\t\t\tpathName: 'getTransferStatus/:id',\n\t\t\tassertRequest: (input) => {\n\t\t\t\tif (input !== undefined) {\n\t\t\t\t\tthrow(new KeetaAnchorUserError('No body expected for getTransferStatus'));\n\t\t\t\t}\n\n\t\t\t\treturn(undefined);\n\t\t\t},\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorGetTransferStatusResponse,\n\t\t\tgetSignatureFieldAccountFromRequest: ({ url }) => parseSignatureFromURL(url),\n\t\t\tparseRequestToArgs: ({ params, account }) => {\n\t\t\t\tconst id = params.get('id');\n\t\t\t\tif (typeof id !== 'string' || id.length === 0) {\n\t\t\t\t\tthrow(new KeetaAnchorUserError('Missing or invalid id parameter'));\n\t\t\t\t}\n\n\t\t\t\treturn([ id, account ] as const);\n\t\t\t},\n\t\t\tgetSigningData(_ignore_request, params) {\n\t\t\t\tconst id = params.get('id');\n\t\t\t\tif (typeof id !== 'string' || id.length === 0) {\n\t\t\t\t\tthrow(new KeetaAnchorUserError('Missing or invalid id parameter'));\n\t\t\t\t}\n\n\t\t\t\treturn(getKeetaAssetMovementAnchorGetTransferStatusRequestSigningData({ id }));\n\t\t\t},\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\ttransaction: serializeTransactionResponse(data.transaction)\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'listTransactions',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorlistTransactionsRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorlistTransactionsRequestSigningData,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\ttransactions: data.transactions.map(tx => serializeTransactionResponse(tx))\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'initiatePersistentForwardingTemplate',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorInitiatePersistentForwardingAddressTemplateRequestSigningData\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'createPersistentForwardingTemplate',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorCreatePersistentForwardingAddressTemplateRequestSigningData,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\t...(serializePersistentAddressTemplateResponse(data))\n\t\t\t\t})\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'listPersistentForwardingTemplate',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorListForwardingAddressTemplateRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorListForwardingAddressTemplateResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorListForwardingAddressTemplateRequestSigningData,\n\t\t\tserializeResponse(data) {\n\t\t\t\treturn({\n\t\t\t\t\t...data,\n\t\t\t\t\ttemplates: data.templates.map(template => serializePersistentAddressTemplateResponse(template))\n\t\t\t\t})\n\t\t\t}\n\t\t});\n\n\t\taddRoute({\n\t\t\tmethod: 'POST',\n\t\t\thandlerName: 'shareKYC',\n\t\t\tassertRequest: assertKeetaAssetMovementAnchorShareKYCRequest,\n\t\t\tassertResponse: assertKeetaAssetMovementAnchorShareKYCResponse,\n\t\t\tgetSigningData: getKeetaAssetMovementAnchorShareKYCRequestSigningData\n\t\t});\n\n\t\treturn(routes);\n\t}\n\n\tasync serviceMetadata(): Promise<NonNullable<ServiceMetadata['services']['assetMovement']>[string]> {\n\t\tconst operations: NonNullable<ServiceMetadata['services']['assetMovement']>[string]['operations'] = {};\n\n\t\tconst routes = [\n\t\t\t'initiateTransfer',\n\t\t\t'simulateTransfer',\n\t\t\t'listTransactions',\n\t\t\t'initiatePersistentForwardingTemplate',\n\t\t\t'createPersistentForwardingTemplate',\n\t\t\t'listPersistentForwardingTemplate',\n\t\t\t'createPersistentForwarding',\n\t\t\t'listPersistentForwarding',\n\t\t\t'shareKYC',\n\t\t\t[ 'getTransferStatus', 'getTransferStatus/{id}' ],\n\t\t\t[ 'executeTransfer', 'executeTransfer/{id}' ]\n\t\t] as const satisfies ((keyof typeof operations) | [ keyof typeof operations, string ])[];\n\n\t\tfor (const routeInput of routes) {\n\t\t\tlet op;\n\t\t\tlet url;\n\t\t\tif (Array.isArray(routeInput)) {\n\t\t\t\top = routeInput[0];\n\t\t\t\turl = routeInput[1];\n\t\t\t} else {\n\t\t\t\top = routeInput;\n\t\t\t\turl = routeInput;\n\t\t\t}\n\n\t\t\tif (this.assetMovement[op] !== undefined) {\n\t\t\t\tconst computedURL = (new URL(`/api/${url}`, this.url)).toString();\n\t\t\t\tif (this.assetMovement.authenticationRequired) {\n\t\t\t\t\toperations[op] = {\n\t\t\t\t\t\turl: computedURL,\n\t\t\t\t\t\toptions: { authentication: { method: 'keeta-account', type: 'required' }}\n\t\t\t\t\t};\n\t\t\t\t} else {\n\t\t\t\t\toperations[op] = computedURL;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (Object.keys(operations).length === 0) {\n\t\t\tthrow(new KeetaAnchorUserError('No operations are supported on this server'));\n\t\t}\n\t\treturn({\n\t\t\t...(this.assetMovement.legal ? { legal: this.assetMovement.legal } : {}),\n\t\t\t...(this.assetMovement.locationMetadata ? { locationMetadata: this.assetMovement.locationMetadata } : {}),\n\t\t\toperations: operations,\n\t\t\tsupportedAssets: this.assetMovement.supportedAssets\n\t\t});\n\t}\n}\n"]}
|
package/services/fx/client.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type Resolver from '../../lib/resolver.ts';
|
|
|
6
6
|
import type { ServiceMetadata, SharedLookupCriteria } from '../../lib/resolver.ts';
|
|
7
7
|
import type { BrandedString } from '../../lib/utils/brand.ts';
|
|
8
8
|
import type { ConversionInput, ConversionInputCanonical, KeetaFXAnchorEstimate, KeetaFXAnchorExchange, KeetaFXAnchorQuote, KeetaNetTokenPublicKeyString } from './common.ts';
|
|
9
|
+
import type { SharedAnchorMetadataLegalExtension } from '../../lib/metadata.types.js';
|
|
9
10
|
/**
|
|
10
11
|
* An opaque type that represents a provider ID.
|
|
11
12
|
*/
|
|
@@ -63,12 +64,12 @@ type KeetaFXAnchorOperations = {
|
|
|
63
64
|
[key: string]: string;
|
|
64
65
|
}) => URL;
|
|
65
66
|
};
|
|
66
|
-
|
|
67
|
+
interface KeetaFXServiceInfo extends SharedAnchorMetadataLegalExtension {
|
|
67
68
|
operations: {
|
|
68
69
|
[operation in keyof KeetaFXAnchorOperations]: Promise<KeetaFXAnchorOperations[operation]>;
|
|
69
70
|
};
|
|
70
71
|
from: NonNullable<ServiceMetadata['services']['fx']>[string]['from'];
|
|
71
|
-
}
|
|
72
|
+
}
|
|
72
73
|
interface KeetaFXAnchorBaseConfig {
|
|
73
74
|
client: KeetaNetUserClient;
|
|
74
75
|
logger?: Logger | undefined;
|