@keetanetwork/anchor 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/index.d.ts +6 -0
- package/client/index.d.ts.map +1 -1
- package/client/index.js +7 -0
- package/client/index.js.map +1 -1
- package/lib/resolver.d.ts +59 -18
- package/lib/resolver.d.ts.map +1 -1
- package/lib/resolver.js +1368 -309
- package/lib/resolver.js.map +1 -1
- package/npm-shrinkwrap.json +5 -5
- package/package.json +2 -2
- package/services/asset-movement/client.d.ts +106 -0
- package/services/asset-movement/client.d.ts.map +1 -0
- package/services/asset-movement/client.js +279 -0
- package/services/asset-movement/client.js.map +1 -0
- package/services/asset-movement/common.d.ts +229 -0
- package/services/asset-movement/common.d.ts.map +1 -0
- package/services/asset-movement/common.js +2776 -0
- package/services/asset-movement/common.js.map +1 -0
- package/services/asset-movement/server.d.ts +60 -0
- package/services/asset-movement/server.d.ts.map +1 -0
- package/services/asset-movement/server.js +143 -0
- package/services/asset-movement/server.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/services/asset-movement/common.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAyElE,CAAC;AAMD,CAAC;AAyBF,sBAAsB;AACtB,WAAW;AACX,KAAK;AACL,YAAY;AACZ,6HAA6H;AAC7H,iJAAiJ;AACjJ,MAAM;AACN,MAAM;AACN,KAAK;AACL,YAAY;AACZ,kFAAkF;AAClF,yGAAyG;AACzG,MAAM;AACN,MAAM;AACN,KAAK;AACL,YAAY;AACZ,qFAAqF;AACrF,gGAAgG;AAChG,MAAM;AACN,KAAK;AACL,KAAK;AAE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AAM,CAAC,MAAM,0EAA0E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAuL,CAAC;AAE/Q,MAAM,CAAC,MAAM,4DAA4D;;;;;;;sFAAkK,CAAC;AAC5O,MAAM,CAAC,MAAM,kDAAkD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sFAA8I,CAAC;AAC9M,MAAM,CAAC,MAAM,mDAAmD;;;;;;;;;;;;sFAAgJ,CAAC;AACjN,MAAM,CAAC,MAAM,sEAAsE;;;;;;;;;;;;sFAAsL,CAAC","sourcesContent":["import type { ServiceMetadata } from '../../lib/resolver.ts';\nimport { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\nimport * as CurrencyInfo from '@keetanetwork/currency-info';\nimport type { TokenAddress, TokenPublicKeyString } from '@keetanetwork/keetanet-client/lib/account.js';\nimport { createAssert, createAssertEquals, createIs } from 'typia';\n\ntype HexString = `0x${string}`;\n\nexport type KeetaNetTokenPublicKeyString = ReturnType<InstanceType<typeof KeetaNetLib.Account<typeof KeetaNetLib.Account.AccountKeyAlgorithm.TOKEN>>['publicKeyString']['get']>;\n\ntype CurrencySearchInput = CurrencyInfo.ISOCurrencyCode | CurrencyInfo.ISOCurrencyNumber | CurrencyInfo.Currency;\ntype CurrencySearchCanonical = CurrencyInfo.ISOCurrencyCode; /* XXX:TODO */\n\ntype TokenSearchInput = TokenAddress | TokenPublicKeyString;\ntype TokenSearchCanonical = TokenPublicKeyString;\n\nexport type MovableAssetSearchInput = CurrencySearchInput | TokenSearchInput;\nexport type MovableAssetSearchCanonical = CurrencySearchCanonical | TokenSearchCanonical;\nexport type MovableAsset = TokenAddress | TokenPublicKeyString | CurrencyInfo.Currency;\n\nexport type AssetLocationInput = AssetLocation | AssetLocationString;\nexport type AssetLocationCanonical = AssetLocationString;\n\nexport type AssetMovementRail = unknown;\n\nexport type ProviderSearchInput = {\n\tasset: MovableAsset,\n\tfrom?: AssetLocationInput,\n\tto?: AssetLocationInput\n}\n/**\n * Defines the chain and id for a supported asset location\n */\nexport type AssetLocation = {\n\ttype: 'chain';\n\tchain: {\n\t\ttype: 'keeta';\n\t\tnetworkId: bigint;\n\t} | {\n\t\ttype: 'evm';\n\t\tchainId: bigint;\n\t}\n} | {\n\ttype: 'bank-account';\n\tworkInProgress?: never;\n}\n\n// Disable bank-account until it's implemented\nexport type AssetLocationString =\n\t`chain:${'keeta' | 'evm'}:${bigint}` |\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n\t`bank-account:${never}`;\n\nexport type AssetLocationLike = AssetLocation | AssetLocationString;\n\n// A given asset should have a location and ID for the contract or public key for that asset\nexport interface Asset {\n\tlocation?: AssetLocationString;\n\tid: string; // keeta token pub or evm contract address or currency code\n}\n\nexport type Rail = 'ACH_SEND' | 'ACH_DEBIT' | 'KEETA_SEND' | 'EVM_SEND' | 'EVM_CALL';\n\n// Rails can be inbound, outbound or common (inbound and outbound)\nexport interface AssetWithRails extends Asset {\n\trails: (({\n\t\tinbound: Rail[];\n\t\toutbound?: Rail[];\n\t} | {\n\t\tinbound?: Rail[];\n\t\toutbound: Rail[];\n\t} | {\n\t\tinbound?: never;\n\t\toutbound?: never;\n\t}) & {\n\t\tcommon?: Rail[];\n\t});\n};\n\n// A given asset path should consist of exactly one tuple of locations\nexport interface AssetPath {\n\tpair: [ AssetWithRails, AssetWithRails ];\n\tkycProviders?: string[];\n};\n\nexport interface SupportedAssets {\n\tasset: TokenPublicKeyString,\n\tpaths: AssetPath[]\n}\n\nexport interface AssetWithRailsMetadata {\n\tlocation: string;\n\tid: string;\n\trails: (({\n\t\tinbound: string[];\n\t\toutbound?: string[];\n\t} | {\n\t\tinbound?: string[];\n\t\toutbound: string[];\n\t} | {\n\t\tinbound?: never;\n\t\toutbound?: never;\n\t}) & {\n\t\tcommon?: string[];\n\t})\n}\n\n\n// Example Asset Paths\n// paths: [\n// \t{\n// \t\tpair: [\n// \t\t\t{ location: 'chain:keeta:123', id: 'keeta_KT1EXmXoG7fV8b2c5rYkUu4j3t6b3v6v5X8m', rails: { common: [ 'KEETA_SEND' ] } },\n// \t\t\t{ location: 'chain:evm:100', id: '0xc0634090F2Fe6c6d75e61Be2b949464aBB498973', rails: { common: [ 'EVM_SEND' ], inbound: [ 'EVM_CALL' ] } }\n// \t\t]\n// \t},\n// \t{\n// \t\tpair: [\n// \t\t\t{ location: 'chain:keeta:123', id: 'keeta_USDCPUB', rails: ['KEETA_SEND'] },\n// \t\t\t{ location: 'bank-account:US', id: 'USD', rails: { common: ['ACH_SEND'], inbound: ['ACH_DEBIT'] } }\n// \t\t]\n// \t},\n// \t{\n// \t\tpair: [\n// \t\t\t{ location: 'bank-account:EU', id: 'EUR', rails: { inbound: [ 'WIRE_SEND' }] },\n// \t\t\t{ location: 'chain:keeta:123', id: 'keeta_EURCPUB', rails: { outbound: [ 'KEETA_SEND' ]} }\n// \t\t]\n// \t}\n// ];\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}\n\t} else if (input.type === 'bank-account') {\n\t\tthrow(new Error('Cannot convert bank-account AssetLocation to string'));\n\t}\n\n\tthrow(new Error(`Invalid AssetLocation type: ${JSON.stringify(input)}`));\n}\n\nexport function toAssetLocationFromString(input: string): AssetLocation {\n\tconst parts = input.split(':');\n\n\tif (parts.length === 3 && parts[0] === 'chain') {\n\t\tconst chainType = parts[1];\n\t\tif (!parts[2] || typeof parts[2] !== 'string') {\n\t\t\tthrow(new Error('Invalid chain id in AssetLocation string'));\n\t\t}\n\n\t\tconst chainId = BigInt(parts[2]);\n\n\t\treturn({\n\t\t\ttype: 'chain',\n\t\t\tchain: (() => {\n\t\t\t\tif (chainType === 'keeta') {\n\t\t\t\t\treturn({\n\t\t\t\t\t\ttype: 'keeta',\n\t\t\t\t\t\tnetworkId: chainId\n\t\t\t\t\t});\n\t\t\t\t} else if (chainType === 'evm') {\n\t\t\t\t\treturn({\n\t\t\t\t\t\ttype: 'evm',\n\t\t\t\t\t\tchainId: chainId\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tthrow(new Error(`Invalid chain type in AssetLocation string: ${chainType}`));\n\t\t\t\t}\n\t\t\t})()\n\t\t});\n\t}\n\n\tthrow(new Error('unsupported AssetLocation string format'));\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\n\nexport function convertAssetSearchInputToCanonical(input: MovableAssetSearchInput): MovableAssetSearchCanonical {\n\tif (input instanceof CurrencyInfo.Currency || CurrencyInfo.Currency.isCurrencyCode(input) || CurrencyInfo.Currency.isISOCurrencyNumber(input)) {\n\t\tif (CurrencyInfo.Currency.isCurrencyCode(input)) {\n\t\t\treturn(input);\n\t\t} else if (CurrencyInfo.Currency.isISOCurrencyNumber(input)) {\n\t\t\tinput = new CurrencyInfo.Currency(input);\n\t\t}\n\n\t\treturn(input.code);\n\t} else {\n\t\tif (typeof input === 'string') {\n\t\t\treturn(input);\n\t\t}\n\n\t\tinput.assertKeyType(KeetaNetLib.Account.AccountKeyAlgorithm.TOKEN);\n\t\treturn(input.publicKeyString.get());\n\t}\n}\n\nexport type Operations = NonNullable<ServiceMetadata['services']['assetMovement']>[string]['operations'];\nexport type OperationNames = keyof Operations;\n\nexport type KeetaAssetMovementAnchorInitiateTransferRequest = {\n\tasset: MovableAsset;\n\tfrom: { location: AssetLocationLike };\n\tto: { location: AssetLocationLike; recipient: string; };\n\tvalue: string;\n\tallowedRails?: AssetMovementRail[];\n}\n\nexport type AssetTransferInstructions = ({\n\ttype: 'KEETA_SEND';\n\tlocation: AssetLocationLike;\n\n\tsendToAddress: string;\n\tvalue: string;\n\ttokenAddress: string;\n\n\texternal?: string;\n} | {\n\ttype: 'EVM_SEND';\n\tlocation: AssetLocationLike;\n\n\tsendToAddress: string;\n\tvalue: string;\n\ttokenAddress: HexString;\n} | {\n\ttype: 'EVM_CALL';\n\tlocation: AssetLocationLike;\n\n\tcontractAddress: string;\n\tcontractMethodName: string;\n\tcontractMethodArgs: string[];\n}) & ({\n\tassetFee: string;\n});\n\nexport type KeetaAssetMovementAnchorInitiateTransferResponse = ({\n\tok: true;\n\tid: string;\n\tinstructionChoices: AssetTransferInstructions[];\n}) | ({\n\tok: false;\n\terror: string;\n})\n\nexport interface KeetaAssetMovementAnchorGetTransferStatusRequest {\n\tid: string;\n}\n\ntype TransactionStatus = string;\n\nexport type TransactionId = {\n\tid: string;\n\tnonce: string;\n};\n\ntype TransactionIds<T extends string> = {\n\t[type in T]: TransactionId | null;\n};\n\nexport type KeetaAssetMovementTransaction = {\n\tid: string;\n\tstatus: TransactionStatus;\n\tasset: MovableAsset;\n\n\tfrom: {\n\t\tlocation: AssetLocationString;\n\t\tvalue: string;\n\t\ttransactions: TransactionIds<'persistentForwarding' | 'deposit' | 'finalization'>;\n\t};\n\n\tto: {\n\t\tlocation: AssetLocationString;\n\t\tvalue: string;\n\t\ttransactions: TransactionIds<'withdraw'>;\n\t};\n\n\tfee: {\n\t\tasset: MovableAsset;\n\t\tvalue: string;\n\t} | null;\n\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport type KeetaAssetMovementAnchorGetTransferStatusResponse = ({\n\tok: true;\n\ttransaction: KeetaAssetMovementTransaction;\n} | {\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaAssetMovementAnchorCreatePersistentForwardingRequest = {\n\tasset: MovableAsset;\n\tdestinationLocation: AssetLocationLike;\n\tdestinationAddress: string;\n\tsourceLocation: AssetLocationLike;\n}\n\nexport type KeetaAssetMovementAnchorCreatePersistentForwardingResponse = ({\n\tok: true;\n\taddress: string;\n} | {\n\tok: false;\n\terror: string;\n});\n\ntype PaginationQuery = {\n\tlimit?: number;\n\toffset?: number;\n}\n\ntype PaginationResponseInformation = {\n\ttotal: string;\n}\n\nexport type KeetaAssetMovementAnchorlistTransactionsRequest = {\n\tpersistentAddresses?: { location: AssetLocationLike; persistentAddress: string; }[];\n\tfrom?: { location: AssetLocationLike; userAddress?: string; asset?: MovableAsset; };\n\tto?: { location: AssetLocationLike; userAddress?: string; asset?: MovableAsset; };\n\tpagination?: PaginationQuery;\n}\n\nexport type KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse = (({\n\tok: true;\n\ttransactions: KeetaAssetMovementTransaction[] ;\n} & PaginationResponseInformation) | {\n\tok: false;\n\terror: string;\n});\n\nexport const assertKeetaSupportedAssets: (input: unknown) => SupportedAssets[] = createAssert<SupportedAssets[]>();\nexport const assertKeetaAssetMovementAnchorCreatePersistentForwardingRequest: (input: unknown) => KeetaAssetMovementAnchorCreatePersistentForwardingRequest = createAssert<KeetaAssetMovementAnchorCreatePersistentForwardingRequest>();\nexport const assertKeetaAssetMovementAnchorCreatePersistentForwardingResponse: (input: unknown) => KeetaAssetMovementAnchorCreatePersistentForwardingResponse = createAssertEquals<KeetaAssetMovementAnchorCreatePersistentForwardingResponse>();\nexport const assertKeetaAssetMovementAnchorInitiateTransferRequest: (input: unknown) => KeetaAssetMovementAnchorInitiateTransferRequest = createAssert<KeetaAssetMovementAnchorInitiateTransferRequest>();\nexport const assertKeetaAssetMovementAnchorInitiateTransferResponse: (input: unknown) => KeetaAssetMovementAnchorInitiateTransferResponse = createAssertEquals<KeetaAssetMovementAnchorInitiateTransferResponse>();\nexport const assertKeetaAssetMovementAnchorGetTransferStatusRequest: (input: unknown) => KeetaAssetMovementAnchorGetTransferStatusRequest = createAssert<KeetaAssetMovementAnchorGetTransferStatusRequest>();\nexport const assertKeetaAssetMovementAnchorGetTransferStatusResponse: (input: unknown) => KeetaAssetMovementAnchorGetTransferStatusResponse = createAssertEquals<KeetaAssetMovementAnchorGetTransferStatusResponse>();\nexport const assertKeetaAssetMovementAnchorlistTransactionsRequest: (input: unknown) => KeetaAssetMovementAnchorlistTransactionsRequest = createAssert<KeetaAssetMovementAnchorlistTransactionsRequest>();\nexport const assertKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse: (input: unknown) => KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse = createAssertEquals<KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse>();\n\nexport const isKeetaAssetMovementAnchorCreatePersistentForwardingResponse: (input: unknown) => input is KeetaAssetMovementAnchorCreatePersistentForwardingResponse = createIs<KeetaAssetMovementAnchorCreatePersistentForwardingResponse>();\nexport const isKeetaAssetMovementAnchorInitiateTransferResponse: (input: unknown) => input is KeetaAssetMovementAnchorInitiateTransferResponse = createIs<KeetaAssetMovementAnchorInitiateTransferResponse>();\nexport const isKeetaAssetMovementAnchorGetExchangeStatusResponse: (input: unknown) => input is KeetaAssetMovementAnchorGetTransferStatusResponse = createIs<KeetaAssetMovementAnchorGetTransferStatusResponse>();\nexport const isKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse: (input: unknown) => input is KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse = createIs<KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse>();\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as KeetaAnchorHTTPServer from '../../lib/http-server.js';
|
|
2
|
+
import type KeetaNet from '@keetanetwork/keetanet-client';
|
|
3
|
+
import type { KeetaAssetMovementAnchorCreatePersistentForwardingRequest, KeetaAssetMovementAnchorCreatePersistentForwardingResponse, KeetaAssetMovementAnchorInitiateTransferRequest, KeetaAssetMovementAnchorInitiateTransferResponse, KeetaAssetMovementAnchorGetTransferStatusResponse, KeetaAssetMovementAnchorlistTransactionsRequest, KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse } from './common.ts';
|
|
4
|
+
import type { ServiceMetadata } from '../../lib/resolver.ts';
|
|
5
|
+
export interface KeetaAnchorAssetMovementServerConfig extends KeetaAnchorHTTPServer.KeetaAnchorHTTPServerConfig {
|
|
6
|
+
/**
|
|
7
|
+
* The data to use for the index page (optional)
|
|
8
|
+
*/
|
|
9
|
+
homepage?: string | (() => Promise<string> | string);
|
|
10
|
+
/**
|
|
11
|
+
* The network client to use for submitting blocks
|
|
12
|
+
*/
|
|
13
|
+
client: {
|
|
14
|
+
client: KeetaNet.Client;
|
|
15
|
+
network: bigint;
|
|
16
|
+
networkAlias: typeof KeetaNet.Client.Config.networksArray[number];
|
|
17
|
+
} | KeetaNet.UserClient;
|
|
18
|
+
/**
|
|
19
|
+
* Configuration for asset movement operations
|
|
20
|
+
*/
|
|
21
|
+
assetMovement: {
|
|
22
|
+
/**
|
|
23
|
+
* Supported assets and their configurations
|
|
24
|
+
*/
|
|
25
|
+
supportedAssets: NonNullable<ServiceMetadata['services']['assetMovement']>[string]['supportedAssets'];
|
|
26
|
+
/**
|
|
27
|
+
* Method to create a persistent forwarding address
|
|
28
|
+
*/
|
|
29
|
+
createPersistentForwarding?: (request: KeetaAssetMovementAnchorCreatePersistentForwardingRequest) => Promise<Omit<Extract<KeetaAssetMovementAnchorCreatePersistentForwardingResponse, {
|
|
30
|
+
ok: true;
|
|
31
|
+
}>, 'ok'>>;
|
|
32
|
+
/**
|
|
33
|
+
* Method to initiate a transfer
|
|
34
|
+
*/
|
|
35
|
+
initiateTransfer?: (request: KeetaAssetMovementAnchorInitiateTransferRequest) => Promise<Omit<Extract<KeetaAssetMovementAnchorInitiateTransferResponse, {
|
|
36
|
+
ok: true;
|
|
37
|
+
}>, 'ok'>>;
|
|
38
|
+
/**
|
|
39
|
+
* Method to get the status of a transfer
|
|
40
|
+
*/
|
|
41
|
+
getTransferStatus?: (id: string) => Promise<Omit<Extract<KeetaAssetMovementAnchorGetTransferStatusResponse, {
|
|
42
|
+
ok: true;
|
|
43
|
+
}>, 'ok'>>;
|
|
44
|
+
/**
|
|
45
|
+
* Method to list transactions
|
|
46
|
+
*/
|
|
47
|
+
listTransactions?: (request: KeetaAssetMovementAnchorlistTransactionsRequest) => Promise<Omit<Extract<KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse, {
|
|
48
|
+
ok: true;
|
|
49
|
+
}>, 'ok'>>;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export declare class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHTTPServer.KeetaNetAnchorHTTPServer<KeetaAnchorAssetMovementServerConfig> implements Required<KeetaAnchorAssetMovementServerConfig> {
|
|
53
|
+
readonly homepage: NonNullable<KeetaAnchorAssetMovementServerConfig['homepage']>;
|
|
54
|
+
readonly client: KeetaAnchorAssetMovementServerConfig['client'];
|
|
55
|
+
readonly assetMovement: NonNullable<KeetaAnchorAssetMovementServerConfig['assetMovement']>;
|
|
56
|
+
constructor(config: KeetaAnchorAssetMovementServerConfig);
|
|
57
|
+
protected initRoutes(config: KeetaAnchorAssetMovementServerConfig): Promise<KeetaAnchorHTTPServer.Routes>;
|
|
58
|
+
serviceMetadata(): Promise<NonNullable<ServiceMetadata['services']['assetMovement']>[string]>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/services/asset-movement/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,qBAAqB,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAC;AAI1D,OAAO,KAAK,EACX,yDAAyD,EACzD,0DAA0D,EAC1D,+CAA+C,EAC/C,gDAAgD,EAEhD,iDAAiD,EACjD,+CAA+C,EAC/C,oEAAoE,EACpE,MAAM,aAAa,CAAC;AAWrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,WAAW,oCAAqC,SAAQ,qBAAqB,CAAC,2BAA2B;IAC9G;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;IAErD;;OAEG;IACH,MAAM,EAAE;QAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,OAAO,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;KAAE,GAAG,QAAQ,CAAC,UAAU,CAAC;IAE9I;;OAEG;IACH,aAAa,EAAE;QACd;;WAEG;QACH,eAAe,EAAE,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC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AC,MAAM,CAAC;IA+HzG,eAAe,IAAI,OAAO,CAAC,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;CAwBnG"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import * as KeetaAnchorHTTPServer from '../../lib/http-server.js';
|
|
2
|
+
import { KeetaAnchorUserError } from '../../lib/error.js';
|
|
3
|
+
import { assertKeetaAssetMovementAnchorCreatePersistentForwardingRequest, assertKeetaAssetMovementAnchorCreatePersistentForwardingResponse, assertKeetaAssetMovementAnchorInitiateTransferRequest, assertKeetaAssetMovementAnchorInitiateTransferResponse, assertKeetaAssetMovementAnchorGetTransferStatusRequest, assertKeetaAssetMovementAnchorGetTransferStatusResponse, assertKeetaAssetMovementAnchorlistTransactionsRequest, assertKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse } from './common.js';
|
|
4
|
+
;
|
|
5
|
+
export class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHTTPServer.KeetaNetAnchorHTTPServer {
|
|
6
|
+
homepage;
|
|
7
|
+
client;
|
|
8
|
+
assetMovement;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super(config);
|
|
11
|
+
this.homepage = config.homepage ?? '';
|
|
12
|
+
this.client = config.client;
|
|
13
|
+
this.assetMovement = config.assetMovement;
|
|
14
|
+
}
|
|
15
|
+
async initRoutes(config) {
|
|
16
|
+
const routes = {};
|
|
17
|
+
/**
|
|
18
|
+
* If a homepage is provided, setup the route for it
|
|
19
|
+
*/
|
|
20
|
+
if ('homepage' in config) {
|
|
21
|
+
routes['GET /'] = async function () {
|
|
22
|
+
let homepageData;
|
|
23
|
+
if (typeof config.homepage === 'string') {
|
|
24
|
+
homepageData = config.homepage;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
if (!config.homepage) {
|
|
28
|
+
throw (new Error('internal error: No homepage function provided'));
|
|
29
|
+
}
|
|
30
|
+
homepageData = await config.homepage();
|
|
31
|
+
}
|
|
32
|
+
return ({
|
|
33
|
+
output: homepageData,
|
|
34
|
+
contentType: 'text/html'
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Setup the various operation endpoints
|
|
40
|
+
*/
|
|
41
|
+
if (config.assetMovement.createPersistentForwarding !== undefined) {
|
|
42
|
+
routes['POST /api/createPersistentForwarding'] = async function (_ignore_params, postData) {
|
|
43
|
+
if (config.assetMovement.createPersistentForwarding === undefined) {
|
|
44
|
+
throw (new Error('internal error: createPersistentForwarding disappeared'));
|
|
45
|
+
}
|
|
46
|
+
const request = assertKeetaAssetMovementAnchorCreatePersistentForwardingRequest(postData);
|
|
47
|
+
const result = await config.assetMovement.createPersistentForwarding(request);
|
|
48
|
+
const output = {
|
|
49
|
+
...result,
|
|
50
|
+
ok: true
|
|
51
|
+
};
|
|
52
|
+
assertKeetaAssetMovementAnchorCreatePersistentForwardingResponse(output);
|
|
53
|
+
return ({
|
|
54
|
+
output: JSON.stringify(output)
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (config.assetMovement.initiateTransfer !== undefined) {
|
|
59
|
+
routes['POST /api/initiateTransfer'] = async function (_ignore_params, postData) {
|
|
60
|
+
if (config.assetMovement.initiateTransfer === undefined) {
|
|
61
|
+
throw (new Error('internal error: initiateTransfer disappeared'));
|
|
62
|
+
}
|
|
63
|
+
const request = assertKeetaAssetMovementAnchorInitiateTransferRequest(postData);
|
|
64
|
+
const result = await config.assetMovement.initiateTransfer(request);
|
|
65
|
+
const output = {
|
|
66
|
+
...result,
|
|
67
|
+
ok: true
|
|
68
|
+
};
|
|
69
|
+
assertKeetaAssetMovementAnchorInitiateTransferResponse(output);
|
|
70
|
+
return ({
|
|
71
|
+
output: JSON.stringify(output)
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (config.assetMovement.getTransferStatus !== undefined) {
|
|
76
|
+
routes['GET /api/getTransferStatus/:id'] = async function (params) {
|
|
77
|
+
if (config.assetMovement.getTransferStatus === undefined) {
|
|
78
|
+
throw (new Error('internal error: getTransferStatus disappeared'));
|
|
79
|
+
}
|
|
80
|
+
const id = params.get('id');
|
|
81
|
+
if (typeof id !== 'string' || id.length === 0) {
|
|
82
|
+
throw (new KeetaAnchorUserError('Missing or invalid id parameter'));
|
|
83
|
+
}
|
|
84
|
+
/*
|
|
85
|
+
* Validate the request against the defined schema
|
|
86
|
+
*/
|
|
87
|
+
const request = assertKeetaAssetMovementAnchorGetTransferStatusRequest({
|
|
88
|
+
id: id
|
|
89
|
+
});
|
|
90
|
+
const result = await config.assetMovement.getTransferStatus(request.id);
|
|
91
|
+
const output = {
|
|
92
|
+
...result,
|
|
93
|
+
ok: true
|
|
94
|
+
};
|
|
95
|
+
assertKeetaAssetMovementAnchorGetTransferStatusResponse(output);
|
|
96
|
+
return ({
|
|
97
|
+
output: JSON.stringify(output)
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (config.assetMovement.listTransactions !== undefined) {
|
|
102
|
+
routes['POST /api/listTransactions'] = async function (_ignore_params, postData) {
|
|
103
|
+
if (config.assetMovement.listTransactions === undefined) {
|
|
104
|
+
throw (new Error('internal error: listTransactions disappeared'));
|
|
105
|
+
}
|
|
106
|
+
const request = assertKeetaAssetMovementAnchorlistTransactionsRequest(postData);
|
|
107
|
+
const result = await config.assetMovement.listTransactions(request);
|
|
108
|
+
const output = {
|
|
109
|
+
...result,
|
|
110
|
+
ok: true
|
|
111
|
+
};
|
|
112
|
+
assertKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse(output);
|
|
113
|
+
return ({
|
|
114
|
+
output: JSON.stringify(output)
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return (routes);
|
|
119
|
+
}
|
|
120
|
+
async serviceMetadata() {
|
|
121
|
+
const operations = {};
|
|
122
|
+
if (this.assetMovement.createPersistentForwarding !== undefined) {
|
|
123
|
+
operations.createPersistentForwarding = (new URL('/api/createPersistentForwarding', this.url)).toString();
|
|
124
|
+
}
|
|
125
|
+
if (this.assetMovement.initiateTransfer !== undefined) {
|
|
126
|
+
operations.initiateTransfer = (new URL('/api/initiateTransfer', this.url)).toString();
|
|
127
|
+
}
|
|
128
|
+
if (this.assetMovement.getTransferStatus !== undefined) {
|
|
129
|
+
operations.getTransferStatus = (new URL('/api/getTransferStatus/{id}', this.url)).toString();
|
|
130
|
+
}
|
|
131
|
+
if (this.assetMovement.listTransactions !== undefined) {
|
|
132
|
+
operations.listTransactions = (new URL('/api/listTransactions', this.url)).toString();
|
|
133
|
+
}
|
|
134
|
+
if (Object.keys(operations).length === 0) {
|
|
135
|
+
throw (new KeetaAnchorUserError('No operations are supported on this server'));
|
|
136
|
+
}
|
|
137
|
+
return ({
|
|
138
|
+
operations: operations,
|
|
139
|
+
supportedAssets: this.assetMovement.supportedAssets
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/services/asset-movement/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,qBAAqB,MAAM,0BAA0B,CAAC;AAElE,OAAO,EACN,oBAAoB,EACpB,MAAM,oBAAoB,CAAC;AAW5B,OAAO,EACN,+DAA+D,EAC/D,gEAAgE,EAChE,qDAAqD,EACrD,sDAAsD,EACtD,sDAAsD,EACtD,uDAAuD,EACvD,qDAAqD,EACrD,0EAA0E,EAC1E,MAAM,aAAa,CAAC;AA2CpB,CAAC;AAEF,MAAM,OAAO,qCAAsC,SAAQ,qBAAqB,CAAC,wBAA8D;IACrI,QAAQ,CAAgE;IACxE,MAAM,CAAiD;IACvD,aAAa,CAAqE;IAE3F,YAAY,MAA4C;QACvD,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IA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AM,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.js';\nimport type KeetaNet from '@keetanetwork/keetanet-client';\nimport {\n\tKeetaAnchorUserError\n} from '../../lib/error.js';\nimport type {\n\tKeetaAssetMovementAnchorCreatePersistentForwardingRequest,\n\tKeetaAssetMovementAnchorCreatePersistentForwardingResponse,\n\tKeetaAssetMovementAnchorInitiateTransferRequest,\n\tKeetaAssetMovementAnchorInitiateTransferResponse,\n\tKeetaAssetMovementAnchorGetTransferStatusRequest,\n\tKeetaAssetMovementAnchorGetTransferStatusResponse,\n\tKeetaAssetMovementAnchorlistTransactionsRequest,\n\tKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse\n} from './common.ts';\nimport {\n\tassertKeetaAssetMovementAnchorCreatePersistentForwardingRequest,\n\tassertKeetaAssetMovementAnchorCreatePersistentForwardingResponse,\n\tassertKeetaAssetMovementAnchorInitiateTransferRequest,\n\tassertKeetaAssetMovementAnchorInitiateTransferResponse,\n\tassertKeetaAssetMovementAnchorGetTransferStatusRequest,\n\tassertKeetaAssetMovementAnchorGetTransferStatusResponse,\n\tassertKeetaAssetMovementAnchorlistTransactionsRequest,\n\tassertKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse\n} from './common.js';\nimport type { ServiceMetadata } from '../../lib/resolver.ts';\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 * The network client to use for submitting blocks\n\t */\n\tclient: { client: KeetaNet.Client; network: bigint; networkAlias: typeof KeetaNet.Client.Config.networksArray[number] } | KeetaNet.UserClient;\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\t/**\n\t\t * Method to create a persistent forwarding address\n\t\t */\n\t\tcreatePersistentForwarding?: (request: KeetaAssetMovementAnchorCreatePersistentForwardingRequest) => Promise<Omit<Extract<KeetaAssetMovementAnchorCreatePersistentForwardingResponse, { ok: true }>, 'ok'>>;\n\n\t\t/**\n\t\t * Method to initiate a transfer\n\t\t */\n\t\tinitiateTransfer?: (request: KeetaAssetMovementAnchorInitiateTransferRequest) => Promise<Omit<Extract<KeetaAssetMovementAnchorInitiateTransferResponse, { ok: true }>, 'ok'>>;\n\n\t\t/**\n\t\t * Method to get the status of a transfer\n\t\t */\n\t\tgetTransferStatus?: (id: string) => Promise<Omit<Extract<KeetaAssetMovementAnchorGetTransferStatusResponse, { ok: true }>, 'ok'>>;\n\n\t\t/**\n\t\t * Method to list transactions\n\t\t */\n\t\tlistTransactions?: (request: KeetaAssetMovementAnchorlistTransactionsRequest) => Promise<Omit<Extract<KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse, { ok: true }>, 'ok'>>;\n\t}\n};\n\nexport class KeetaNetAssetMovementAnchorHTTPServer extends KeetaAnchorHTTPServer.KeetaNetAnchorHTTPServer<KeetaAnchorAssetMovementServerConfig> implements Required<KeetaAnchorAssetMovementServerConfig> {\n\treadonly homepage: NonNullable<KeetaAnchorAssetMovementServerConfig['homepage']>;\n\treadonly client: KeetaAnchorAssetMovementServerConfig['client'];\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.client = config.client;\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\t/**\n\t\t * Setup the various operation endpoints\n\t\t */\n\t\tif (config.assetMovement.createPersistentForwarding !== undefined) {\n\t\t\troutes['POST /api/createPersistentForwarding'] = async function(_ignore_params, postData) {\n\t\t\t\tif (config.assetMovement.createPersistentForwarding === undefined) {\n\t\t\t\t\tthrow(new Error('internal error: createPersistentForwarding disappeared'));\n\t\t\t\t}\n\n\t\t\t\tconst request = assertKeetaAssetMovementAnchorCreatePersistentForwardingRequest(postData);\n\t\t\t\tconst result = await config.assetMovement.createPersistentForwarding(request);\n\t\t\t\tconst output: KeetaAssetMovementAnchorCreatePersistentForwardingResponse = {\n\t\t\t\t\t...result,\n\t\t\t\t\tok: true\n\t\t\t\t};\n\n\t\t\t\tassertKeetaAssetMovementAnchorCreatePersistentForwardingResponse(output);\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify(output)\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (config.assetMovement.initiateTransfer !== undefined) {\n\t\t\troutes['POST /api/initiateTransfer'] = async function(_ignore_params, postData) {\n\t\t\t\tif (config.assetMovement.initiateTransfer === undefined) {\n\t\t\t\t\tthrow(new Error('internal error: initiateTransfer disappeared'));\n\t\t\t\t}\n\n\t\t\t\tconst request = assertKeetaAssetMovementAnchorInitiateTransferRequest(postData);\n\t\t\t\tconst result = await config.assetMovement.initiateTransfer(request);\n\t\t\t\tconst output: KeetaAssetMovementAnchorInitiateTransferResponse = {\n\t\t\t\t\t...result,\n\t\t\t\t\tok: true\n\t\t\t\t};\n\n\t\t\t\tassertKeetaAssetMovementAnchorInitiateTransferResponse(output);\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify(output)\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (config.assetMovement.getTransferStatus !== undefined) {\n\t\t\troutes['GET /api/getTransferStatus/:id'] = async function(params) {\n\t\t\t\tif (config.assetMovement.getTransferStatus === undefined) {\n\t\t\t\t\tthrow(new Error('internal error: getTransferStatus disappeared'));\n\t\t\t\t}\n\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\t/*\n\t\t\t\t * Validate the request against the defined schema\n\t\t\t\t */\n\t\t\t\tconst request = assertKeetaAssetMovementAnchorGetTransferStatusRequest({\n\t\t\t\t\tid: id\n\t\t\t\t} satisfies KeetaAssetMovementAnchorGetTransferStatusRequest);\n\n\t\t\t\tconst result = await config.assetMovement.getTransferStatus(request.id);\n\t\t\t\tconst output: KeetaAssetMovementAnchorGetTransferStatusResponse = {\n\t\t\t\t\t...result,\n\t\t\t\t\tok: true\n\t\t\t\t};\n\n\t\t\t\tassertKeetaAssetMovementAnchorGetTransferStatusResponse(output);\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify(output)\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (config.assetMovement.listTransactions !== undefined) {\n\t\t\troutes['POST /api/listTransactions'] = async function(_ignore_params, postData) {\n\t\t\t\tif (config.assetMovement.listTransactions === undefined) {\n\t\t\t\t\tthrow(new Error('internal error: listTransactions disappeared'));\n\t\t\t\t}\n\n\t\t\t\tconst request = assertKeetaAssetMovementAnchorlistTransactionsRequest(postData);\n\t\t\t\tconst result = await config.assetMovement.listTransactions(request);\n\t\t\t\tconst output: KeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse = {\n\t\t\t\t\t...result,\n\t\t\t\t\tok: true\n\t\t\t\t};\n\n\t\t\t\tassertKeetaAssetMovementAnchorlistPersistentForwardingTransactionsResponse(output);\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify(output)\n\t\t\t\t});\n\t\t\t}\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\tif (this.assetMovement.createPersistentForwarding !== undefined) {\n\t\t\toperations.createPersistentForwarding = (new URL('/api/createPersistentForwarding', this.url)).toString();\n\t\t}\n\t\tif (this.assetMovement.initiateTransfer !== undefined) {\n\t\t\toperations.initiateTransfer = (new URL('/api/initiateTransfer', this.url)).toString();\n\t\t}\n\t\tif (this.assetMovement.getTransferStatus !== undefined) {\n\t\t\toperations.getTransferStatus = (new URL('/api/getTransferStatus/{id}', this.url)).toString();\n\t\t}\n\t\tif (this.assetMovement.listTransactions !== undefined) {\n\t\t\toperations.listTransactions = (new URL('/api/listTransactions', this.url)).toString();\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"]}
|