@chainvue/verus-sdk 0.4.0
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/LICENSE +21 -0
- package/README.md +75 -0
- package/dist/VerusSDK.d.ts +59 -0
- package/dist/VerusSDK.d.ts.map +1 -0
- package/dist/VerusSDK.js +170 -0
- package/dist/VerusSDK.js.map +1 -0
- package/dist/address/index.d.ts +16 -0
- package/dist/address/index.d.ts.map +1 -0
- package/dist/address/index.js +33 -0
- package/dist/address/index.js.map +1 -0
- package/dist/bundle.js +34129 -0
- package/dist/constants/index.d.ts +51 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +53 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/currency/classify.d.ts +14 -0
- package/dist/currency/classify.d.ts.map +1 -0
- package/dist/currency/classify.js +32 -0
- package/dist/currency/classify.js.map +1 -0
- package/dist/currency/index.d.ts +22 -0
- package/dist/currency/index.d.ts.map +1 -0
- package/dist/currency/index.js +87 -0
- package/dist/currency/index.js.map +1 -0
- package/dist/errors.d.ts +37 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +69 -0
- package/dist/errors.js.map +1 -0
- package/dist/identity/index.d.ts +129 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +691 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -0
- package/dist/keys/index.d.ts +48 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +169 -0
- package/dist/keys/index.js.map +1 -0
- package/dist/message/index.d.ts +18 -0
- package/dist/message/index.d.ts.map +1 -0
- package/dist/message/index.js +61 -0
- package/dist/message/index.js.map +1 -0
- package/dist/signing/index.d.ts +53 -0
- package/dist/signing/index.d.ts.map +1 -0
- package/dist/signing/index.js +100 -0
- package/dist/signing/index.js.map +1 -0
- package/dist/transfer/index.d.ts +37 -0
- package/dist/transfer/index.d.ts.map +1 -0
- package/dist/transfer/index.js +275 -0
- package/dist/transfer/index.js.map +1 -0
- package/dist/types/index.d.ts +359 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +48 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +141 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utxo/index.d.ts +21 -0
- package/dist/utxo/index.d.ts.map +1 -0
- package/dist/utxo/index.js +139 -0
- package/dist/utxo/index.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verus protocol constants and network configuration
|
|
3
|
+
*/
|
|
4
|
+
export type Network = 'mainnet' | 'testnet';
|
|
5
|
+
export declare const NETWORK_CONFIG: {
|
|
6
|
+
readonly mainnet: {
|
|
7
|
+
readonly chainId: "i5w5MuNik5NtLcYmNzcvaoixooEebB6MGV";
|
|
8
|
+
readonly pubKeyHash: 60;
|
|
9
|
+
readonly scriptHash: 85;
|
|
10
|
+
readonly wif: 188;
|
|
11
|
+
};
|
|
12
|
+
readonly testnet: {
|
|
13
|
+
readonly chainId: "iJhCezBExJHvtyH3fGhNnt2NhU4Ztkf2yq";
|
|
14
|
+
readonly pubKeyHash: 60;
|
|
15
|
+
readonly scriptHash: 85;
|
|
16
|
+
readonly wif: 188;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/** Sapling consensus branch ID */
|
|
20
|
+
export declare const CONSENSUS_BRANCH_ID = 1991772603;
|
|
21
|
+
/** Sapling version group ID */
|
|
22
|
+
export declare const VERSION_GROUP_ID = 2301567109;
|
|
23
|
+
/** Default transaction version */
|
|
24
|
+
export declare const TX_VERSION = 4;
|
|
25
|
+
/** Default fee per KB in satoshis (0.0001 VRSC) */
|
|
26
|
+
export declare const DEFAULT_FEE_PER_KB = 10000;
|
|
27
|
+
/** Minimum output value (dust threshold) */
|
|
28
|
+
export declare const DUST_THRESHOLD = 546;
|
|
29
|
+
/** Default registration fee: 100 VRSC in satoshis */
|
|
30
|
+
export declare const DEFAULT_REGISTRATION_FEE = 10000000000;
|
|
31
|
+
/** Default referral levels for identity registration */
|
|
32
|
+
export declare const DEFAULT_REFERRAL_LEVELS = 3;
|
|
33
|
+
/** CReserveTransfer VRSC fee (20000 sat = 0.0002 VRSC) */
|
|
34
|
+
export declare const RESERVE_TRANSFER_FEE = 20000;
|
|
35
|
+
/** Canonical eval pubkey address for EVAL_RESERVE_TRANSFER */
|
|
36
|
+
export declare const RESERVE_TRANSFER_EVAL_PKH = "RTqQe58LSj2yr5CrwYFwcsAQ1edQwmrkUU";
|
|
37
|
+
/** Identity version byte for i-addresses */
|
|
38
|
+
export declare const I_ADDR_VERSION = 102;
|
|
39
|
+
/** PubKeyHash prefix for R-addresses */
|
|
40
|
+
export declare const PUBKEY_HASH_PREFIX = 60;
|
|
41
|
+
/** ScriptHash prefix */
|
|
42
|
+
export declare const SCRIPT_HASH_PREFIX = 85;
|
|
43
|
+
/** WIF prefix for Verus keys */
|
|
44
|
+
export declare const WIF_PREFIX = 188;
|
|
45
|
+
/** Identity flag: active currency defined */
|
|
46
|
+
export declare const IDENTITY_FLAG_ACTIVECURRENCY = 1;
|
|
47
|
+
/** Identity flag: locked */
|
|
48
|
+
export declare const IDENTITY_FLAG_LOCKED = 2;
|
|
49
|
+
/** Hash type for IdentitySignature */
|
|
50
|
+
export declare const HASH_SHA256 = 5;
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAE5C,eAAO,MAAM,cAAc;;;;;;;;;;;;;CAajB,CAAC;AAEX,kCAAkC;AAClC,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAE9C,+BAA+B;AAC/B,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C,kCAAkC;AAClC,eAAO,MAAM,UAAU,IAAI,CAAC;AAE5B,mDAAmD;AACnD,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AAExC,4CAA4C;AAC5C,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,qDAAqD;AACrD,eAAO,MAAM,wBAAwB,cAAiB,CAAC;AAEvD,wDAAwD;AACxD,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,0DAA0D;AAC1D,eAAO,MAAM,oBAAoB,QAAQ,CAAC;AAE1C,8DAA8D;AAC9D,eAAO,MAAM,yBAAyB,uCAAuC,CAAC;AAE9E,4CAA4C;AAC5C,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,wCAAwC;AACxC,eAAO,MAAM,kBAAkB,KAAO,CAAC;AAEvC,wBAAwB;AACxB,eAAO,MAAM,kBAAkB,KAAO,CAAC;AAEvC,gCAAgC;AAChC,eAAO,MAAM,UAAU,MAAO,CAAC;AAE/B,6CAA6C;AAC7C,eAAO,MAAM,4BAA4B,IAAM,CAAC;AAEhD,4BAA4B;AAC5B,eAAO,MAAM,oBAAoB,IAAM,CAAC;AAExC,sCAAsC;AACtC,eAAO,MAAM,WAAW,IAAI,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Verus protocol constants and network configuration
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HASH_SHA256 = exports.IDENTITY_FLAG_LOCKED = exports.IDENTITY_FLAG_ACTIVECURRENCY = exports.WIF_PREFIX = exports.SCRIPT_HASH_PREFIX = exports.PUBKEY_HASH_PREFIX = exports.I_ADDR_VERSION = exports.RESERVE_TRANSFER_EVAL_PKH = exports.RESERVE_TRANSFER_FEE = exports.DEFAULT_REFERRAL_LEVELS = exports.DEFAULT_REGISTRATION_FEE = exports.DUST_THRESHOLD = exports.DEFAULT_FEE_PER_KB = exports.TX_VERSION = exports.VERSION_GROUP_ID = exports.CONSENSUS_BRANCH_ID = exports.NETWORK_CONFIG = void 0;
|
|
7
|
+
exports.NETWORK_CONFIG = {
|
|
8
|
+
mainnet: {
|
|
9
|
+
chainId: 'i5w5MuNik5NtLcYmNzcvaoixooEebB6MGV',
|
|
10
|
+
pubKeyHash: 0x3c,
|
|
11
|
+
scriptHash: 0x55,
|
|
12
|
+
wif: 0xbc,
|
|
13
|
+
},
|
|
14
|
+
testnet: {
|
|
15
|
+
chainId: 'iJhCezBExJHvtyH3fGhNnt2NhU4Ztkf2yq',
|
|
16
|
+
pubKeyHash: 0x3c,
|
|
17
|
+
scriptHash: 0x55,
|
|
18
|
+
wif: 0xbc,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
/** Sapling consensus branch ID */
|
|
22
|
+
exports.CONSENSUS_BRANCH_ID = 0x76b809bb;
|
|
23
|
+
/** Sapling version group ID */
|
|
24
|
+
exports.VERSION_GROUP_ID = 0x892f2085;
|
|
25
|
+
/** Default transaction version */
|
|
26
|
+
exports.TX_VERSION = 4;
|
|
27
|
+
/** Default fee per KB in satoshis (0.0001 VRSC) */
|
|
28
|
+
exports.DEFAULT_FEE_PER_KB = 10000;
|
|
29
|
+
/** Minimum output value (dust threshold) */
|
|
30
|
+
exports.DUST_THRESHOLD = 546;
|
|
31
|
+
/** Default registration fee: 100 VRSC in satoshis */
|
|
32
|
+
exports.DEFAULT_REGISTRATION_FEE = 10000000000;
|
|
33
|
+
/** Default referral levels for identity registration */
|
|
34
|
+
exports.DEFAULT_REFERRAL_LEVELS = 3;
|
|
35
|
+
/** CReserveTransfer VRSC fee (20000 sat = 0.0002 VRSC) */
|
|
36
|
+
exports.RESERVE_TRANSFER_FEE = 20000;
|
|
37
|
+
/** Canonical eval pubkey address for EVAL_RESERVE_TRANSFER */
|
|
38
|
+
exports.RESERVE_TRANSFER_EVAL_PKH = 'RTqQe58LSj2yr5CrwYFwcsAQ1edQwmrkUU';
|
|
39
|
+
/** Identity version byte for i-addresses */
|
|
40
|
+
exports.I_ADDR_VERSION = 102; // 0x66
|
|
41
|
+
/** PubKeyHash prefix for R-addresses */
|
|
42
|
+
exports.PUBKEY_HASH_PREFIX = 0x3c;
|
|
43
|
+
/** ScriptHash prefix */
|
|
44
|
+
exports.SCRIPT_HASH_PREFIX = 0x55;
|
|
45
|
+
/** WIF prefix for Verus keys */
|
|
46
|
+
exports.WIF_PREFIX = 0xbc;
|
|
47
|
+
/** Identity flag: active currency defined */
|
|
48
|
+
exports.IDENTITY_FLAG_ACTIVECURRENCY = 0x1;
|
|
49
|
+
/** Identity flag: locked */
|
|
50
|
+
exports.IDENTITY_FLAG_LOCKED = 0x2;
|
|
51
|
+
/** Hash type for IdentitySignature */
|
|
52
|
+
exports.HASH_SHA256 = 5;
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIU,QAAA,cAAc,GAAG;IAC5B,OAAO,EAAE;QACP,OAAO,EAAE,oCAAoC;QAC7C,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE,IAAI;QAChB,GAAG,EAAE,IAAI;KACV;IACD,OAAO,EAAE;QACP,OAAO,EAAE,oCAAoC;QAC7C,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE,IAAI;QAChB,GAAG,EAAE,IAAI;KACV;CACO,CAAC;AAEX,kCAAkC;AACrB,QAAA,mBAAmB,GAAG,UAAU,CAAC;AAE9C,+BAA+B;AAClB,QAAA,gBAAgB,GAAG,UAAU,CAAC;AAE3C,kCAAkC;AACrB,QAAA,UAAU,GAAG,CAAC,CAAC;AAE5B,mDAAmD;AACtC,QAAA,kBAAkB,GAAG,KAAK,CAAC;AAExC,4CAA4C;AAC/B,QAAA,cAAc,GAAG,GAAG,CAAC;AAElC,qDAAqD;AACxC,QAAA,wBAAwB,GAAG,WAAc,CAAC;AAEvD,wDAAwD;AAC3C,QAAA,uBAAuB,GAAG,CAAC,CAAC;AAEzC,0DAA0D;AAC7C,QAAA,oBAAoB,GAAG,KAAK,CAAC;AAE1C,8DAA8D;AACjD,QAAA,yBAAyB,GAAG,oCAAoC,CAAC;AAE9E,4CAA4C;AAC/B,QAAA,cAAc,GAAG,GAAG,CAAC,CAAC,OAAO;AAE1C,wCAAwC;AAC3B,QAAA,kBAAkB,GAAG,IAAI,CAAC;AAEvC,wBAAwB;AACX,QAAA,kBAAkB,GAAG,IAAI,CAAC;AAEvC,gCAAgC;AACnB,QAAA,UAAU,GAAG,IAAI,CAAC;AAE/B,6CAA6C;AAChC,QAAA,4BAA4B,GAAG,GAAG,CAAC;AAEhD,4BAA4B;AACf,QAAA,oBAAoB,GAAG,GAAG,CAAC;AAExC,sCAAsC;AACzB,QAAA,WAAW,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency classification from getcurrency RPC response
|
|
3
|
+
*/
|
|
4
|
+
export type CurrencyType = 'native' | 'gateway' | 'bridge' | 'liquidity_pool' | 'token' | 'nft';
|
|
5
|
+
/** Sort priority: native first, then gateway, bridge, liquidity_pool, token, nft */
|
|
6
|
+
export declare const CURRENCY_TYPE_ORDER: Record<CurrencyType, number>;
|
|
7
|
+
/** Classify a getcurrency RPC response by its options bitmask */
|
|
8
|
+
export declare function classifyCurrency(currencyInfo: {
|
|
9
|
+
systemid?: string;
|
|
10
|
+
currencyid?: string;
|
|
11
|
+
options?: number;
|
|
12
|
+
currencies?: any;
|
|
13
|
+
}): CurrencyType;
|
|
14
|
+
//# sourceMappingURL=classify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../../src/currency/classify.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AAEhG,oFAAoF;AACpF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAO5D,CAAC;AAEF,iEAAiE;AACjE,wBAAgB,gBAAgB,CAAC,YAAY,EAAE;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB,GAAG,YAAY,CAQf"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Currency classification from getcurrency RPC response
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CURRENCY_TYPE_ORDER = void 0;
|
|
7
|
+
exports.classifyCurrency = classifyCurrency;
|
|
8
|
+
/** Sort priority: native first, then gateway, bridge, liquidity_pool, token, nft */
|
|
9
|
+
exports.CURRENCY_TYPE_ORDER = {
|
|
10
|
+
native: 0,
|
|
11
|
+
gateway: 1,
|
|
12
|
+
bridge: 2,
|
|
13
|
+
liquidity_pool: 3,
|
|
14
|
+
token: 4,
|
|
15
|
+
nft: 5,
|
|
16
|
+
};
|
|
17
|
+
/** Classify a getcurrency RPC response by its options bitmask */
|
|
18
|
+
function classifyCurrency(currencyInfo) {
|
|
19
|
+
if (currencyInfo.systemid === currencyInfo.currencyid)
|
|
20
|
+
return 'native';
|
|
21
|
+
const opts = currencyInfo.options ?? 0;
|
|
22
|
+
if (opts & 0x200)
|
|
23
|
+
return 'bridge';
|
|
24
|
+
if (opts & 0x80)
|
|
25
|
+
return 'gateway';
|
|
26
|
+
if ((opts & 0x01) && currencyInfo.currencies)
|
|
27
|
+
return 'liquidity_pool';
|
|
28
|
+
if (opts & 0x800)
|
|
29
|
+
return 'nft';
|
|
30
|
+
return 'token';
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=classify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classify.js","sourceRoot":"","sources":["../../src/currency/classify.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAeH,4CAaC;AAxBD,oFAAoF;AACvE,QAAA,mBAAmB,GAAiC;IAC/D,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;IACV,MAAM,EAAE,CAAC;IACT,cAAc,EAAE,CAAC;IACjB,KAAK,EAAE,CAAC;IACR,GAAG,EAAE,CAAC;CACP,CAAC;AAEF,iEAAiE;AACjE,SAAgB,gBAAgB,CAAC,YAKhC;IACC,IAAI,YAAY,CAAC,QAAQ,KAAK,YAAY,CAAC,UAAU;QAAE,OAAO,QAAQ,CAAC;IACvE,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,IAAI,CAAC,CAAC;IACvC,IAAI,IAAI,GAAG,KAAK;QAAE,OAAO,QAAQ,CAAC;IAClC,IAAI,IAAI,GAAG,IAAI;QAAE,OAAO,SAAS,CAAC;IAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,YAAY,CAAC,UAAU;QAAE,OAAO,gBAAgB,CAAC;IACtE,IAAI,IAAI,GAAG,KAAK;QAAE,OAAO,KAAK,CAAC;IAC/B,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency definition (manual mode only — offline)
|
|
3
|
+
*
|
|
4
|
+
* Creates a currency definition transaction. Requires a pre-built
|
|
5
|
+
* currency definition script hex (obtained externally).
|
|
6
|
+
*
|
|
7
|
+
* Currency creation requires:
|
|
8
|
+
* 1. An existing identity with the same name
|
|
9
|
+
* 2. The identity's FLAG_ACTIVECURRENCY must be set
|
|
10
|
+
* 3. A currency definition output (EVAL_CURRENCY_DEFINITION)
|
|
11
|
+
*/
|
|
12
|
+
export { classifyCurrency, CURRENCY_TYPE_ORDER } from './classify.js';
|
|
13
|
+
export type { CurrencyType } from './classify.js';
|
|
14
|
+
import type { Network } from '../constants/index.js';
|
|
15
|
+
import type { DefineCurrencyParams, DefineCurrencyResult } from '../types/index.js';
|
|
16
|
+
/**
|
|
17
|
+
* Build and sign a currency definition transaction (manual mode)
|
|
18
|
+
*
|
|
19
|
+
* Takes a pre-built currency definition script hex. No node RPC needed.
|
|
20
|
+
*/
|
|
21
|
+
export declare function defineCurrency(params: DefineCurrencyParams, network: Network): DefineCurrencyResult;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/currency/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACtE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAMlD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGrD,OAAO,KAAK,EAAQ,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAI1F;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,OAAO,GACf,oBAAoB,CAsFtB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Currency definition (manual mode only — offline)
|
|
4
|
+
*
|
|
5
|
+
* Creates a currency definition transaction. Requires a pre-built
|
|
6
|
+
* currency definition script hex (obtained externally).
|
|
7
|
+
*
|
|
8
|
+
* Currency creation requires:
|
|
9
|
+
* 1. An existing identity with the same name
|
|
10
|
+
* 2. The identity's FLAG_ACTIVECURRENCY must be set
|
|
11
|
+
* 3. A currency definition output (EVAL_CURRENCY_DEFINITION)
|
|
12
|
+
*/
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.CURRENCY_TYPE_ORDER = exports.classifyCurrency = void 0;
|
|
18
|
+
exports.defineCurrency = defineCurrency;
|
|
19
|
+
// Re-export classification utilities
|
|
20
|
+
var classify_js_1 = require("./classify.js");
|
|
21
|
+
Object.defineProperty(exports, "classifyCurrency", { enumerable: true, get: function () { return classify_js_1.classifyCurrency; } });
|
|
22
|
+
Object.defineProperty(exports, "CURRENCY_TYPE_ORDER", { enumerable: true, get: function () { return classify_js_1.CURRENCY_TYPE_ORDER; } });
|
|
23
|
+
const utxo_lib_1 = require("@bitgo/utxo-lib");
|
|
24
|
+
const verus_typescript_primitives_1 = require("verus-typescript-primitives");
|
|
25
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
26
|
+
const index_js_1 = require("../constants/index.js");
|
|
27
|
+
const index_js_2 = require("../signing/index.js");
|
|
28
|
+
const index_js_3 = require("../utxo/index.js");
|
|
29
|
+
const { completeFundedIdentityUpdate } = utxo_lib_1.smarttxs;
|
|
30
|
+
/**
|
|
31
|
+
* Build and sign a currency definition transaction (manual mode)
|
|
32
|
+
*
|
|
33
|
+
* Takes a pre-built currency definition script hex. No node RPC needed.
|
|
34
|
+
*/
|
|
35
|
+
function defineCurrency(params, network) {
|
|
36
|
+
const verusNetwork = (0, index_js_2.getNetwork)(network === 'testnet');
|
|
37
|
+
const networkConfig = index_js_1.NETWORK_CONFIG[network];
|
|
38
|
+
const systemId = networkConfig.chainId;
|
|
39
|
+
const currencyDefValue = params.currencyDefValue || 0;
|
|
40
|
+
// Parse identity and set FLAG_ACTIVECURRENCY
|
|
41
|
+
const identity = new verus_typescript_primitives_1.Identity();
|
|
42
|
+
identity.fromBuffer(Buffer.from(params.identityHex, 'hex'));
|
|
43
|
+
if (!identity.hasActiveCurrency()) {
|
|
44
|
+
const currentFlags = identity.flags.toNumber();
|
|
45
|
+
identity.flags = new bn_js_1.default(currentFlags | index_js_1.IDENTITY_FLAG_ACTIVECURRENCY);
|
|
46
|
+
}
|
|
47
|
+
const identityScript = verus_typescript_primitives_1.IdentityScript.fromIdentity(identity);
|
|
48
|
+
const identityOutputScript = identityScript.toBuffer();
|
|
49
|
+
const currencyDefScript = Buffer.from(params.currencyDefScript, 'hex');
|
|
50
|
+
// Select funding UTXOs
|
|
51
|
+
const selection = (0, index_js_3.selectUtxos)(params.utxos, currencyDefValue, new Map(), 2, systemId, undefined, true);
|
|
52
|
+
// Build transaction
|
|
53
|
+
const txb = new utxo_lib_1.TransactionBuilder(verusNetwork);
|
|
54
|
+
txb.setVersion(4);
|
|
55
|
+
txb.setExpiryHeight(params.expiryHeight || 0);
|
|
56
|
+
txb.setVersionGroupId(index_js_1.VERSION_GROUP_ID);
|
|
57
|
+
for (const utxo of selection.selected) {
|
|
58
|
+
txb.addInput(Buffer.from(utxo.txid, 'hex').reverse(), utxo.outputIndex, 0xffffffff, Buffer.from(utxo.script, 'hex'));
|
|
59
|
+
}
|
|
60
|
+
txb.addOutput(identityOutputScript, 0);
|
|
61
|
+
txb.addOutput(currencyDefScript, currencyDefValue);
|
|
62
|
+
if (selection.nativeChange > 0) {
|
|
63
|
+
txb.addOutput(params.changeAddress, selection.nativeChange);
|
|
64
|
+
}
|
|
65
|
+
const fundedTx = txb.buildIncomplete();
|
|
66
|
+
const fundedHex = fundedTx.toHex();
|
|
67
|
+
// Add the previous identity UTXO as last input
|
|
68
|
+
const prevOutScripts = selection.selected.map(u => Buffer.from(u.script, 'hex'));
|
|
69
|
+
const idUtxo = params.identityUtxo;
|
|
70
|
+
const completedHex = completeFundedIdentityUpdate(fundedHex, verusNetwork, prevOutScripts, {
|
|
71
|
+
hash: Buffer.from(idUtxo.txid, 'hex').reverse(),
|
|
72
|
+
index: idUtxo.outputIndex,
|
|
73
|
+
sequence: 0xffffffff,
|
|
74
|
+
script: Buffer.from(idUtxo.script, 'hex'),
|
|
75
|
+
});
|
|
76
|
+
const allUtxos = [...selection.selected, idUtxo];
|
|
77
|
+
const { signedTx, txid } = (0, index_js_2.signTransactionSmart)(completedHex, params.wif, allUtxos, verusNetwork);
|
|
78
|
+
return {
|
|
79
|
+
signedTx,
|
|
80
|
+
txid,
|
|
81
|
+
fee: selection.fee,
|
|
82
|
+
identityAddress: identity.getIdentityAddress(),
|
|
83
|
+
inputsUsed: allUtxos.length,
|
|
84
|
+
nativeChange: selection.nativeChange,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/currency/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;AAsBH,wCAyFC;AA7GD,qCAAqC;AACrC,6CAAsE;AAA7D,+GAAA,gBAAgB,OAAA;AAAE,kHAAA,mBAAmB,OAAA;AAG9C,8CAA+D;AAC/D,6EAAuE;AACvE,kDAAuB;AACvB,oDAAuG;AAEvG,kDAAuE;AACvE,+CAA+C;AAG/C,MAAM,EAAE,4BAA4B,EAAE,GAAG,mBAAQ,CAAC;AAElD;;;;GAIG;AACH,SAAgB,cAAc,CAC5B,MAA4B,EAC5B,OAAgB;IAEhB,MAAM,YAAY,GAAG,IAAA,qBAAU,EAAC,OAAO,KAAK,SAAS,CAAC,CAAC;IACvD,MAAM,aAAa,GAAG,yBAAc,CAAC,OAAO,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC;IACvC,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,IAAI,CAAC,CAAC;IAEtD,6CAA6C;IAC7C,MAAM,QAAQ,GAAG,IAAI,sCAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,UA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GAAG;QAClB,eAAe,EAAE,QAAQ,CAAC,kBAAkB,EAAE;QAC9C,UAAU,EAAE,QAAQ,CAAC,MAAM;QAC3B,YAAY,EAAE,SAAS,CAAC,YAAY;KACrC,CAAC;AACJ,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error classes for the Verus TypeScript SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides structured errors with machine-readable codes and
|
|
5
|
+
* contextual data for callers to handle programmatically.
|
|
6
|
+
*/
|
|
7
|
+
/** Base error class for all SDK errors */
|
|
8
|
+
export declare class VerusError extends Error {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
constructor(code: string, message: string);
|
|
11
|
+
}
|
|
12
|
+
/** Thrown when UTXOs cannot cover the required amount */
|
|
13
|
+
export declare class InsufficientFundsError extends VerusError {
|
|
14
|
+
readonly required: number;
|
|
15
|
+
readonly available: number;
|
|
16
|
+
readonly currency: string;
|
|
17
|
+
constructor(required: number, available: number, currency?: string);
|
|
18
|
+
}
|
|
19
|
+
/** Thrown when a WIF key is missing, empty, or malformed */
|
|
20
|
+
export declare class InvalidWifError extends VerusError {
|
|
21
|
+
constructor(detail?: string);
|
|
22
|
+
}
|
|
23
|
+
/** Thrown when an address fails format validation */
|
|
24
|
+
export declare class InvalidAddressError extends VerusError {
|
|
25
|
+
readonly address: string;
|
|
26
|
+
constructor(address: string, detail?: string);
|
|
27
|
+
}
|
|
28
|
+
/** Thrown when an identity name fails validation */
|
|
29
|
+
export declare class InvalidNameError extends VerusError {
|
|
30
|
+
readonly identityName: string;
|
|
31
|
+
constructor(identityName: string, detail?: string);
|
|
32
|
+
}
|
|
33
|
+
/** Thrown when transaction construction fails for structural reasons */
|
|
34
|
+
export declare class TransactionBuildError extends VerusError {
|
|
35
|
+
constructor(detail: string);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,0CAA0C;AAC1C,qBAAa,UAAW,SAAQ,KAAK;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAED,yDAAyD;AACzD,qBAAa,sBAAuB,SAAQ,UAAU;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAe;CAW3E;AAED,4DAA4D;AAC5D,qBAAa,eAAgB,SAAQ,UAAU;gBACjC,MAAM,CAAC,EAAE,MAAM;CAI5B;AAED,qDAAqD;AACrD,qBAAa,mBAAoB,SAAQ,UAAU;IACjD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAU7C;AAED,oDAAoD;AACpD,qBAAa,gBAAiB,SAAQ,UAAU;IAC9C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;gBAElB,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAUlD;AAED,wEAAwE;AACxE,qBAAa,qBAAsB,SAAQ,UAAU;gBACvC,MAAM,EAAE,MAAM;CAI3B"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Typed error classes for the Verus TypeScript SDK
|
|
4
|
+
*
|
|
5
|
+
* Provides structured errors with machine-readable codes and
|
|
6
|
+
* contextual data for callers to handle programmatically.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TransactionBuildError = exports.InvalidNameError = exports.InvalidAddressError = exports.InvalidWifError = exports.InsufficientFundsError = exports.VerusError = void 0;
|
|
10
|
+
/** Base error class for all SDK errors */
|
|
11
|
+
class VerusError extends Error {
|
|
12
|
+
constructor(code, message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'VerusError';
|
|
15
|
+
this.code = code;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.VerusError = VerusError;
|
|
19
|
+
/** Thrown when UTXOs cannot cover the required amount */
|
|
20
|
+
class InsufficientFundsError extends VerusError {
|
|
21
|
+
constructor(required, available, currency = 'VRSC') {
|
|
22
|
+
const shortfall = required - available;
|
|
23
|
+
super('INSUFFICIENT_FUNDS', `Insufficient ${currency} balance. Need ${shortfall} more satoshis (required: ${required}, available: ${available}).`);
|
|
24
|
+
this.name = 'InsufficientFundsError';
|
|
25
|
+
this.required = required;
|
|
26
|
+
this.available = available;
|
|
27
|
+
this.currency = currency;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.InsufficientFundsError = InsufficientFundsError;
|
|
31
|
+
/** Thrown when a WIF key is missing, empty, or malformed */
|
|
32
|
+
class InvalidWifError extends VerusError {
|
|
33
|
+
constructor(detail) {
|
|
34
|
+
super('INVALID_WIF', detail ? `Invalid WIF: ${detail}` : 'Invalid or missing WIF key.');
|
|
35
|
+
this.name = 'InvalidWifError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.InvalidWifError = InvalidWifError;
|
|
39
|
+
/** Thrown when an address fails format validation */
|
|
40
|
+
class InvalidAddressError extends VerusError {
|
|
41
|
+
constructor(address, detail) {
|
|
42
|
+
super('INVALID_ADDRESS', detail
|
|
43
|
+
? `Invalid address "${address}": ${detail}`
|
|
44
|
+
: `Invalid address: "${address}"`);
|
|
45
|
+
this.name = 'InvalidAddressError';
|
|
46
|
+
this.address = address;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.InvalidAddressError = InvalidAddressError;
|
|
50
|
+
/** Thrown when an identity name fails validation */
|
|
51
|
+
class InvalidNameError extends VerusError {
|
|
52
|
+
constructor(identityName, detail) {
|
|
53
|
+
super('INVALID_NAME', detail
|
|
54
|
+
? `Invalid identity name "${identityName}": ${detail}`
|
|
55
|
+
: `Invalid identity name: "${identityName}". Must be 1-64 characters: a-z, 0-9, _, -`);
|
|
56
|
+
this.name = 'InvalidNameError';
|
|
57
|
+
this.identityName = identityName;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.InvalidNameError = InvalidNameError;
|
|
61
|
+
/** Thrown when transaction construction fails for structural reasons */
|
|
62
|
+
class TransactionBuildError extends VerusError {
|
|
63
|
+
constructor(detail) {
|
|
64
|
+
super('TX_BUILD_ERROR', `Transaction build failed: ${detail}`);
|
|
65
|
+
this.name = 'TransactionBuildError';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.TransactionBuildError = TransactionBuildError;
|
|
69
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,0CAA0C;AAC1C,MAAa,UAAW,SAAQ,KAAK;IAGnC,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AARD,gCAQC;AAED,yDAAyD;AACzD,MAAa,sBAAuB,SAAQ,UAAU;IAKpD,YAAY,QAAgB,EAAE,SAAiB,EAAE,WAAmB,MAAM;QACxE,MAAM,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;QACvC,KAAK,CACH,oBAAoB,EACpB,gBAAgB,QAAQ,kBAAkB,SAAS,6BAA6B,QAAQ,gBAAgB,SAAS,I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BAAgB,EAAE,6BAA6B,MAAM,EAAE,CAAC,CAAC;QAC/D,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AALD,sDAKC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity transaction building utilities and workflows
|
|
3
|
+
*
|
|
4
|
+
* Handles:
|
|
5
|
+
* - Name commitment (Step 1 of identity creation)
|
|
6
|
+
* - Identity registration (Step 2)
|
|
7
|
+
* - Identity updates (modify, revoke, recover, lock, unlock)
|
|
8
|
+
* - Script/hash construction for CC outputs
|
|
9
|
+
*/
|
|
10
|
+
import { Identity } from 'verus-typescript-primitives';
|
|
11
|
+
import { nameAndParentAddrToIAddr } from 'verus-typescript-primitives';
|
|
12
|
+
import type { Network } from '../constants/index.js';
|
|
13
|
+
import type { CreateCommitmentParams, CreateCommitmentResult, RegisterIdentityParams, RegisterIdentityResult, UpdateIdentityParams, UpdateIdentityResult } from '../types/index.js';
|
|
14
|
+
export { nameAndParentAddrToIAddr };
|
|
15
|
+
/**
|
|
16
|
+
* Generate a random 32-byte salt for name commitment
|
|
17
|
+
*/
|
|
18
|
+
export declare function generateSalt(): Buffer;
|
|
19
|
+
/**
|
|
20
|
+
* Serialize a CNameReservation (for VRSC-parent identities)
|
|
21
|
+
*/
|
|
22
|
+
export declare function serializeNameReservation(name: string, referralHash: Buffer, salt: Buffer): Buffer;
|
|
23
|
+
/**
|
|
24
|
+
* Serialize a CAdvancedNameReservation (for PBaaS-parent identities)
|
|
25
|
+
*/
|
|
26
|
+
export declare function serializeAdvancedNameReservation(version: number, name: string, parentHash: Buffer, referralHash: Buffer, salt: Buffer): Buffer;
|
|
27
|
+
/**
|
|
28
|
+
* Calculate the commitment hash from a serialized name reservation
|
|
29
|
+
*/
|
|
30
|
+
export declare function calculateCommitmentHash(serializedReservation: Buffer): Buffer;
|
|
31
|
+
/**
|
|
32
|
+
* Serialize a CCommitmentHash
|
|
33
|
+
*/
|
|
34
|
+
export declare function serializeCommitmentHash(hash: Buffer): Buffer;
|
|
35
|
+
/**
|
|
36
|
+
* Build the commitment output script
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildCommitmentScript(commitmentHashBuf: Buffer, controlAddress: string): Buffer;
|
|
39
|
+
/**
|
|
40
|
+
* Build the name reservation output script
|
|
41
|
+
*/
|
|
42
|
+
export declare function buildReservationScript(newIdentityIAddress: string, serializedReservation: Buffer, isAdvanced?: boolean): Buffer;
|
|
43
|
+
/**
|
|
44
|
+
* Build an identity definition output script from an Identity object
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildIdentityScript(identity: Identity): Buffer;
|
|
47
|
+
/**
|
|
48
|
+
* Derive the identity i-address from a name and optional parent
|
|
49
|
+
*/
|
|
50
|
+
export declare function deriveIdentityAddress(name: string, parentIAddress?: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Determine if a parent is the VRSC root system
|
|
53
|
+
*/
|
|
54
|
+
export declare function isVRSCParent(parentIAddress: string | undefined, network?: Network): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Build the full commitment data needed for Step 1 of identity creation
|
|
57
|
+
*/
|
|
58
|
+
export declare function prepareNameCommitment(name: string, controlAddress: string, referralIAddress?: string, parentIAddress?: string, network?: Network): {
|
|
59
|
+
salt: Buffer;
|
|
60
|
+
serializedReservation: Buffer;
|
|
61
|
+
commitmentHash: Buffer;
|
|
62
|
+
serializedCommitmentHash: Buffer;
|
|
63
|
+
commitmentScript: Buffer;
|
|
64
|
+
identityAddress: string;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Build a P2ID output script (pay to identity)
|
|
68
|
+
*/
|
|
69
|
+
export declare function buildP2IDScript(iAddress: string): Buffer;
|
|
70
|
+
/**
|
|
71
|
+
* The standard pay-to-identity output script (CC EVAL_NONE 1-of-1 to an
|
|
72
|
+
* IdentityID) — byte-identical to what the chain itself produces when paying
|
|
73
|
+
* an identity (verified against on-chain P2ID outputs). Use this for change
|
|
74
|
+
* or payment outputs to an i-address.
|
|
75
|
+
*/
|
|
76
|
+
export declare function identityPaymentScript(iAddress: string): Buffer;
|
|
77
|
+
/**
|
|
78
|
+
* Build a CC referral payment output script
|
|
79
|
+
*/
|
|
80
|
+
export declare function buildReferralPaymentScript(iAddress: string): Buffer;
|
|
81
|
+
/**
|
|
82
|
+
* Calculate registration fee breakdown
|
|
83
|
+
*/
|
|
84
|
+
export declare function calculateRegistrationFees(hasReferral: boolean, totalFee?: number, referralLevels?: number): {
|
|
85
|
+
issuerFee: number;
|
|
86
|
+
referralAmount: number;
|
|
87
|
+
totalRequired: number;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Build a new Identity object for registration
|
|
91
|
+
*/
|
|
92
|
+
export declare function createIdentityObject(params: {
|
|
93
|
+
name: string;
|
|
94
|
+
primaryAddresses: string[];
|
|
95
|
+
minSigs?: number;
|
|
96
|
+
revocationAuthority: string;
|
|
97
|
+
recoveryAuthority: string;
|
|
98
|
+
parentIAddress: string;
|
|
99
|
+
systemId: string;
|
|
100
|
+
}): Identity;
|
|
101
|
+
/**
|
|
102
|
+
* Build a CReserveTransfer fee output for sub-ID registration
|
|
103
|
+
*/
|
|
104
|
+
export declare function buildRegistrationFeeOutput(parentCurrencyId: string, feeAmount: number, systemId: string, _controlAddress: string): {
|
|
105
|
+
script: Buffer;
|
|
106
|
+
nativeValue: number;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Build a token change output (EVAL_RESERVE_OUTPUT)
|
|
110
|
+
*/
|
|
111
|
+
export declare function buildTokenChangeOutput(changeAddress: string, currencyChanges: Map<string, number>): {
|
|
112
|
+
script: Buffer;
|
|
113
|
+
nativeValue: number;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Build and sign a name commitment transaction (Step 1 of identity creation)
|
|
117
|
+
*/
|
|
118
|
+
export declare function buildAndSignCommitment(params: CreateCommitmentParams, network: Network): CreateCommitmentResult;
|
|
119
|
+
/**
|
|
120
|
+
* Build and sign an identity registration transaction (Step 2)
|
|
121
|
+
*/
|
|
122
|
+
export declare function buildAndSignRegistration(params: RegisterIdentityParams, network: Network): RegisterIdentityResult;
|
|
123
|
+
/**
|
|
124
|
+
* Build and sign an identity update transaction
|
|
125
|
+
*/
|
|
126
|
+
export declare function buildAndSignIdentityUpdate(params: UpdateIdentityParams, network: Network, operation?: 'update' | 'revoke' | 'recover' | 'lock' | 'unlock', lockUnlockParams?: {
|
|
127
|
+
unlockAfter?: number;
|
|
128
|
+
}): UpdateIdentityResult;
|
|
129
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAQL,QAAQ,EAQT,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,wBAAwB,EAEzB,MAAM,6BAA6B,CAAC;AAWrC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAMrD,OAAO,KAAK,EAEV,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EAQrB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EAAE,wBAAwB,EAAE,CAAC;AAapC;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GACX,MAAM,CAIR;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GACX,MAAM,CAMR;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,qBAAqB,EAA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