@argonprotocol/mainchain 1.0.18 → 1.1.0-rc.2
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 +110 -3
- package/lib/cli.cjs +3078 -0
- package/lib/cli.cjs.map +1 -0
- package/lib/cli.d.cts +1 -0
- package/lib/cli.d.ts +1 -0
- package/lib/cli.js +3073 -0
- package/lib/cli.js.map +1 -0
- package/lib/clis/index.cjs +3097 -0
- package/lib/clis/index.cjs.map +1 -0
- package/lib/clis/index.d.cts +26 -0
- package/lib/clis/index.d.ts +26 -0
- package/lib/clis/index.js +3077 -0
- package/lib/clis/index.js.map +1 -0
- package/lib/index.cjs +2402 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +11542 -0
- package/lib/index.d.ts +11542 -0
- package/lib/index.js +2333 -0
- package/lib/index.js.map +1 -0
- package/lib/test-utils/index.cjs +2933 -0
- package/lib/test-utils/index.cjs.map +1 -0
- package/lib/test-utils/index.d.cts +180 -0
- package/lib/test-utils/index.d.ts +180 -0
- package/lib/test-utils/index.js +2915 -0
- package/lib/test-utils/index.js.map +1 -0
- package/package.json +50 -45
- package/lib/cjs/WageProtector.d.ts +0 -37
- package/lib/cjs/WageProtector.js +0 -64
- package/lib/cjs/WageProtector.js.map +0 -1
- package/lib/cjs/__test__/WageProtector.test.d.ts +0 -1
- package/lib/cjs/__test__/WageProtector.test.js +0 -28
- package/lib/cjs/__test__/WageProtector.test.js.map +0 -1
- package/lib/cjs/examples/decodePkcs.d.ts +0 -1
- package/lib/cjs/examples/decodePkcs.js +0 -48
- package/lib/cjs/examples/decodePkcs.js.map +0 -1
- package/lib/cjs/examples/findSs58Formats.d.ts +0 -1
- package/lib/cjs/examples/findSs58Formats.js +0 -42
- package/lib/cjs/examples/findSs58Formats.js.map +0 -1
- package/lib/cjs/index.d.ts +0 -32
- package/lib/cjs/index.js +0 -60
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/interfaces/augment-api-consts.d.ts +0 -442
- package/lib/cjs/interfaces/augment-api-consts.js +0 -8
- package/lib/cjs/interfaces/augment-api-consts.js.map +0 -1
- package/lib/cjs/interfaces/augment-api-errors.d.ts +0 -919
- package/lib/cjs/interfaces/augment-api-errors.js +0 -8
- package/lib/cjs/interfaces/augment-api-errors.js.map +0 -1
- package/lib/cjs/interfaces/augment-api-events.d.ts +0 -1675
- package/lib/cjs/interfaces/augment-api-events.js +0 -8
- package/lib/cjs/interfaces/augment-api-events.js.map +0 -1
- package/lib/cjs/interfaces/augment-api-query.d.ts +0 -988
- package/lib/cjs/interfaces/augment-api-query.js +0 -8
- package/lib/cjs/interfaces/augment-api-query.js.map +0 -1
- package/lib/cjs/interfaces/augment-api-rpc.d.ts +0 -683
- package/lib/cjs/interfaces/augment-api-rpc.js +0 -8
- package/lib/cjs/interfaces/augment-api-rpc.js.map +0 -1
- package/lib/cjs/interfaces/augment-api-runtime.d.ts +0 -204
- package/lib/cjs/interfaces/augment-api-runtime.js +0 -8
- package/lib/cjs/interfaces/augment-api-runtime.js.map +0 -1
- package/lib/cjs/interfaces/augment-api-tx.d.ts +0 -1605
- package/lib/cjs/interfaces/augment-api-tx.js +0 -8
- package/lib/cjs/interfaces/augment-api-tx.js.map +0 -1
- package/lib/cjs/interfaces/augment-api.d.ts +0 -7
- package/lib/cjs/interfaces/augment-api.js +0 -12
- package/lib/cjs/interfaces/augment-api.js.map +0 -1
- package/lib/cjs/interfaces/augment-types.d.ts +0 -1316
- package/lib/cjs/interfaces/augment-types.js +0 -8
- package/lib/cjs/interfaces/augment-types.js.map +0 -1
- package/lib/cjs/interfaces/definitions.d.ts +0 -0
- package/lib/cjs/interfaces/definitions.js +0 -2
- package/lib/cjs/interfaces/definitions.js.map +0 -1
- package/lib/cjs/interfaces/lookup.d.ts +0 -2999
- package/lib/cjs/interfaces/lookup.js +0 -3262
- package/lib/cjs/interfaces/lookup.js.map +0 -1
- package/lib/cjs/interfaces/registry.d.ts +0 -250
- package/lib/cjs/interfaces/registry.js +0 -8
- package/lib/cjs/interfaces/registry.js.map +0 -1
- package/lib/cjs/interfaces/types-lookup.d.ts +0 -2974
- package/lib/cjs/interfaces/types-lookup.js +0 -8
- package/lib/cjs/interfaces/types-lookup.js.map +0 -1
- package/lib/cjs/package.json +0 -3
- package/lib/esm/WageProtector.d.ts +0 -37
- package/lib/esm/WageProtector.js +0 -60
- package/lib/esm/WageProtector.js.map +0 -1
- package/lib/esm/__test__/WageProtector.test.d.ts +0 -1
- package/lib/esm/__test__/WageProtector.test.js +0 -26
- package/lib/esm/__test__/WageProtector.test.js.map +0 -1
- package/lib/esm/examples/decodePkcs.d.ts +0 -1
- package/lib/esm/examples/decodePkcs.js +0 -45
- package/lib/esm/examples/decodePkcs.js.map +0 -1
- package/lib/esm/examples/findSs58Formats.d.ts +0 -1
- package/lib/esm/examples/findSs58Formats.js +0 -39
- package/lib/esm/examples/findSs58Formats.js.map +0 -1
- package/lib/esm/index.d.ts +0 -32
- package/lib/esm/index.js +0 -50
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/interfaces/augment-api-consts.d.ts +0 -442
- package/lib/esm/interfaces/augment-api-consts.js +0 -6
- package/lib/esm/interfaces/augment-api-consts.js.map +0 -1
- package/lib/esm/interfaces/augment-api-errors.d.ts +0 -919
- package/lib/esm/interfaces/augment-api-errors.js +0 -6
- package/lib/esm/interfaces/augment-api-errors.js.map +0 -1
- package/lib/esm/interfaces/augment-api-events.d.ts +0 -1675
- package/lib/esm/interfaces/augment-api-events.js +0 -6
- package/lib/esm/interfaces/augment-api-events.js.map +0 -1
- package/lib/esm/interfaces/augment-api-query.d.ts +0 -988
- package/lib/esm/interfaces/augment-api-query.js +0 -6
- package/lib/esm/interfaces/augment-api-query.js.map +0 -1
- package/lib/esm/interfaces/augment-api-rpc.d.ts +0 -683
- package/lib/esm/interfaces/augment-api-rpc.js +0 -6
- package/lib/esm/interfaces/augment-api-rpc.js.map +0 -1
- package/lib/esm/interfaces/augment-api-runtime.d.ts +0 -204
- package/lib/esm/interfaces/augment-api-runtime.js +0 -6
- package/lib/esm/interfaces/augment-api-runtime.js.map +0 -1
- package/lib/esm/interfaces/augment-api-tx.d.ts +0 -1605
- package/lib/esm/interfaces/augment-api-tx.js +0 -6
- package/lib/esm/interfaces/augment-api-tx.js.map +0 -1
- package/lib/esm/interfaces/augment-api.d.ts +0 -7
- package/lib/esm/interfaces/augment-api.js +0 -10
- package/lib/esm/interfaces/augment-api.js.map +0 -1
- package/lib/esm/interfaces/augment-types.d.ts +0 -1316
- package/lib/esm/interfaces/augment-types.js +0 -6
- package/lib/esm/interfaces/augment-types.js.map +0 -1
- package/lib/esm/interfaces/definitions.d.ts +0 -0
- package/lib/esm/interfaces/definitions.js +0 -2
- package/lib/esm/interfaces/definitions.js.map +0 -1
- package/lib/esm/interfaces/lookup.d.ts +0 -2999
- package/lib/esm/interfaces/lookup.js +0 -3260
- package/lib/esm/interfaces/lookup.js.map +0 -1
- package/lib/esm/interfaces/registry.d.ts +0 -250
- package/lib/esm/interfaces/registry.js +0 -6
- package/lib/esm/interfaces/registry.js.map +0 -1
- package/lib/esm/interfaces/types-lookup.d.ts +0 -2974
- package/lib/esm/interfaces/types-lookup.js +0 -6
- package/lib/esm/interfaces/types-lookup.js.map +0 -1
- package/lib/tsconfig-cjs.tsbuildinfo +0 -1
- package/lib/tsconfig-types.tsbuildinfo +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/types/WageProtector.d.ts +0 -37
- package/lib/types/__test__/WageProtector.test.d.ts +0 -1
- package/lib/types/examples/decodePkcs.d.ts +0 -1
- package/lib/types/examples/findSs58Formats.d.ts +0 -1
- package/lib/types/index.d.ts +0 -32
- package/lib/types/interfaces/augment-api-consts.d.ts +0 -442
- package/lib/types/interfaces/augment-api-errors.d.ts +0 -919
- package/lib/types/interfaces/augment-api-events.d.ts +0 -1675
- package/lib/types/interfaces/augment-api-query.d.ts +0 -988
- package/lib/types/interfaces/augment-api-rpc.d.ts +0 -683
- package/lib/types/interfaces/augment-api-runtime.d.ts +0 -204
- package/lib/types/interfaces/augment-api-tx.d.ts +0 -1605
- package/lib/types/interfaces/augment-api.d.ts +0 -7
- package/lib/types/interfaces/augment-types.d.ts +0 -1316
- package/lib/types/interfaces/definitions.d.ts +0 -0
- package/lib/types/interfaces/lookup.d.ts +0 -2999
- package/lib/types/interfaces/registry.d.ts +0 -250
- package/lib/types/interfaces/types-lookup.d.ts +0 -2974
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
|
3
|
-
/* eslint-disable */
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
// import type lookup before we augment - in some environments
|
|
6
|
-
// this is required to allow for ambient/previous definitions
|
|
7
|
-
require("@polkadot/types/lookup");
|
|
8
|
-
//# sourceMappingURL=types-lookup.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-lookup.js","sourceRoot":"","sources":["../../../src/interfaces/types-lookup.ts"],"names":[],"mappings":";AAAA,kEAAkE;AAClE,oBAAoB;;AAEpB,8DAA8D;AAC9D,6DAA6D;AAC7D,kCAAgC"}
|
package/lib/cjs/package.json
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ArgonClient } from './index';
|
|
2
|
-
export interface IArgonCpiSnapshot {
|
|
3
|
-
argonUsdTargetPrice: bigint;
|
|
4
|
-
argonUsdPrice: bigint;
|
|
5
|
-
finalizedBlock: Uint8Array;
|
|
6
|
-
tick: bigint;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* The WageProtector class is used to protect wages from inflation by using the current Argon Price Index to adjust the
|
|
10
|
-
* baseAmount to current conditions. This ensures that the wage is always stable and does not lose or gain value based on
|
|
11
|
-
* demand for the argon or fiat monetary supply changes.
|
|
12
|
-
*/
|
|
13
|
-
export declare class WageProtector {
|
|
14
|
-
latestCpi: IArgonCpiSnapshot;
|
|
15
|
-
constructor(latestCpi: IArgonCpiSnapshot);
|
|
16
|
-
/**
|
|
17
|
-
* Converts the base wage to the current wage using the latest CPI snapshot
|
|
18
|
-
*
|
|
19
|
-
* @param baseWage The base wage to convert
|
|
20
|
-
* @returns The protected wage
|
|
21
|
-
*/
|
|
22
|
-
getProtectedWage(baseWage: bigint): bigint;
|
|
23
|
-
/**
|
|
24
|
-
* Subscribes to the current CPI and calls the callback function whenever the CPI changes
|
|
25
|
-
* @param client The ArgonClient to use
|
|
26
|
-
* @param callback The callback function to call when the CPI changes
|
|
27
|
-
* @returns An object with an unsubscribe function that can be called to stop the subscription
|
|
28
|
-
*/
|
|
29
|
-
static subscribe(client: ArgonClient, callback: (cpi: WageProtector) => void): Promise<{
|
|
30
|
-
unsubscribe: () => void;
|
|
31
|
-
}>;
|
|
32
|
-
/**
|
|
33
|
-
* Creates a new WageProtector instance by subscribing to the current CPI and waiting for the first value
|
|
34
|
-
* @param client The ArgonClient to use
|
|
35
|
-
*/
|
|
36
|
-
static create(client: ArgonClient): Promise<WageProtector>;
|
|
37
|
-
}
|
package/lib/esm/WageProtector.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The WageProtector class is used to protect wages from inflation by using the current Argon Price Index to adjust the
|
|
3
|
-
* baseAmount to current conditions. This ensures that the wage is always stable and does not lose or gain value based on
|
|
4
|
-
* demand for the argon or fiat monetary supply changes.
|
|
5
|
-
*/
|
|
6
|
-
export class WageProtector {
|
|
7
|
-
latestCpi;
|
|
8
|
-
constructor(latestCpi) {
|
|
9
|
-
this.latestCpi = latestCpi;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Converts the base wage to the current wage using the latest CPI snapshot
|
|
13
|
-
*
|
|
14
|
-
* @param baseWage The base wage to convert
|
|
15
|
-
* @returns The protected wage
|
|
16
|
-
*/
|
|
17
|
-
getProtectedWage(baseWage) {
|
|
18
|
-
return ((baseWage * this.latestCpi.argonUsdTargetPrice) /
|
|
19
|
-
this.latestCpi.argonUsdPrice);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Subscribes to the current CPI and calls the callback function whenever the CPI changes
|
|
23
|
-
* @param client The ArgonClient to use
|
|
24
|
-
* @param callback The callback function to call when the CPI changes
|
|
25
|
-
* @returns An object with an unsubscribe function that can be called to stop the subscription
|
|
26
|
-
*/
|
|
27
|
-
static async subscribe(client, callback) {
|
|
28
|
-
const unsubscribe = await client.query.priceIndex.current(async (cpi) => {
|
|
29
|
-
if (cpi.isNone) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const finalizedBlock = await client.rpc.chain.getFinalizedHead();
|
|
33
|
-
callback(new WageProtector({
|
|
34
|
-
argonUsdTargetPrice: cpi.value.argonUsdTargetPrice.toBigInt(),
|
|
35
|
-
argonUsdPrice: cpi.value.argonUsdPrice.toBigInt(),
|
|
36
|
-
finalizedBlock: finalizedBlock.toU8a(),
|
|
37
|
-
tick: cpi.value.tick.toBigInt(),
|
|
38
|
-
}));
|
|
39
|
-
});
|
|
40
|
-
return { unsubscribe };
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Creates a new WageProtector instance by subscribing to the current CPI and waiting for the first value
|
|
44
|
-
* @param client The ArgonClient to use
|
|
45
|
-
*/
|
|
46
|
-
static async create(client) {
|
|
47
|
-
return new Promise(async (resolve, reject) => {
|
|
48
|
-
try {
|
|
49
|
-
const { unsubscribe } = await WageProtector.subscribe(client, x => {
|
|
50
|
-
resolve(x);
|
|
51
|
-
unsubscribe();
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
catch (e) {
|
|
55
|
-
reject(e);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=WageProtector.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WageProtector.js","sourceRoot":"","sources":["../../src/WageProtector.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Aa,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE;oBAChE,OAAO,CAAC,CAAC,CAAC,CAAC;oBACX,WAAW,EAAE,CAAC;gBAChB,CAAC,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,CAAC,CAAC,CAAC,CAAC;YACZ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { WageProtector, waitForLoad } from '../index';
|
|
2
|
-
it('adjusts the price of a wage for inflation', async () => {
|
|
3
|
-
await waitForLoad();
|
|
4
|
-
const wageProtector = new WageProtector({
|
|
5
|
-
argonUsdTargetPrice: 1010000000000000000n,
|
|
6
|
-
argonUsdPrice: 1000000000000000000n,
|
|
7
|
-
tick: 1n,
|
|
8
|
-
finalizedBlock: Buffer.from([]),
|
|
9
|
-
});
|
|
10
|
-
// if price of argon is below the target price, we have argon inflation, which means we need to increase the wage
|
|
11
|
-
// to keep the value of the wage stable. It will take 1.01 argon to buy the same amount of goods.
|
|
12
|
-
expect(wageProtector.getProtectedWage(2500n)).toBe(BigInt(2500 * 1.01));
|
|
13
|
-
});
|
|
14
|
-
it('adjusts the price of a wage for deflation', async () => {
|
|
15
|
-
await waitForLoad();
|
|
16
|
-
const wageProtector = new WageProtector({
|
|
17
|
-
argonUsdTargetPrice: 1000000000000000000n,
|
|
18
|
-
argonUsdPrice: 1010000000000000000n,
|
|
19
|
-
tick: 1n,
|
|
20
|
-
finalizedBlock: Buffer.from([]),
|
|
21
|
-
});
|
|
22
|
-
// if price of argon is below the target price, we have argon deflation, which means we need to decrease the wages to
|
|
23
|
-
// match the argon's market value.
|
|
24
|
-
expect(wageProtector.getProtectedWage(2500n)).toBe(BigInt(2500 * 0.99));
|
|
25
|
-
});
|
|
26
|
-
//# sourceMappingURL=WageProtector.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WageProtector.test.js","sourceRoot":"","sources":["../../../src/__test__/WageProtector.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEtD,EAAE,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;IACzD,MAAM,WAAW,EAAE,CAAC;IACpB,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC;QACtC,mBAAmB,EAAE,oBAA0B;QAC/C,aAAa,EAAE,oBAA0B;QACzC,IAAI,EAAE,EAAE;QACR,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;KAChC,CAAC,CAAC;IAEH,iHAAiH;IACjH,iGAAiG;IACjG,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;AAC1E,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;IACzD,MAAM,WAAW,EAAE,CAAC;IACpB,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC;QACtC,mBAAmB,EAAE,oBAA0B;QAC/C,aAAa,EAAE,oBAA0B;QACzC,IAAI,EAAE,EAAE;QACR,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;KAChC,CAAC,CAAC;IAEH,qHAAqH;IACrH,kCAAkC;IAClC,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;AAC1E,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Keyring, waitForLoad } from '../index';
|
|
2
|
-
import { readFileSync } from 'fs';
|
|
3
|
-
import * as readline from 'readline';
|
|
4
|
-
import * as util from 'node:util';
|
|
5
|
-
import { decodePair } from '@polkadot/keyring/pair/decode';
|
|
6
|
-
import * as utilCrypto from '@polkadot/util-crypto';
|
|
7
|
-
import { base64Decode } from '@polkadot/util-crypto';
|
|
8
|
-
const jsonFile = process.argv[2];
|
|
9
|
-
if (!jsonFile) {
|
|
10
|
-
console.error('Usage: node decodePkcs.js <jsonFile>');
|
|
11
|
-
process.exit(1);
|
|
12
|
-
}
|
|
13
|
-
const json = JSON.parse(readFileSync(jsonFile, 'utf8'));
|
|
14
|
-
(async () => {
|
|
15
|
-
await waitForLoad();
|
|
16
|
-
const keyring = new Keyring();
|
|
17
|
-
const account = keyring.addFromJson(json);
|
|
18
|
-
console.log(json);
|
|
19
|
-
// prompt for password
|
|
20
|
-
const rl = readline.createInterface({
|
|
21
|
-
input: process.stdin,
|
|
22
|
-
output: process.stdout,
|
|
23
|
-
});
|
|
24
|
-
rl.question('Enter password: ', async (password) => {
|
|
25
|
-
account.decodePkcs8(password);
|
|
26
|
-
let secretKey = new Uint8Array();
|
|
27
|
-
const decoded = decodePair(password, base64Decode(json.encoded), json.encoding.type);
|
|
28
|
-
if (decoded.secretKey.length === 64) {
|
|
29
|
-
secretKey = decoded.secretKey;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
const type = json.encoding.content[1];
|
|
33
|
-
const pair = {
|
|
34
|
-
ecdsa: utilCrypto.secp256k1PairFromSeed,
|
|
35
|
-
ed25519: utilCrypto.ed25519PairFromSeed,
|
|
36
|
-
sr25519: utilCrypto.sr25519PairFromSeed,
|
|
37
|
-
}[type](decoded.secretKey);
|
|
38
|
-
secretKey = pair.secretKey;
|
|
39
|
-
}
|
|
40
|
-
console.log('SecretKey: 0x%s', Buffer.from(secretKey).toString('hex'));
|
|
41
|
-
console.log(util.inspect(account, true, null, true));
|
|
42
|
-
rl.close();
|
|
43
|
-
});
|
|
44
|
-
})();
|
|
45
|
-
//# sourceMappingURL=decodePkcs.js.map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C,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC9B,IAAI,SAAS,GAAG,IAAI,UAAU,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,UAAU,CACxB,QAAQ,EACR,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,EAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CACnB,CAAC;QACF,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACpC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAoC,CAAC;YACzE,MAAM,IAAI,GAAG;gBACX,KAAK,EAAE,UAAU,CAAC,qBAAqB;gBACvC,OAAO,EAAE,UAAU,CAAC,mBAAmB;gBACvC,OAAO,EAAE,UAAU,CAAC,mBAAmB;aACxC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAC3B,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAC7B,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QAEvE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QACrD,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Keyring } from '@polkadot/keyring';
|
|
2
|
-
import { encodeAddress } from '@polkadot/util-crypto';
|
|
3
|
-
import Registry from '@substrate/ss58-registry';
|
|
4
|
-
const keyring = new Keyring();
|
|
5
|
-
const address1 = keyring.createFromUri('//Alice').publicKey;
|
|
6
|
-
const address2 = keyring.createFromUri('//Bob').publicKey;
|
|
7
|
-
const maxSS58AddressPrefixesCount = 16383;
|
|
8
|
-
const reservedSS58Formats = new Set();
|
|
9
|
-
for (const entry of Registry) {
|
|
10
|
-
reservedSS58Formats.add(entry.prefix);
|
|
11
|
-
}
|
|
12
|
-
// Find SS58 Address Prefixes that generate an SS58 Address Format that starts with the letter 'e'
|
|
13
|
-
// Optionally add a filter to this function if you only want to return those not listed in the
|
|
14
|
-
// the SS58 Registry https://github.com/paritytech/ss58-registry/blob/main/ss58-registry.json
|
|
15
|
-
function findSS58AddressPrefixes() {
|
|
16
|
-
const foundSS58AddressPrefixes = [];
|
|
17
|
-
//
|
|
18
|
-
for (let prefix = 0; prefix <= maxSS58AddressPrefixesCount; prefix++) {
|
|
19
|
-
if (!reservedSS58Formats.has(prefix)) {
|
|
20
|
-
const ss58Address1 = encodeAddress(address1, prefix);
|
|
21
|
-
const ss58Address2 = encodeAddress(address2, prefix);
|
|
22
|
-
const lower1 = ss58Address1.toLowerCase().slice(0, 2);
|
|
23
|
-
const lower2 = ss58Address2.toLowerCase().slice(0, 2);
|
|
24
|
-
if (lower1 === process.argv[2] && lower2 === process.argv[2]) {
|
|
25
|
-
foundSS58AddressPrefixes.push([
|
|
26
|
-
prefix,
|
|
27
|
-
ss58Address1.slice(0),
|
|
28
|
-
ss58Address2.slice(0, 2),
|
|
29
|
-
ss58Address1,
|
|
30
|
-
]);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return foundSS58AddressPrefixes;
|
|
35
|
-
}
|
|
36
|
-
const foundSS58AddressPrefixes = findSS58AddressPrefixes();
|
|
37
|
-
console.log('count: ', foundSS58AddressPrefixes.length);
|
|
38
|
-
console.log('foundSS58AddressPrefixes: ', foundSS58AddressPrefixes);
|
|
39
|
-
//# sourceMappingURL=findSs58Formats.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1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C,EAAE,CAAC,CAAC,CAAC;YACtD,IAAI,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC7D,wBAAwB,CAAC,IAAI,CAAC;oBAC5B,MAAM;oBACN,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;oBACrB,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;oBACxB,YAAY;iBACb,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,wBAAwB,CAAC;AAClC,CAAC;AAED,MAAM,wBAAwB,GAAG,uBAAuB,EAAE,CAAC;AAC3D,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,wBAAwB,CAAC,MAAM,CAAC,CAAC;AACxD,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,wBAAwB,CAAC,CAAC"}
|
package/lib/esm/index.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import './interfaces/augment-api.js';
|
|
2
|
-
import './interfaces/augment-types.js';
|
|
3
|
-
import './interfaces/types-lookup.js';
|
|
4
|
-
import { KeyringPair, KeyringPair$Json } from '@polkadot/keyring/types';
|
|
5
|
-
import { ApiPromise, Keyring } from '@polkadot/api';
|
|
6
|
-
import { decodeAddress, mnemonicGenerate } from '@polkadot/util-crypto';
|
|
7
|
-
import { EventRecord } from '@polkadot/types/interfaces/system';
|
|
8
|
-
import { InterfaceTypes } from '@polkadot/types/types/registry';
|
|
9
|
-
import { KeypairType } from '@polkadot/util-crypto/types';
|
|
10
|
-
export { WageProtector } from './WageProtector';
|
|
11
|
-
export { Keyring, KeyringPair, KeyringPair$Json, KeypairType, mnemonicGenerate, decodeAddress, };
|
|
12
|
-
export * from '@polkadot/types';
|
|
13
|
-
export * from '@polkadot/types/lookup';
|
|
14
|
-
export { InterfaceTypes as interfaces };
|
|
15
|
-
export type ArgonClient = ApiPromise;
|
|
16
|
-
/**
|
|
17
|
-
* Wait for the crypto library to be ready (requires wasm, which needs async loading in commonjs)
|
|
18
|
-
*/
|
|
19
|
-
export declare function waitForLoad(): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Get a client for the given host
|
|
22
|
-
* @param host The host to connect to
|
|
23
|
-
* @returns The client
|
|
24
|
-
*/
|
|
25
|
-
export declare function getClient(host: string): Promise<ArgonClient>;
|
|
26
|
-
/**
|
|
27
|
-
* Check for an extrinsic success event in the given events. Helpful to validate the result of an extrinsic inclusion in a block (it will be included even if it fails)
|
|
28
|
-
* @param events The events to check
|
|
29
|
-
* @param client The client to use
|
|
30
|
-
* @returns A promise that resolves if the extrinsic was successful, and rejects if it failed
|
|
31
|
-
*/
|
|
32
|
-
export declare function checkForExtrinsicSuccess(events: EventRecord[], client: ArgonClient): Promise<void>;
|
package/lib/esm/index.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import './interfaces/augment-api.js';
|
|
2
|
-
import './interfaces/augment-types.js';
|
|
3
|
-
import './interfaces/types-lookup.js';
|
|
4
|
-
import { ApiPromise, Keyring, WsProvider } from '@polkadot/api';
|
|
5
|
-
import { cryptoWaitReady, decodeAddress, mnemonicGenerate, } from '@polkadot/util-crypto';
|
|
6
|
-
export { WageProtector } from './WageProtector';
|
|
7
|
-
export { Keyring, mnemonicGenerate, decodeAddress, };
|
|
8
|
-
export * from '@polkadot/types';
|
|
9
|
-
export * from '@polkadot/types/lookup';
|
|
10
|
-
/**
|
|
11
|
-
* Wait for the crypto library to be ready (requires wasm, which needs async loading in commonjs)
|
|
12
|
-
*/
|
|
13
|
-
export async function waitForLoad() {
|
|
14
|
-
await cryptoWaitReady();
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Get a client for the given host
|
|
18
|
-
* @param host The host to connect to
|
|
19
|
-
* @returns The client
|
|
20
|
-
*/
|
|
21
|
-
export async function getClient(host) {
|
|
22
|
-
const provider = new WsProvider(host);
|
|
23
|
-
return await ApiPromise.create({ provider, noInitWarn: true });
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Check for an extrinsic success event in the given events. Helpful to validate the result of an extrinsic inclusion in a block (it will be included even if it fails)
|
|
27
|
-
* @param events The events to check
|
|
28
|
-
* @param client The client to use
|
|
29
|
-
* @returns A promise that resolves if the extrinsic was successful, and rejects if it failed
|
|
30
|
-
*/
|
|
31
|
-
export function checkForExtrinsicSuccess(events, client) {
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
for (const { event } of events) {
|
|
34
|
-
if (client.events.system.ExtrinsicSuccess.is(event)) {
|
|
35
|
-
resolve();
|
|
36
|
-
}
|
|
37
|
-
else if (client.events.system.ExtrinsicFailed.is(event)) {
|
|
38
|
-
// extract the data for this event
|
|
39
|
-
const [dispatchError] = event.data;
|
|
40
|
-
let errorInfo = dispatchError.toString();
|
|
41
|
-
if (dispatchError.isModule) {
|
|
42
|
-
const decoded = client.registry.findMetaError(dispatchError.asModule);
|
|
43
|
-
errorInfo = `${decoded.section}.${decoded.name}`;
|
|
44
|
-
}
|
|
45
|
-
reject(new Error(`${event.section}.${event.method}:: ExtrinsicFailed:: ${errorInfo}`));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,6BAA6B,CAAC;AACrC,OAAO,+BAA+B,CAAC;AACvC,OAAO,8BAA8B,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EACL,eAAe,EACf,aAAa,EACb,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAK/B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,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