OSDN Git Service

10e2256cfd0977507a360bbc9037eba509fcc8cf
[bytom/bytom-node-sdk.git] / src / api / assets.js
1 /**
2  * An asset is a type of value that can be issued on a blockchain. All units of
3  * a given asset are fungible. Units of an asset can be transacted directly
4  * between parties without the involvement of the issuer.
5  *
6  * @typedef {Object} Asset
7  * @global
8  *
9  * @property {String} id
10  * Globally unique identifier of the asset.
11  * Asset specifies the asset id as the hash of:
12  * - the asset's issuance program
13  * - the core's VM version
14  * - the hash of asset definition
15  *
16  * @property {String} alias
17  * User specified, unique identifier in one Bytom node.
18  *
19  * @property {String} issuanceProgram
20  *
21  * @property {Key[]} keys
22  * The list of keys used to issue units of the asset.
23  *
24  * @property {Number} quorum
25  * The number of signatures required to issue new units of the asset.
26  *
27  * @property {Object} defintion
28  * User-specified, arbitrary/unstructured data visible across Bytom
29  * blockchain networks. assets specify the definition in their
30  * issuance programs, rendering the definition immutable.
31  */
32
33 /**
34  * API for interacting with {@link Asset assets}.
35  *
36  * @module AssetsApi
37  */
38 const assetsApi = (connection) => {
39   /**
40    * @typedef {String[]} xpubs
41    * The list of keys used to issue units of the asset.
42    */
43
44   /**
45    * @typedef {String} [alias]
46    * User specified, unique identifier.
47    */
48
49   /**
50    * @typedef {Number} quorum
51    * The number of signatures required to issue new units of the asset.
52    */
53
54   /**
55    * @typedef {String} id
56    * Unique account identifier in one Bytom node.
57    */
58
59   /**
60    * @typedef {Object} definition
61    * User-specified, asset attributes accross Bytom blockchain network.
62    */
63
64   return {
65     /**
66      * Create a new asset.
67      *
68      * @param {module:AssetsApi~xpubs} xpubs - Keys for asseet creation.
69      * @param {module:AssetsApi~quorum} quorum - The number of keys required to sign transactions for the account.
70      * @param {module:AssetsApi~alias} alias - Asset alias.
71      * @param {module:AssetsApi~definition} definition - Asset definition.
72      * @returns {Promise<Response>} Newly created asset response.
73      */
74     create: (xpubs, quorum, alias, definition) => connection.request('/create-asset', {
75       alias,
76       quorum,
77       definition,
78       root_xpubs: xpubs
79     }),
80
81     /**
82      * List all assets in one Bytom node.
83      *
84      * @returns {Promise<Response>} target assets response.
85      */
86     listAssets: () => connection.request('/list-assets', {}),
87
88     /**
89      * Get asset by the asset id.
90      *
91      * @param {module:AssetsApi~id} id - Asset id.
92      * @returns {Promise<Response>} target asset response.
93      */
94     getAsset: (id) => connection.request('/get-asset', {id}),
95
96     /**
97      * Update asset alias.
98      *
99      * @param {module:AssetsApi~id} id - Asset id.
100      * @param {String} newAlias - new alias.
101      * @returns {Promise<Response>} update response.
102      */
103     updateAssetAlias: (id, newAlias) => connection.request('/update-asset-alias', {id, alias: newAlias})
104   }
105 }
106
107 export default assetsApi