From 3dcdc311e583f8eafe571b28522eb20bd780ca5c Mon Sep 17 00:00:00 2001 From: ohager Date: Wed, 15 Mar 2023 18:19:23 -0300 Subject: [PATCH] added SIP48 implementation (#46) * feat: added SIP48 implementation * chore: added unit tests, removed code smells --- packages/core/CHANGELOG.md | 5 +- .../core/src/api/__tests__/aliasApi.spec.ts | 56 ++++++++++++++++++- packages/core/src/api/composeApi.ts | 14 ++++- .../api/factories/alias/buyTopLevelDomain.ts | 34 +++++++++++ .../src/api/factories/alias/getAliasById.ts | 2 +- .../src/api/factories/alias/getAliasByName.ts | 8 ++- .../api/factories/alias/getTopLevelDomains.ts | 16 ++++++ .../core/src/api/factories/alias/index.ts | 3 + .../factories/alias/searchAliasesByName.ts | 17 ++++++ .../constants/transactionArbitrarySubtype.ts | 1 + .../rebuildTransactionPostData.spec.ts | 16 ++++++ .../__tests__/verifyTransaction.spec.ts | 22 ++++++++ .../verifyTransaction/getAttachmentFields.ts | 3 + .../getRequestRebuildInfo.ts | 1 + .../verifyTransaction/verifyTransaction.ts | 2 +- packages/core/src/typings/alias.ts | 14 +++++ packages/core/src/typings/api/aliasApi.ts | 31 +++++++++- .../core/src/typings/args/buyAliasArgs.ts | 2 + .../src/typings/args/buyTopLevelDomainArgs.ts | 14 +++++ .../core/src/typings/args/getAliasesArgs.ts | 5 ++ .../typings/args/getTopLevelDomainsArgs.ts | 20 +++++++ packages/core/src/typings/args/index.ts | 3 + .../typings/args/searchAliasesByNameArgs.ts | 25 +++++++++ .../core/src/typings/args/sellAliasArgs.ts | 2 + .../core/src/typings/args/setAliasArgs.ts | 2 + packages/core/src/typings/attachment.ts | 8 ++- packages/core/src/typings/topLevelDomain.ts | 20 +++++++ .../core/src/typings/topLevelDomainList.ts | 15 +++++ 28 files changed, 349 insertions(+), 12 deletions(-) create mode 100644 packages/core/src/api/factories/alias/buyTopLevelDomain.ts create mode 100644 packages/core/src/api/factories/alias/getTopLevelDomains.ts create mode 100644 packages/core/src/api/factories/alias/searchAliasesByName.ts create mode 100644 packages/core/src/typings/args/buyTopLevelDomainArgs.ts create mode 100644 packages/core/src/typings/args/getTopLevelDomainsArgs.ts create mode 100644 packages/core/src/typings/args/searchAliasesByNameArgs.ts create mode 100644 packages/core/src/typings/topLevelDomain.ts create mode 100644 packages/core/src/typings/topLevelDomainList.ts diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index ed90efba..0a5c57fe 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -45,7 +45,10 @@ This version is a major breakthrough with a lots of significant and breaking cha - `transferAssetOwnership`, - `getTransactionByReferenceHash` - `calculateDistributionFee`, - - `getAssetsByOwner` + - `getAssetsByOwner`, + - `searchAliasesByName`, + - `getTopLevelDomains` + - `buyTopLevelDomain` - New Transaction Subtype Enums for Assets - `getAccountTransactions` can resolve asset distributions now! diff --git a/packages/core/src/api/__tests__/aliasApi.spec.ts b/packages/core/src/api/__tests__/aliasApi.spec.ts index b0fca422..cec2bd29 100644 --- a/packages/core/src/api/__tests__/aliasApi.spec.ts +++ b/packages/core/src/api/__tests__/aliasApi.spec.ts @@ -5,9 +5,11 @@ import { getAliasesOnSale, buyAlias, sellAlias, - getAliasByName + getAliasByName, buyTopLevelDomain, getTopLevelDomains } from '../factories'; import {mockSignAndBroadcastTransaction, createChainService} from '../../__tests__/helpers'; +import {searchAliasesByName} from '../factories/alias/searchAliasesByName'; +import {AttachmentMessage} from '../../typings/attachment'; describe('Alias Api', () => { @@ -159,4 +161,56 @@ describe('Alias Api', () => { expect(asset).toEqual({'transaction': 'transactionId'}); }); }); + + describe('searchAliasesByName', () => { + it('should search as expected', async () => { + httpMock = HttpMockBuilder.create().onGetReply(200, {'aliases': []}, + 'relPath?requestType=getAliasesByName&aliasName=aliasName×tamp=10000&firstIndex=0&lastIndex=150' + ).build(); + const service = createChainService(httpMock, 'relPath'); + const result = await searchAliasesByName(service)({ + aliasName: 'aliasName', + timestamp: 10000, + firstIndex: 0, + lastIndex: 150 + }); + expect(result.aliases).toHaveLength(0); + }); + }); + + describe('getTLDS', () => { + it('should get as expected', async () => { + httpMock = HttpMockBuilder.create().onGetReply(200, {'tlds': []}, + 'relPath?requestType=getTLDs×tamp=10000&firstIndex=0&lastIndex=150' + ).build(); + const service = createChainService(httpMock, 'relPath'); + const result = await getTopLevelDomains(service)({ + timestamp: 10000, + firstIndex: 0, + lastIndex: 150 + }); + expect(result.tlds).toHaveLength(0); + }); + }); + + describe('buyTopLevelDomain', () => { + it('should buy as expected', async () => { + httpMock = HttpMockBuilder.create().onPostReply(200, { + broadcasted: true, + unsignedTransactionBytes: 'unsignedHexMessage' + }, + 'relPath?requestType=setTLD&message=Some%20message&messageIsText=true&tld=tld&amountNQT=10000000000000&deadline=1440&feeNQT=100000&publicKey=senderPublicKey' + ).build(); + const service = createChainService(httpMock, 'relPath'); + const result = await buyTopLevelDomain(service)({ + feePlanck: '100000', + amountPlanck: '10000000000000', + tld: 'tld', + attachment: new AttachmentMessage({message: 'Some message', messageIsText: true}), + deadline: 1440, + senderPublicKey: 'senderPublicKey' + }); + expect(result.unsignedTransactionBytes).toBe('unsignedHexMessage'); + }); + }); }); diff --git a/packages/core/src/api/composeApi.ts b/packages/core/src/api/composeApi.ts index 78f42a25..c7fb9e2f 100644 --- a/packages/core/src/api/composeApi.ts +++ b/packages/core/src/api/composeApi.ts @@ -44,7 +44,16 @@ import { setRewardRecipient, getRewardRecipient, addCommitment, removeCommitment, } from './factories/account'; -import {getAliasById, getAliasByName, getAliasesOnSale, sellAlias, buyAlias} from './factories/alias'; +import { + getAliasById, + getAliasByName, + getAliasesOnSale, + sellAlias, + buyAlias, + searchAliasesByName, + getTopLevelDomains, + buyTopLevelDomain +} from './factories/alias'; import { callContractMethod, getAllContractIds, @@ -213,6 +222,9 @@ export function composeApi(settings: ApiSettings): Api { buyAlias, sellAlias, getAliases, + searchAliasesByName, + getTopLevelDomains, + buyTopLevelDomain }).withContractApi({ getContract, getContractsByAccount, diff --git a/packages/core/src/api/factories/alias/buyTopLevelDomain.ts b/packages/core/src/api/factories/alias/buyTopLevelDomain.ts new file mode 100644 index 00000000..61c34bdf --- /dev/null +++ b/packages/core/src/api/factories/alias/buyTopLevelDomain.ts @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2023 Signum Network + */ +import {ChainService} from '../../../service/chainService'; +import {UnsignedTransaction} from '../../../typings/unsignedTransaction'; +import {signIfPrivateKey} from '../../../internal/signIfPrivateKey'; +import {DefaultDeadline} from '../../../constants'; +import {BuyTopLevelDomainArgs} from '../../../typings/args'; +import {createParametersFromAttachment} from '../../../internal'; + +/** + * Use with [[ApiComposer]] and belongs to [[AliasApi]]. + * + * See details at [[AliasApi.buyTopLevelDomain]] + * + * @module core.api.factories + */ +export const buyTopLevelDomain = (service: ChainService) => + (args: BuyTopLevelDomainArgs) => + signIfPrivateKey(service, args, async (a: BuyTopLevelDomainArgs) => { + let parameters = { + tld: a.tld, + amountNQT: a.amountPlanck, + deadline: a.deadline || DefaultDeadline, + feeNQT: a.feePlanck, + publicKey: a.senderPublicKey, + referencedTransactionFullHash: a.referencedTransactionFullHash, + }; + + if (args.attachment) { + parameters = createParametersFromAttachment(a.attachment, parameters); + } + return service.send('setTLD', parameters); + }); diff --git a/packages/core/src/api/factories/alias/getAliasById.ts b/packages/core/src/api/factories/alias/getAliasById.ts index a9d7e6f9..14c76cfd 100644 --- a/packages/core/src/api/factories/alias/getAliasById.ts +++ b/packages/core/src/api/factories/alias/getAliasById.ts @@ -13,5 +13,5 @@ import {AliasList} from '../../../typings/aliasList'; export const getAliasById = (service: ChainService): (aliasId: string) => Promise => (aliasId: string): Promise => service.query('getAlias', { - alias:aliasId, + alias: aliasId, }); diff --git a/packages/core/src/api/factories/alias/getAliasByName.ts b/packages/core/src/api/factories/alias/getAliasByName.ts index 657c7a5d..844b18d1 100644 --- a/packages/core/src/api/factories/alias/getAliasByName.ts +++ b/packages/core/src/api/factories/alias/getAliasByName.ts @@ -1,5 +1,6 @@ /** * Copyright (c) 2019 Burst Apps Team + * Modified (c) 2023 Signum Network */ import {ChainService} from '../../../service/chainService'; import {AliasList} from '../../../typings/aliasList'; @@ -11,7 +12,8 @@ import {AliasList} from '../../../typings/aliasList'; * @module core.api.factories */ export const getAliasByName = (service: ChainService): - (aliasName: string) => Promise => - (aliasName: string): Promise => service.query('getAlias', { - aliasName + (aliasName: string, tld?: string) => Promise => + (aliasName: string, tld?: string): Promise => service.query('getAlias', { + aliasName, + tld }); diff --git a/packages/core/src/api/factories/alias/getTopLevelDomains.ts b/packages/core/src/api/factories/alias/getTopLevelDomains.ts new file mode 100644 index 00000000..e705cdc6 --- /dev/null +++ b/packages/core/src/api/factories/alias/getTopLevelDomains.ts @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2023 Signum Network + */ +import {ChainService} from '../../../service/chainService'; +import {GetTopLevelDomainsArgs} from '../../../typings/args/getTopLevelDomainsArgs'; +import {TopLevelDomainList} from '../../../typings/topLevelDomainList'; + +/** + * Use with [[ApiComposer]] and belongs to [[AliasApi]]. + * + * See details at [[AliasApi.getTopLevelDomains]] + * @module core.api.factories + */ +export const getTopLevelDomains = (service: ChainService): + (args: GetTopLevelDomainsArgs) => Promise => + (args: GetTopLevelDomainsArgs): Promise => service.query('getTLDs', args); diff --git a/packages/core/src/api/factories/alias/index.ts b/packages/core/src/api/factories/alias/index.ts index 8d75e5d7..4b2589e9 100644 --- a/packages/core/src/api/factories/alias/index.ts +++ b/packages/core/src/api/factories/alias/index.ts @@ -3,3 +3,6 @@ export * from './getAliasByName'; export * from './getAliasesOnSale'; export * from './buyAlias'; export * from './sellAlias'; +export * from './getTopLevelDomains'; +export * from './buyTopLevelDomain'; +export * from './searchAliasesByName'; diff --git a/packages/core/src/api/factories/alias/searchAliasesByName.ts b/packages/core/src/api/factories/alias/searchAliasesByName.ts new file mode 100644 index 00000000..be940a14 --- /dev/null +++ b/packages/core/src/api/factories/alias/searchAliasesByName.ts @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2019 Burst Apps Team + * Modified (c) 2023 Signum Network + */ +import {ChainService} from '../../../service/chainService'; +import {AliasList} from '../../../typings/aliasList'; +import { SearchAliasesByNameArgs } from '../../../typings/args/searchAliasesByNameArgs'; + +/** + * Use with [[ApiComposer]] and belongs to [[AliasApi]]. + * + * See details at [[AliasApi.searchAliasesByName]] + * @module core.api.factories + */ +export const searchAliasesByName = (service: ChainService): + (args: SearchAliasesByNameArgs) => Promise => + (args): Promise => service.query('getAliasesByName', args); diff --git a/packages/core/src/constants/transactionArbitrarySubtype.ts b/packages/core/src/constants/transactionArbitrarySubtype.ts index aa17cb53..263abbd8 100644 --- a/packages/core/src/constants/transactionArbitrarySubtype.ts +++ b/packages/core/src/constants/transactionArbitrarySubtype.ts @@ -15,5 +15,6 @@ export enum TransactionArbitrarySubtype { AccountInfo, AliasSale, AliasBuy, + TopLevelDomainAssignment } diff --git a/packages/core/src/internal/verifyTransaction/__tests__/rebuildTransactionPostData.spec.ts b/packages/core/src/internal/verifyTransaction/__tests__/rebuildTransactionPostData.spec.ts index 8fb7c3bd..e7cf98a1 100644 --- a/packages/core/src/internal/verifyTransaction/__tests__/rebuildTransactionPostData.spec.ts +++ b/packages/core/src/internal/verifyTransaction/__tests__/rebuildTransactionPostData.spec.ts @@ -198,6 +198,22 @@ describe('rebuildTransactionPostData', () => { }); }); }); + describe('setTLD', () => { + const requestType = 'setTLD'; + it('should rebuild data correctly', () => { + const transactionBytes = '01289da31c10140004d794aa453a5bbdb8d580f1d9a76b6d7a25cde0ed38c098550ea0f784d9317a000000000000000000a0724e18090000002d3101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000055f4070086134aea12e0d25404cfe1531b543c7c010c313233737061636573686970'; + const rebuiltData = { + tld: '123spaceship', + amountNQT: '10000000000000', + feeNQT: '20000000', + publicKey: '04d794aa453a5bbdb8d580f1d9a76b6d7a25cde0ed38c098550ea0f784d9317a', + deadline: 20 + }; + const output = rebuildTransactionPostData(transactionBytes); + expect(output.requestType).toEqual(requestType); + expect(output.rebuiltData).toEqual(rebuiltData); + }); + }); describe('setAccountInfo', () => { const requestType = 'setAccountInfo'; it('should rebuild data correctly - Plus very long and utf-8 data', () => { diff --git a/packages/core/src/internal/verifyTransaction/__tests__/verifyTransaction.spec.ts b/packages/core/src/internal/verifyTransaction/__tests__/verifyTransaction.spec.ts index 6f11f081..fbc5549c 100644 --- a/packages/core/src/internal/verifyTransaction/__tests__/verifyTransaction.spec.ts +++ b/packages/core/src/internal/verifyTransaction/__tests__/verifyTransaction.spec.ts @@ -282,4 +282,26 @@ describe('verifyTransaction', function () { }).not.toThrow(); }); }); + describe('setTLD', function () { + it('should pass verification as expected', () => { + const requestType = 'setTLD'; + const formData = { + tld: '123spaceship', + amountNQT: '10000000000000', + feeNQT: '20000000', + publicKey: '04d794aa453a5bbdb8d580f1d9a76b6d7a25cde0ed38c098550ea0f784d9317a', + deadline: 20 + }; + + const testResponse = { + 'broadcasted': false, + 'unsignedTransactionBytes': '01289da31c10140004d794aa453a5bbdb8d580f1d9a76b6d7a25cde0ed38c098550ea0f784d9317a000000000000000000a0724e18090000002d3101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000055f4070086134aea12e0d25404cfe1531b543c7c010c313233737061636573686970', + 'transactionJSON': {}, + 'requestProcessingTime': 8 + }; + expect(() => { + verifyTransaction(requestType, formData, testResponse); + }).not.toThrow(); + }); + }); }); diff --git a/packages/core/src/internal/verifyTransaction/getAttachmentFields.ts b/packages/core/src/internal/verifyTransaction/getAttachmentFields.ts index 18abf1e3..08986653 100644 --- a/packages/core/src/internal/verifyTransaction/getAttachmentFields.ts +++ b/packages/core/src/internal/verifyTransaction/getAttachmentFields.ts @@ -91,6 +91,9 @@ const AttachmentSpecV1: AttachmentSpec = new Map([ {type: 'ShortString*1', parameterName: 'description'}, {type: 'CreationBytes*1'}, ]], + ['setTLD', [ + {type: 'ByteString*1', parameterName: 'tld'}, + ]], ]); const AttachmentSpecV2: AttachmentSpec = new Map([ diff --git a/packages/core/src/internal/verifyTransaction/getRequestRebuildInfo.ts b/packages/core/src/internal/verifyTransaction/getRequestRebuildInfo.ts index 4289c68b..a1da37b8 100644 --- a/packages/core/src/internal/verifyTransaction/getRequestRebuildInfo.ts +++ b/packages/core/src/internal/verifyTransaction/getRequestRebuildInfo.ts @@ -13,6 +13,7 @@ const DecodeRequestType = [ {type: 1, subtype: 5, requestType: 'setAccountInfo', hasAttachment: true}, {type: 1, subtype: 6, requestType: 'sellAlias', hasAttachment: true}, {type: 1, subtype: 7, requestType: 'buyAlias', hasAttachment: true}, + {type: 1, subtype: 8, requestType: 'setTLD', hasAttachment: true}, {type: 2, subtype: 0, requestType: 'issueAsset', hasAttachment: true}, {type: 2, subtype: 1, requestType: 'transferAsset', hasAttachment: true}, {type: 2, subtype: 2, requestType: 'placeAskOrder', hasAttachment: true}, diff --git a/packages/core/src/internal/verifyTransaction/verifyTransaction.ts b/packages/core/src/internal/verifyTransaction/verifyTransaction.ts index 96bd88ad..910a17a9 100644 --- a/packages/core/src/internal/verifyTransaction/verifyTransaction.ts +++ b/packages/core/src/internal/verifyTransaction/verifyTransaction.ts @@ -13,7 +13,7 @@ import {rebuildTransactionPostData} from './rebuildTransactionPostData'; // Type 22 (automated transactions): OK const methodsToVerify = new Set([ 'sendMoney', 'sendMoneyMulti', 'sendMoneyMultiSame', - 'sendMessage', 'setAlias', 'setAccountInfo', + 'sendMessage', 'setAlias', 'setTLD', 'setAccountInfo', 'issueAsset', 'transferAsset', 'transferAssetOwnership', 'placeAskOrder', 'placeBidOrder', 'cancelAskOrder', 'mintAsset', 'addAssetTreasuryAccount', 'distributeToAssetHolders', 'cancelBidOrder', 'transferAssetMulti', 'setRewardRecipient', 'addCommitment', 'removeCommitment', diff --git a/packages/core/src/typings/alias.ts b/packages/core/src/typings/alias.ts index 169c21ea..1d6a4f86 100644 --- a/packages/core/src/typings/alias.ts +++ b/packages/core/src/typings/alias.ts @@ -32,4 +32,18 @@ export interface Alias { */ aliasURI: string; timestamp: number; + + /** + * The id of the Top Level Domain (tld) aka namespace for this alias. Default is '0', which points to 'signum' + */ + tld?: string; + /** + * The name of the Top Level Domain (tld) aka namespace for this alias. Default is 'signum' + */ + tldName?: string; + + /** + * Numbers of aliases within the namespace/ top level domain. + */ + numberOfAlias?: number; } diff --git a/packages/core/src/typings/api/aliasApi.ts b/packages/core/src/typings/api/aliasApi.ts index ef816135..3e5b361c 100644 --- a/packages/core/src/typings/api/aliasApi.ts +++ b/packages/core/src/typings/api/aliasApi.ts @@ -1,9 +1,17 @@ import {TransactionId} from '../transactionId'; import {Alias} from '../alias'; import {UnsignedTransaction} from '../unsignedTransaction'; -import {SetAliasArgs} from '../args/setAliasArgs'; import {AliasList} from '../aliasList'; -import {BuyAliasArgs, GetAliasesOnSaleArgs, SellAliasArgs} from '../args'; +import { + BuyAliasArgs, + BuyTopLevelDomainArgs, + GetAliasesOnSaleArgs, + SellAliasArgs, + SetAliasArgs, + GetTopLevelDomainsArgs, + SearchAliasesByNameArgs +} from '../args'; +import {TopLevelDomainList} from '../topLevelDomainList'; /** * Alias API @@ -27,10 +35,12 @@ export interface AliasApi { /** * Get alias by name, i.e. get basic account info for given alias name * @param {string} aliasName The alias name + * @param {string} tld optional Top Level Domain. If not given, the default domain 'signum' is being used * @return {Promise} The Alias object */ getAliasByName: ( aliasName: string, + tld?: string, ) => Promise; /** @@ -64,4 +74,21 @@ export interface AliasApi { * @return The Transaction Id or Unsigned Bytes as Hex String if no private key was sent */ sellAlias: (args: SellAliasArgs) => Promise; + + /** + * Searches for aliases by their name or part of the name + * @param args The args + */ + searchAliasesByName: (args: SearchAliasesByNameArgs) => Promise; + /** + * Gets all registered Top Level Domains + * @param args The args + */ + getTopLevelDomains: (args: GetTopLevelDomainsArgs) => Promise; + + /** + * Buys a Top Level Domain (TLD) + * @param args The args + */ + buyTopLevelDomain: (args: BuyTopLevelDomainArgs) => Promise; } diff --git a/packages/core/src/typings/args/buyAliasArgs.ts b/packages/core/src/typings/args/buyAliasArgs.ts index 60bbc811..3aa28486 100644 --- a/packages/core/src/typings/args/buyAliasArgs.ts +++ b/packages/core/src/typings/args/buyAliasArgs.ts @@ -7,10 +7,12 @@ import {DefaultSendArgs} from './defaultSendArgs'; * @param alias The alias Id * @param aliasName Alternative to alias Id * @param amountPlanck The amount for buy in Planck + * @param tld The name of the Top Level Domain (TLD) aka namespace where this alias belongs to * @module core */ export interface BuyAliasArgs extends DefaultSendArgs { aliasId: string; aliasName?: string; amountPlanck: string; + tld?: string; } diff --git a/packages/core/src/typings/args/buyTopLevelDomainArgs.ts b/packages/core/src/typings/args/buyTopLevelDomainArgs.ts new file mode 100644 index 00000000..f96b3717 --- /dev/null +++ b/packages/core/src/typings/args/buyTopLevelDomainArgs.ts @@ -0,0 +1,14 @@ +import {DefaultSendArgs} from './defaultSendArgs'; + + +/** + * The argument object for [[AccountApi.setTopLevelDomain]] + * + * @param tld The name of the Top Level Domain (max. 40 chars only digits and letters) + * @param amountPlanck The amount in planck according SIP-48 + * @module core + */ +export interface BuyTopLevelDomainArgs extends DefaultSendArgs { + tld: string; + amountPlanck: string; +} diff --git a/packages/core/src/typings/args/getAliasesArgs.ts b/packages/core/src/typings/args/getAliasesArgs.ts index 60808821..ddb8c403 100644 --- a/packages/core/src/typings/args/getAliasesArgs.ts +++ b/packages/core/src/typings/args/getAliasesArgs.ts @@ -22,4 +22,9 @@ export interface GetAliasesArgs { * The last index of the list. At maximum 500 will be returned */ lastIndex?: number; + + /** + * The Top Level Domain. If it is given without further parameters all aliases of this tld are being returned. + */ + tld?: string; } diff --git a/packages/core/src/typings/args/getTopLevelDomainsArgs.ts b/packages/core/src/typings/args/getTopLevelDomainsArgs.ts new file mode 100644 index 00000000..7a9ac176 --- /dev/null +++ b/packages/core/src/typings/args/getTopLevelDomainsArgs.ts @@ -0,0 +1,20 @@ +/** + * The argument object for [[AliasApi.getTopLevelDomains]] + * + * @module core + */ +export interface GetTopLevelDomainsArgs { + /** + * The first index to be returned. Use this for pagination. Starts at 0 + */ + firstIndex?: number; + /** + * The last index to be returned. Use this for pagination. If not set, at maximum 500 items beginning at firstIndex will be returned + */ + lastIndex?: number; + /** + * The timestamp in seconds since genesis block + * @see [[util.ChainTime]] + */ + timestamp?: number; +} diff --git a/packages/core/src/typings/args/index.ts b/packages/core/src/typings/args/index.ts index eaa612c1..3661efac 100644 --- a/packages/core/src/typings/args/index.ts +++ b/packages/core/src/typings/args/index.ts @@ -45,3 +45,6 @@ export * from './transferMultipleAssetsArgs'; export * from './getAliasesOnSaleArgs'; export * from './transferAssetOwnershipArgs'; export * from './calculateDistributionFeeArgs'; +export * from './getTopLevelDomainsArgs'; +export * from './searchAliasesByNameArgs'; +export * from './buyTopLevelDomainArgs'; diff --git a/packages/core/src/typings/args/searchAliasesByNameArgs.ts b/packages/core/src/typings/args/searchAliasesByNameArgs.ts new file mode 100644 index 00000000..31aea5ad --- /dev/null +++ b/packages/core/src/typings/args/searchAliasesByNameArgs.ts @@ -0,0 +1,25 @@ +/** + * The argument object for [[AliasApi.searchAliasesByName]] + * + * @module core + */ +export interface SearchAliasesByNameArgs { + /** + * The name or part of the name to search for. + */ + aliasName: string; + /** + * The first index to be returned. Use this for pagination. Starts at 0 + */ + firstIndex?: number; + /** + * The last index to be returned. Use this for pagination. If not set, at maximum 500 items beginning at firstIndex will be returned + */ + lastIndex?: number; + + /** + * The timestamp in seconds since genesis block. + * @see [[util.ChainTime]] + */ + timestamp?: number; +} diff --git a/packages/core/src/typings/args/sellAliasArgs.ts b/packages/core/src/typings/args/sellAliasArgs.ts index ce4ae8d1..951fa1c9 100644 --- a/packages/core/src/typings/args/sellAliasArgs.ts +++ b/packages/core/src/typings/args/sellAliasArgs.ts @@ -9,6 +9,7 @@ import {DefaultSendArgs} from './defaultSendArgs'; * @param amountPlanck The sale amount in Planck * @param recipientId The optional recipient Id. If given, then only that recipient can buy the alias. * @param recipientPublicKey The optional recipient public key. + * @param tld The name of the Top Level Domain (TLD) aka namespace where this alias belongs to * @module core */ export interface SellAliasArgs extends DefaultSendArgs { @@ -17,4 +18,5 @@ export interface SellAliasArgs extends DefaultSendArgs { amountPlanck: string; recipientId?: string; recipientPublicKey?: string; + tld?: string; } diff --git a/packages/core/src/typings/args/setAliasArgs.ts b/packages/core/src/typings/args/setAliasArgs.ts index 30bf0050..c14a3d15 100644 --- a/packages/core/src/typings/args/setAliasArgs.ts +++ b/packages/core/src/typings/args/setAliasArgs.ts @@ -6,9 +6,11 @@ import {DefaultSendArgs} from './defaultSendArgs'; * * @param aliasName The alias name * @param aliasUri The alias uri + * @param tld The name of the Top Level Domain (TLD) aka namespace where this alias belongs to * @module core */ export interface SetAliasArgs extends DefaultSendArgs { aliasName: string; aliasURI?: string; + tld?: string; } diff --git a/packages/core/src/typings/attachment.ts b/packages/core/src/typings/attachment.ts index 572375ff..8719d816 100644 --- a/packages/core/src/typings/attachment.ts +++ b/packages/core/src/typings/attachment.ts @@ -15,6 +15,11 @@ export class Attachment { constructor(public type: string) {} } +interface AttachmentMessageArgs { + messageIsText?: boolean; + message?: string; +} + /** * Message class * @@ -25,8 +30,7 @@ export class AttachmentMessage extends Attachment { public messageIsText: boolean; public message: string; - // TODO: make constructor attrs as single args to be more expressive - constructor(data: any = {}) { + constructor(data: AttachmentMessageArgs = {}) { super('message'); this.messageIsText = data.messageIsText || false; this.message = data.message || undefined; diff --git a/packages/core/src/typings/topLevelDomain.ts b/packages/core/src/typings/topLevelDomain.ts new file mode 100644 index 00000000..1be10083 --- /dev/null +++ b/packages/core/src/typings/topLevelDomain.ts @@ -0,0 +1,20 @@ +/** + * Original work Copyright (c) 2023 Signum Network + */ + +/** + * Top Level Domain + * + * Top Level Domains are part of the Alias system. There are serving as namespaces for aliases + * Look also at [SIP48](https://github.com/signum-network/SIPs/blob/master/SIP/sip-48.md) + * + * @module core + */ +export interface TopLevelDomain { + account: string; + accountRS: string; + alias: string; + aliasName: string; + timestamp: number; + numberOfAliases: number; +} diff --git a/packages/core/src/typings/topLevelDomainList.ts b/packages/core/src/typings/topLevelDomainList.ts new file mode 100644 index 00000000..713dc945 --- /dev/null +++ b/packages/core/src/typings/topLevelDomainList.ts @@ -0,0 +1,15 @@ +/** + * Original work Copyright (c) 2023 Signum Network + */ + +import {TopLevelDomain} from './topLevelDomain'; + +/** + * Top Level Domain List + * + * @module core + */ +export interface TopLevelDomainList { + tlds: TopLevelDomain[]; + requestProcessingTime: number; +}