ecash-lib 3.2.0 → 4.0.1
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/README.md +1 -0
- package/dist/consts.d.ts +22 -0
- package/dist/consts.d.ts.map +1 -1
- package/dist/consts.js +23 -1
- package/dist/consts.js.map +1 -1
- package/dist/ffi/ecash_lib_wasm_bg_browser.js +2597 -1753
- package/dist/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/dist/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +5 -1
- package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
- package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +5 -1
- package/dist/ffi/ecash_lib_wasm_browser.d.ts +22 -1
- package/dist/ffi/ecash_lib_wasm_browser.js +115 -0
- package/dist/ffi/ecash_lib_wasm_nodejs.d.ts +17 -0
- package/dist/ffi/ecash_lib_wasm_nodejs.js +116 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/initBrowser.js +7 -2
- package/dist/initBrowser.js.map +1 -1
- package/dist/initNodeJs.js +6 -1
- package/dist/initNodeJs.js.map +1 -1
- package/dist/payment/action.d.ts +107 -0
- package/dist/payment/action.d.ts.map +1 -0
- package/dist/payment/action.js +13 -0
- package/dist/payment/action.js.map +1 -0
- package/dist/payment/index.d.ts +2 -0
- package/dist/payment/index.d.ts.map +1 -1
- package/dist/payment/index.js +7 -0
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/output.d.ts +31 -0
- package/dist/payment/output.d.ts.map +1 -0
- package/dist/payment/output.js +6 -0
- package/dist/payment/output.js.map +1 -0
- package/dist/payment/x509.d.ts +6 -0
- package/dist/payment/x509.d.ts.map +1 -1
- package/dist/payment/x509.js +7 -1
- package/dist/payment/x509.js.map +1 -1
- package/dist/publicKeyCrypto.d.ts +25 -0
- package/dist/publicKeyCrypto.d.ts.map +1 -0
- package/dist/publicKeyCrypto.js +48 -0
- package/dist/publicKeyCrypto.js.map +1 -0
- package/dist/token/alp.d.ts +23 -1
- package/dist/token/alp.d.ts.map +1 -1
- package/dist/token/alp.js +20 -1
- package/dist/token/alp.js.map +1 -1
- package/dist/token/alp.parse.d.ts +5 -5
- package/dist/token/alp.parse.d.ts.map +1 -1
- package/dist/token/alp.parse.js.map +1 -1
- package/dist/token/common.d.ts +13 -0
- package/dist/token/common.d.ts.map +1 -1
- package/dist/token/common.js.map +1 -1
- package/dist/token/slp.d.ts +9 -1
- package/dist/token/slp.d.ts.map +1 -1
- package/dist/token/slp.js +6 -1
- package/dist/token/slp.js.map +1 -1
- package/dist/token/slp.parse.d.ts +4 -4
- package/dist/token/slp.parse.d.ts.map +1 -1
- package/dist/token/slp.parse.js.map +1 -1
- package/package.json +2 -2
- package/src/consts.ts +24 -0
- package/src/ffi/ecash_lib_wasm_bg_browser.js +2597 -1753
- package/src/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/src/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +5 -1
- package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
- package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +5 -1
- package/src/ffi/ecash_lib_wasm_browser.d.ts +22 -1
- package/src/ffi/ecash_lib_wasm_browser.js +115 -0
- package/src/ffi/ecash_lib_wasm_nodejs.d.ts +17 -0
- package/src/ffi/ecash_lib_wasm_nodejs.js +116 -1
- package/src/index.ts +0 -1
- package/src/initBrowser.ts +7 -3
- package/src/initNodeJs.ts +6 -1
- package/src/payment/action.ts +123 -0
- package/src/payment/index.ts +5 -0
- package/src/payment/output.ts +37 -0
- package/src/payment/x509.ts +6 -0
- package/src/publicKeyCrypto.ts +62 -0
- package/src/token/alp.parse.ts +9 -9
- package/src/token/alp.ts +32 -1
- package/src/token/common.ts +15 -0
- package/src/token/slp.parse.ts +11 -8
- package/src/token/slp.ts +21 -1
package/src/token/alp.parse.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ALP_LOKAD_ID,
|
|
10
10
|
ALP_MAX_SIZE,
|
|
11
11
|
ALP_STANDARD,
|
|
12
|
-
|
|
12
|
+
AlpTokenType_Number,
|
|
13
13
|
MintData,
|
|
14
14
|
} from './alp.js';
|
|
15
15
|
import {
|
|
@@ -30,7 +30,7 @@ export interface AlpGenesis {
|
|
|
30
30
|
/** "GENESIS" */
|
|
31
31
|
txType: typeof GENESIS_STR;
|
|
32
32
|
/** Token type of the token to create */
|
|
33
|
-
tokenType:
|
|
33
|
+
tokenType: AlpTokenType_Number;
|
|
34
34
|
/** Info about the token */
|
|
35
35
|
genesisInfo: GenesisInfo;
|
|
36
36
|
/** Which tokens/mint baton to create initially */
|
|
@@ -42,7 +42,7 @@ export interface AlpMint {
|
|
|
42
42
|
/** "MINT" */
|
|
43
43
|
txType: typeof MINT_STR;
|
|
44
44
|
/** Token type of the token to mint */
|
|
45
|
-
tokenType:
|
|
45
|
+
tokenType: AlpTokenType_Number;
|
|
46
46
|
/** Token ID of the token to mint */
|
|
47
47
|
tokenId: string;
|
|
48
48
|
/** Which tokens/mint baton to create */
|
|
@@ -54,7 +54,7 @@ export interface AlpSend {
|
|
|
54
54
|
/** "SEND" */
|
|
55
55
|
txType: typeof SEND_STR;
|
|
56
56
|
/** Token type of the token to send */
|
|
57
|
-
tokenType:
|
|
57
|
+
tokenType: AlpTokenType_Number;
|
|
58
58
|
/** Token ID of the token to send */
|
|
59
59
|
tokenId: string;
|
|
60
60
|
/** Array of the number of token atoms to send to the outputs at 1 to N */
|
|
@@ -68,7 +68,7 @@ export interface AlpBurn {
|
|
|
68
68
|
/** Token type of the token to burn */
|
|
69
69
|
tokenId: string;
|
|
70
70
|
/** Token ID of the token to burn */
|
|
71
|
-
tokenType:
|
|
71
|
+
tokenType: AlpTokenType_Number;
|
|
72
72
|
/** How many tokens should be burned */
|
|
73
73
|
burnAtoms: bigint;
|
|
74
74
|
}
|
|
@@ -138,7 +138,7 @@ export function parseAlp(pushdata: Uint8Array): AlpData | undefined {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
function readGenesis(bytes: Bytes, tokenType:
|
|
141
|
+
function readGenesis(bytes: Bytes, tokenType: AlpTokenType_Number): AlpGenesis {
|
|
142
142
|
const tokenTicker = bytesToStr(readVarBytes(bytes, 'tokenTicker'));
|
|
143
143
|
const tokenName = bytesToStr(readVarBytes(bytes, 'tokenName'));
|
|
144
144
|
const url = bytesToStr(readVarBytes(bytes, 'url'));
|
|
@@ -162,7 +162,7 @@ function readGenesis(bytes: Bytes, tokenType: AlpTokenType): AlpGenesis {
|
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
function readMint(bytes: Bytes, tokenType:
|
|
165
|
+
function readMint(bytes: Bytes, tokenType: AlpTokenType_Number): AlpMint {
|
|
166
166
|
const tokenId = readTokenId(bytes);
|
|
167
167
|
const mintData = readMintData(bytes);
|
|
168
168
|
ensureEnd(bytes, 'MINT');
|
|
@@ -174,7 +174,7 @@ function readMint(bytes: Bytes, tokenType: AlpTokenType): AlpMint {
|
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
function readSend(bytes: Bytes, tokenType:
|
|
177
|
+
function readSend(bytes: Bytes, tokenType: AlpTokenType_Number): AlpSend {
|
|
178
178
|
const tokenId = readTokenId(bytes);
|
|
179
179
|
const sendAtomsArray = readAtomsArray(bytes, 'sendAtomsArray');
|
|
180
180
|
ensureEnd(bytes, 'SEND');
|
|
@@ -186,7 +186,7 @@ function readSend(bytes: Bytes, tokenType: AlpTokenType): AlpSend {
|
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
function readBurn(bytes: Bytes, tokenType:
|
|
189
|
+
function readBurn(bytes: Bytes, tokenType: AlpTokenType_Number): AlpBurn {
|
|
190
190
|
const tokenId = readTokenId(bytes);
|
|
191
191
|
const burnAtoms = readU48(bytes, 'burnAtoms');
|
|
192
192
|
ensureEnd(bytes, 'BURN');
|
package/src/token/alp.ts
CHANGED
|
@@ -18,12 +18,43 @@ export const ALP_LOKAD_ID = strToBytes(ALP_LOKAD_ID_STR);
|
|
|
18
18
|
/** ALP standard token type number */
|
|
19
19
|
export const ALP_STANDARD = 0;
|
|
20
20
|
|
|
21
|
+
export type AlpTokenType_Number = typeof ALP_STANDARD;
|
|
22
|
+
|
|
21
23
|
/** Supported ALP token types */
|
|
22
|
-
export
|
|
24
|
+
export interface AlpTokenType {
|
|
25
|
+
protocol: 'ALP';
|
|
26
|
+
type: AlpTokenType_Type;
|
|
27
|
+
number: number;
|
|
28
|
+
}
|
|
29
|
+
/** Possible ALP token types returned by chronik */
|
|
30
|
+
export type AlpTokenType_Type =
|
|
31
|
+
| 'ALP_TOKEN_TYPE_STANDARD'
|
|
32
|
+
| 'ALP_TOKEN_TYPE_UNKNOWN';
|
|
23
33
|
|
|
24
34
|
/** ALP limits lengths/sizes to this number, e.g. the number of outputs */
|
|
25
35
|
export const ALP_MAX_SIZE = 127;
|
|
26
36
|
|
|
37
|
+
export const ALP_TOKEN_TYPE_STANDARD: AlpTokenType = {
|
|
38
|
+
protocol: 'ALP',
|
|
39
|
+
type: 'ALP_TOKEN_TYPE_STANDARD',
|
|
40
|
+
number: ALP_STANDARD,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Although ALP_MAX_SIZE is 127, in practice we can only
|
|
45
|
+
* handle 29 ALP outputs in a single OP_RETURN given the curent
|
|
46
|
+
* 223-byte OP_RETURN size limit, and even this assumes
|
|
47
|
+
* we are only working with 1 ALP token.
|
|
48
|
+
*
|
|
49
|
+
* For example an ALP tx that sends multiple tokens cannot support
|
|
50
|
+
* 29 token outputs as the instructions will require more than 223
|
|
51
|
+
* bytes in the OP_RETURN.
|
|
52
|
+
*
|
|
53
|
+
* So, this is an upper bound on ALP outputs per current mempool
|
|
54
|
+
* acceptance rules
|
|
55
|
+
*/
|
|
56
|
+
export const ALP_POLICY_MAX_OUTPUTS = 29;
|
|
57
|
+
|
|
27
58
|
/** Mint data specifying mint amounts (in atoms) and batons of a GENESIS/MINT tx */
|
|
28
59
|
export interface MintData {
|
|
29
60
|
/**
|
package/src/token/common.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
4
4
|
|
|
5
5
|
import { strToBytes } from '../io/str.js';
|
|
6
|
+
import { AlpTokenType } from './alp.js';
|
|
7
|
+
import { SlpTokenType } from './slp.js';
|
|
6
8
|
|
|
7
9
|
/** GENESIS tx type: Creates a new token ID */
|
|
8
10
|
export const GENESIS_STR = 'GENESIS';
|
|
@@ -52,3 +54,16 @@ export interface GenesisInfo {
|
|
|
52
54
|
/** decimals of the token, i.e. how many decimal places the token should be displayed with. */
|
|
53
55
|
decimals?: number;
|
|
54
56
|
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* SLP/ALP token type.
|
|
60
|
+
*
|
|
61
|
+
* See `TokenType` in chronik-client.
|
|
62
|
+
*/
|
|
63
|
+
export type TokenType = SlpTokenType | AlpTokenType | UnknownTokenType;
|
|
64
|
+
|
|
65
|
+
export interface UnknownTokenType {
|
|
66
|
+
protocol: 'UNKNOWN';
|
|
67
|
+
type: 'UNKNOWN';
|
|
68
|
+
number: 0;
|
|
69
|
+
}
|
package/src/token/slp.parse.ts
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
SLP_MINT_VAULT_SCRIPTHASH_NUM_BYTES,
|
|
28
28
|
SLP_NFT1_CHILD,
|
|
29
29
|
SLP_NFT1_GROUP,
|
|
30
|
-
|
|
30
|
+
SlpTokenType_Number,
|
|
31
31
|
} from './slp.js';
|
|
32
32
|
|
|
33
33
|
/** Parsed SLP GENESIS OP_RETURN Script */
|
|
@@ -35,7 +35,7 @@ export interface SlpGenesis {
|
|
|
35
35
|
/** "GENESIS" */
|
|
36
36
|
txType: typeof GENESIS_STR;
|
|
37
37
|
/** Token type of the token to create */
|
|
38
|
-
tokenType:
|
|
38
|
+
tokenType: SlpTokenType_Number;
|
|
39
39
|
/** Info about the token */
|
|
40
40
|
genesisInfo: GenesisInfo;
|
|
41
41
|
/** Number of token atoms to initially mint to out_idx=1 */
|
|
@@ -81,7 +81,7 @@ export interface SlpSend {
|
|
|
81
81
|
/** "SEND" */
|
|
82
82
|
txType: typeof SEND_STR;
|
|
83
83
|
/** Token type of the token to send */
|
|
84
|
-
tokenType:
|
|
84
|
+
tokenType: SlpTokenType_Number;
|
|
85
85
|
/** Token ID of the token to send */
|
|
86
86
|
tokenId: string;
|
|
87
87
|
/** Array of the number of token atoms to send to the outputs at 1 to N */
|
|
@@ -93,7 +93,7 @@ export interface SlpBurn {
|
|
|
93
93
|
/** "BURN" */
|
|
94
94
|
txType: typeof BURN_STR;
|
|
95
95
|
/** Token type of the token to burn */
|
|
96
|
-
tokenType:
|
|
96
|
+
tokenType: SlpTokenType_Number;
|
|
97
97
|
/** Token ID of the token to burn */
|
|
98
98
|
tokenId: string;
|
|
99
99
|
/** How many tokens should be burned */
|
|
@@ -190,7 +190,10 @@ export function parseSlp(opreturnScript: Script): SlpData | undefined {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
function nextGenesis(
|
|
193
|
+
function nextGenesis(
|
|
194
|
+
ops: ScriptOpIter,
|
|
195
|
+
tokenType: SlpTokenType_Number,
|
|
196
|
+
): SlpGenesis {
|
|
194
197
|
// Parse genesis info
|
|
195
198
|
const tokenTicker = bytesToStr(nextBytesRequired(ops, 'tokenTicker'));
|
|
196
199
|
const tokenName = bytesToStr(nextBytesRequired(ops, 'tokenName'));
|
|
@@ -243,7 +246,7 @@ function nextGenesis(ops: ScriptOpIter, tokenType: SlpTokenType): SlpGenesis {
|
|
|
243
246
|
};
|
|
244
247
|
}
|
|
245
248
|
|
|
246
|
-
function nextMint(ops: ScriptOpIter, tokenType:
|
|
249
|
+
function nextMint(ops: ScriptOpIter, tokenType: SlpTokenType_Number): SlpMint {
|
|
247
250
|
const tokenId = nextTokenId(ops);
|
|
248
251
|
if (tokenType === SLP_MINT_VAULT) {
|
|
249
252
|
const additionalAtomsArray = nextSlpAtomsArray(ops);
|
|
@@ -271,7 +274,7 @@ function nextMint(ops: ScriptOpIter, tokenType: SlpTokenType): SlpMint {
|
|
|
271
274
|
}
|
|
272
275
|
}
|
|
273
276
|
|
|
274
|
-
function nextSend(ops: ScriptOpIter, tokenType:
|
|
277
|
+
function nextSend(ops: ScriptOpIter, tokenType: SlpTokenType_Number): SlpSend {
|
|
275
278
|
const tokenId = nextTokenId(ops);
|
|
276
279
|
const sendAtomsArray = nextSlpAtomsArray(ops);
|
|
277
280
|
return {
|
|
@@ -282,7 +285,7 @@ function nextSend(ops: ScriptOpIter, tokenType: SlpTokenType): SlpSend {
|
|
|
282
285
|
};
|
|
283
286
|
}
|
|
284
287
|
|
|
285
|
-
function nextBurn(ops: ScriptOpIter, tokenType:
|
|
288
|
+
function nextBurn(ops: ScriptOpIter, tokenType: SlpTokenType_Number): SlpBurn {
|
|
286
289
|
const tokenId = nextTokenId(ops);
|
|
287
290
|
const burnAtoms = parseSlpAtoms(nextBytesRequired(ops, 'burnAtoms'));
|
|
288
291
|
nextEnd(ops, 'BURN');
|
package/src/token/slp.ts
CHANGED
|
@@ -36,12 +36,32 @@ export const SLP_MAX_SEND_OUTPUTS = 19;
|
|
|
36
36
|
export const SLP_ATOMS_NUM_BYTES = 8;
|
|
37
37
|
|
|
38
38
|
/** Supported SLP token types */
|
|
39
|
-
export
|
|
39
|
+
export interface SlpTokenType {
|
|
40
|
+
protocol: 'SLP';
|
|
41
|
+
type: SlpTokenType_Type;
|
|
42
|
+
number: SlpTokenType_Number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Possible SLP token types returned by chronik */
|
|
46
|
+
export type SlpTokenType_Type =
|
|
47
|
+
| 'SLP_TOKEN_TYPE_FUNGIBLE'
|
|
48
|
+
| 'SLP_TOKEN_TYPE_MINT_VAULT'
|
|
49
|
+
| 'SLP_TOKEN_TYPE_NFT1_GROUP'
|
|
50
|
+
| 'SLP_TOKEN_TYPE_NFT1_CHILD'
|
|
51
|
+
| 'SLP_TOKEN_TYPE_UNKNOWN';
|
|
52
|
+
|
|
53
|
+
export type SlpTokenType_Number =
|
|
40
54
|
| typeof SLP_FUNGIBLE
|
|
41
55
|
| typeof SLP_MINT_VAULT
|
|
42
56
|
| typeof SLP_NFT1_CHILD
|
|
43
57
|
| typeof SLP_NFT1_GROUP;
|
|
44
58
|
|
|
59
|
+
export const SLP_TOKEN_TYPE_FUNGIBLE: SlpTokenType = {
|
|
60
|
+
protocol: 'SLP',
|
|
61
|
+
type: 'SLP_TOKEN_TYPE_FUNGIBLE',
|
|
62
|
+
number: SLP_FUNGIBLE,
|
|
63
|
+
};
|
|
64
|
+
|
|
45
65
|
/** Build an SLP GENESIS OP_RETURN, creating a new SLP token */
|
|
46
66
|
export function slpGenesis(
|
|
47
67
|
tokenType: number,
|