@palliora.org/chainsdk 0.3.1 → 0.3.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/dist/index.cjs CHANGED
@@ -1,4 +1,15 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/account/account.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
2
+ var __typeError = (msg) => {
3
+ throw TypeError(msg);
4
+ };
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
8
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
+
12
+ // src/account/account.ts
2
13
  var _wasmcrypto = require('@polkadot/wasm-crypto'); var wasmCrypto = _interopRequireWildcard(_wasmcrypto);
3
14
 
4
15
  // src/account/types.ts
@@ -21,7 +32,9 @@ var AccountSourceType = /* @__PURE__ */ ((AccountSourceType2) => {
21
32
  var _api2 = require('@polkadot/api');
22
33
  var _util = require('@polkadot/util'); _createStarExport(_util);
23
34
  var _utilcrypto = require('@polkadot/util-crypto'); var utilCrypto = _interopRequireWildcard(_utilcrypto);
24
- async function createAccount(input, type, name = "default", cryptoType = "sr25519" /* SR25519 */) {
35
+ var _viem = require('viem');
36
+ var _poseidonlite = require('poseidon-lite');
37
+ async function createAccount(input, type, name = "default", cryptoType = "sr25519" /* SR25519 */, signedMsg = "sign") {
25
38
  await _wasmcrypto.waitReady.call(void 0, );
26
39
  const keyring2 = new (0, _api2.Keyring)({ type: cryptoType });
27
40
  switch (type) {
@@ -48,6 +61,12 @@ async function createAccount(input, type, name = "default", cryptoType = "sr2551
48
61
  cryptoType
49
62
  );
50
63
  return account;
64
+ case "derived" /* DERIVED */:
65
+ if (!input.startsWith("0x")) {
66
+ throw new Error("Invalid signature format for derived account. Expected hex string starting with 0x.");
67
+ }
68
+ const signKeyBytes = sigToSeed(signedMsg, input);
69
+ return createAccount(signKeyBytes, "seed" /* SEED */, name, cryptoType);
51
70
  default:
52
71
  throw new Error("Invalid input type");
53
72
  }
@@ -83,6 +102,15 @@ function pairFromPrivateKeyHex(privateKeyHex, cryptoType) {
83
102
  throw new Error(`Unsupported crypto type: ${cryptoType}`);
84
103
  }
85
104
  }
105
+ function sigToSeed(msg, sign) {
106
+ const seed = BigInt(_viem.keccak256.call(void 0, sign));
107
+ const encoder = new TextEncoder();
108
+ const signBytes = encoder.encode(msg);
109
+ const signHex = Array.from(signBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
110
+ const SALT_SIGN = _poseidonlite.poseidon1.call(void 0, [BigInt(`0x${signHex}`)]);
111
+ const signKeyBytes = _poseidonlite.poseidon2.call(void 0, [seed.toString(), SALT_SIGN]).toString(16).slice(0, 64);
112
+ return signKeyBytes;
113
+ }
86
114
 
87
115
  // src/chain/spec.ts
88
116
  var API_RPC = {
@@ -822,7 +850,7 @@ var debugLog = (message, ...optionalParams) => {
822
850
  };
823
851
 
824
852
  // src/utils/token.ts
825
- var _viem = require('viem');
853
+
826
854
  var PALI_SYMBOL = "PALI";
827
855
  var PALI_DECIMALS = 18;
828
856
  var tokenCache = null;
@@ -2116,6 +2144,465 @@ async function setWorker(account) {
2116
2144
 
2117
2145
 
2118
2146
 
2147
+ // node_modules/.pnpm/@polkadot+keyring@13.5.9_@polkadot+util-crypto@13.5.9_@polkadot+util@13.5.9__@polkadot+util@13.5.9/node_modules/@polkadot/keyring/bundle.js
2148
+
2149
+
2150
+ // node_modules/.pnpm/@polkadot+keyring@13.5.9_@polkadot+util-crypto@13.5.9_@polkadot+util@13.5.9__@polkadot+util@13.5.9/node_modules/@polkadot/keyring/keyring.js
2151
+
2152
+
2153
+
2154
+ // node_modules/.pnpm/@polkadot+keyring@13.5.9_@polkadot+util-crypto@13.5.9_@polkadot+util@13.5.9__@polkadot+util@13.5.9/node_modules/@polkadot/keyring/pair/index.js
2155
+
2156
+
2157
+
2158
+ // node_modules/.pnpm/@polkadot+keyring@13.5.9_@polkadot+util-crypto@13.5.9_@polkadot+util@13.5.9__@polkadot+util@13.5.9/node_modules/@polkadot/keyring/pair/decode.js
2159
+
2160
+
2161
+
2162
+ // node_modules/.pnpm/@polkadot+keyring@13.5.9_@polkadot+util-crypto@13.5.9_@polkadot+util@13.5.9__@polkadot+util@13.5.9/node_modules/@polkadot/keyring/pair/defaults.js
2163
+ var PAIR_DIV = new Uint8Array([161, 35, 3, 33, 0]);
2164
+ var PAIR_HDR = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
2165
+ var PUB_LENGTH = 32;
2166
+ var SEC_LENGTH = 64;
2167
+ var SEED_LENGTH = 32;
2168
+
2169
+ // node_modules/.pnpm/@polkadot+keyring@13.5.9_@polkadot+util-crypto@13.5.9_@polkadot+util@13.5.9__@polkadot+util@13.5.9/node_modules/@polkadot/keyring/pair/decode.js
2170
+ var SEED_OFFSET = PAIR_HDR.length;
2171
+ function decodePair(passphrase, encrypted, _encType) {
2172
+ const encType = Array.isArray(_encType) || _encType === void 0 ? _encType : [_encType];
2173
+ const decrypted = _utilcrypto.jsonDecryptData.call(void 0, encrypted, passphrase, encType);
2174
+ const header = decrypted.subarray(0, PAIR_HDR.length);
2175
+ if (!_util.u8aEq.call(void 0, header, PAIR_HDR)) {
2176
+ throw new Error("Invalid encoding header found in body");
2177
+ }
2178
+ let secretKey = decrypted.subarray(SEED_OFFSET, SEED_OFFSET + SEC_LENGTH);
2179
+ let divOffset = SEED_OFFSET + SEC_LENGTH;
2180
+ let divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
2181
+ if (!_util.u8aEq.call(void 0, divider, PAIR_DIV)) {
2182
+ divOffset = SEED_OFFSET + SEED_LENGTH;
2183
+ secretKey = decrypted.subarray(SEED_OFFSET, divOffset);
2184
+ divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
2185
+ if (!_util.u8aEq.call(void 0, divider, PAIR_DIV)) {
2186
+ throw new Error("Invalid encoding divider found in body");
2187
+ }
2188
+ }
2189
+ const pubOffset = divOffset + PAIR_DIV.length;
2190
+ const publicKey = decrypted.subarray(pubOffset, pubOffset + PUB_LENGTH);
2191
+ return {
2192
+ publicKey,
2193
+ secretKey
2194
+ };
2195
+ }
2196
+
2197
+ // node_modules/.pnpm/@polkadot+keyring@13.5.9_@polkadot+util-crypto@13.5.9_@polkadot+util@13.5.9__@polkadot+util@13.5.9/node_modules/@polkadot/keyring/pair/encode.js
2198
+
2199
+
2200
+ function encodePair({ publicKey, secretKey }, passphrase) {
2201
+ if (!secretKey) {
2202
+ throw new Error("Expected a valid secretKey to be passed to encode");
2203
+ }
2204
+ const encoded = _util.u8aConcat.call(void 0, PAIR_HDR, secretKey, PAIR_DIV, publicKey);
2205
+ if (!passphrase) {
2206
+ return encoded;
2207
+ }
2208
+ const { params, password, salt } = _utilcrypto.scryptEncode.call(void 0, passphrase);
2209
+ const { encrypted, nonce } = _utilcrypto.naclEncrypt.call(void 0, encoded, password.subarray(0, 32));
2210
+ return _util.u8aConcat.call(void 0, _utilcrypto.scryptToU8a.call(void 0, salt, params), nonce, encrypted);
2211
+ }
2212
+
2213
+ // node_modules/.pnpm/@polkadot+keyring@13.5.9_@polkadot+util-crypto@13.5.9_@polkadot+util@13.5.9__@polkadot+util@13.5.9/node_modules/@polkadot/keyring/pair/toJson.js
2214
+
2215
+
2216
+ function pairToJson(type, { address, meta }, encoded, isEncrypted) {
2217
+ return _util.objectSpread.call(void 0, _utilcrypto.jsonEncryptFormat.call(void 0, encoded, ["pkcs8", type], isEncrypted), {
2218
+ address,
2219
+ meta
2220
+ });
2221
+ }
2222
+
2223
+ // node_modules/.pnpm/@polkadot+keyring@13.5.9_@polkadot+util-crypto@13.5.9_@polkadot+util@13.5.9__@polkadot+util@13.5.9/node_modules/@polkadot/keyring/pair/index.js
2224
+ var SIG_TYPE_NONE = new Uint8Array();
2225
+ var TYPE_FROM_SEED = {
2226
+ ecdsa: _utilcrypto.secp256k1PairFromSeed,
2227
+ ed25519: _utilcrypto.ed25519PairFromSeed,
2228
+ ethereum: _utilcrypto.secp256k1PairFromSeed,
2229
+ sr25519: _utilcrypto.sr25519PairFromSeed
2230
+ };
2231
+ var TYPE_PREFIX = {
2232
+ ecdsa: new Uint8Array([2]),
2233
+ ed25519: new Uint8Array([0]),
2234
+ ethereum: new Uint8Array([2]),
2235
+ sr25519: new Uint8Array([1])
2236
+ };
2237
+ var TYPE_SIGNATURE = {
2238
+ ecdsa: (m, p) => _utilcrypto.secp256k1Sign.call(void 0, m, p, "blake2"),
2239
+ ed25519: _utilcrypto.ed25519Sign,
2240
+ ethereum: (m, p) => _utilcrypto.secp256k1Sign.call(void 0, m, p, "keccak"),
2241
+ sr25519: _utilcrypto.sr25519Sign
2242
+ };
2243
+ var TYPE_ADDRESS = {
2244
+ ecdsa: (p) => p.length > 32 ? _utilcrypto.blake2AsU8a.call(void 0, p) : p,
2245
+ ed25519: (p) => p,
2246
+ ethereum: (p) => p.length === 20 ? p : _utilcrypto.keccakAsU8a.call(void 0, _utilcrypto.secp256k1Expand.call(void 0, p)),
2247
+ sr25519: (p) => p
2248
+ };
2249
+ function isLocked(secretKey) {
2250
+ return !secretKey || _util.u8aEmpty.call(void 0, secretKey);
2251
+ }
2252
+ function vrfHash(proof, context, extra) {
2253
+ return _utilcrypto.blake2AsU8a.call(void 0, _util.u8aConcat.call(void 0, context || "", extra || "", proof));
2254
+ }
2255
+ function createPair({ toSS58, type }, { publicKey, secretKey }, meta = {}, encoded = null, encTypes) {
2256
+ const decodePkcs8 = (passphrase, userEncoded) => {
2257
+ const decoded = decodePair(passphrase, userEncoded || encoded, encTypes);
2258
+ if (decoded.secretKey.length === 64) {
2259
+ publicKey = decoded.publicKey;
2260
+ secretKey = decoded.secretKey;
2261
+ } else {
2262
+ const pair = TYPE_FROM_SEED[type](decoded.secretKey);
2263
+ publicKey = pair.publicKey;
2264
+ secretKey = pair.secretKey;
2265
+ }
2266
+ };
2267
+ const recode = (passphrase) => {
2268
+ isLocked(secretKey) && encoded && decodePkcs8(passphrase, encoded);
2269
+ encoded = encodePair({ publicKey, secretKey }, passphrase);
2270
+ encTypes = void 0;
2271
+ return encoded;
2272
+ };
2273
+ const encodeAddress3 = () => {
2274
+ const raw = TYPE_ADDRESS[type](publicKey);
2275
+ return type === "ethereum" ? _utilcrypto.ethereumEncode.call(void 0, raw) : toSS58(raw);
2276
+ };
2277
+ return {
2278
+ get address() {
2279
+ return encodeAddress3();
2280
+ },
2281
+ get addressRaw() {
2282
+ const raw = TYPE_ADDRESS[type](publicKey);
2283
+ return type === "ethereum" ? raw.slice(-20) : raw;
2284
+ },
2285
+ get isLocked() {
2286
+ return isLocked(secretKey);
2287
+ },
2288
+ get meta() {
2289
+ return meta;
2290
+ },
2291
+ get publicKey() {
2292
+ return publicKey;
2293
+ },
2294
+ get type() {
2295
+ return type;
2296
+ },
2297
+ // eslint-disable-next-line sort-keys
2298
+ decodePkcs8,
2299
+ derive: (suri, meta2) => {
2300
+ if (type === "ethereum") {
2301
+ throw new Error("Unable to derive on this keypair");
2302
+ } else if (isLocked(secretKey)) {
2303
+ throw new Error("Cannot derive on a locked keypair");
2304
+ }
2305
+ const { path: path2 } = _utilcrypto.keyExtractPath.call(void 0, suri);
2306
+ const derived = _utilcrypto.keyFromPath.call(void 0, { publicKey, secretKey }, path2, type);
2307
+ return createPair({ toSS58, type }, derived, meta2, null);
2308
+ },
2309
+ encodePkcs8: (passphrase) => {
2310
+ return recode(passphrase);
2311
+ },
2312
+ lock: () => {
2313
+ secretKey = new Uint8Array();
2314
+ },
2315
+ setMeta: (additional) => {
2316
+ meta = _util.objectSpread.call(void 0, {}, meta, additional);
2317
+ },
2318
+ sign: (message, options = {}) => {
2319
+ if (isLocked(secretKey)) {
2320
+ throw new Error("Cannot sign with a locked key pair");
2321
+ }
2322
+ return _util.u8aConcat.call(void 0, options.withType ? TYPE_PREFIX[type] : SIG_TYPE_NONE, TYPE_SIGNATURE[type](_util.u8aToU8a.call(void 0, message), { publicKey, secretKey }));
2323
+ },
2324
+ toJson: (passphrase) => {
2325
+ const address = ["ecdsa", "ethereum"].includes(type) ? publicKey.length === 20 ? _util.u8aToHex.call(void 0, publicKey) : _util.u8aToHex.call(void 0, _utilcrypto.secp256k1Compress.call(void 0, publicKey)) : encodeAddress3();
2326
+ return pairToJson(type, { address, meta }, recode(passphrase), !!passphrase);
2327
+ },
2328
+ unlock: (passphrase) => {
2329
+ return decodePkcs8(passphrase);
2330
+ },
2331
+ verify: (message, signature, signerPublic) => {
2332
+ return _utilcrypto.signatureVerify.call(void 0, message, signature, TYPE_ADDRESS[type](_util.u8aToU8a.call(void 0, signerPublic))).isValid;
2333
+ },
2334
+ vrfSign: (message, context, extra) => {
2335
+ if (isLocked(secretKey)) {
2336
+ throw new Error("Cannot sign with a locked key pair");
2337
+ }
2338
+ if (type === "sr25519") {
2339
+ return _utilcrypto.sr25519VrfSign.call(void 0, message, { secretKey }, context, extra);
2340
+ }
2341
+ const proof = TYPE_SIGNATURE[type](_util.u8aToU8a.call(void 0, message), { publicKey, secretKey });
2342
+ return _util.u8aConcat.call(void 0, vrfHash(proof, context, extra), proof);
2343
+ },
2344
+ vrfVerify: (message, vrfResult, signerPublic, context, extra) => {
2345
+ if (type === "sr25519") {
2346
+ return _utilcrypto.sr25519VrfVerify.call(void 0, message, vrfResult, publicKey, context, extra);
2347
+ }
2348
+ const result = _utilcrypto.signatureVerify.call(void 0, message, _util.u8aConcat.call(void 0, TYPE_PREFIX[type], vrfResult.subarray(32)), TYPE_ADDRESS[type](_util.u8aToU8a.call(void 0, signerPublic)));
2349
+ return result.isValid && _util.u8aEq.call(void 0, vrfResult.subarray(0, 32), vrfHash(vrfResult.subarray(32), context, extra));
2350
+ }
2351
+ };
2352
+ }
2353
+
2354
+ // node_modules/.pnpm/@polkadot+keyring@13.5.9_@polkadot+util-crypto@13.5.9_@polkadot+util@13.5.9__@polkadot+util@13.5.9/node_modules/@polkadot/keyring/defaults.js
2355
+ var DEV_PHRASE = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
2356
+
2357
+ // node_modules/.pnpm/@polkadot+keyring@13.5.9_@polkadot+util-crypto@13.5.9_@polkadot+util@13.5.9__@polkadot+util@13.5.9/node_modules/@polkadot/keyring/pairs.js
2358
+
2359
+
2360
+ var _map;
2361
+ var Pairs = class {
2362
+ constructor() {
2363
+ __privateAdd(this, _map, {});
2364
+ }
2365
+ add(pair) {
2366
+ __privateGet(this, _map)[_utilcrypto.decodeAddress.call(void 0, pair.address).toString()] = pair;
2367
+ return pair;
2368
+ }
2369
+ all() {
2370
+ return Object.values(__privateGet(this, _map));
2371
+ }
2372
+ get(address) {
2373
+ const pair = __privateGet(this, _map)[_utilcrypto.decodeAddress.call(void 0, address).toString()];
2374
+ if (!pair) {
2375
+ throw new Error(`Unable to retrieve keypair '${_util.isU8a.call(void 0, address) || _util.isHex.call(void 0, address) ? _util.u8aToHex.call(void 0, _util.u8aToU8a.call(void 0, address)) : address}'`);
2376
+ }
2377
+ return pair;
2378
+ }
2379
+ remove(address) {
2380
+ delete __privateGet(this, _map)[_utilcrypto.decodeAddress.call(void 0, address).toString()];
2381
+ }
2382
+ };
2383
+ _map = new WeakMap();
2384
+
2385
+ // node_modules/.pnpm/@polkadot+keyring@13.5.9_@polkadot+util-crypto@13.5.9_@polkadot+util@13.5.9__@polkadot+util@13.5.9/node_modules/@polkadot/keyring/keyring.js
2386
+ var PairFromSeed = {
2387
+ ecdsa: (seed) => _utilcrypto.secp256k1PairFromSeed.call(void 0, seed),
2388
+ ed25519: (seed) => _utilcrypto.ed25519PairFromSeed.call(void 0, seed),
2389
+ ethereum: (seed) => _utilcrypto.secp256k1PairFromSeed.call(void 0, seed),
2390
+ sr25519: (seed) => _utilcrypto.sr25519PairFromSeed.call(void 0, seed)
2391
+ };
2392
+ function pairToPublic({ publicKey }) {
2393
+ return publicKey;
2394
+ }
2395
+ var _pairs, _type, _ss58;
2396
+ var Keyring3 = class {
2397
+ constructor(options = {}) {
2398
+ __privateAdd(this, _pairs);
2399
+ __privateAdd(this, _type);
2400
+ __privateAdd(this, _ss58);
2401
+ __publicField(this, "decodeAddress", _utilcrypto.decodeAddress);
2402
+ /**
2403
+ * @name encodeAddress
2404
+ * @description Encodes the input into an ss58 representation
2405
+ */
2406
+ __publicField(this, "encodeAddress", (address, ss58Format) => {
2407
+ return this.type === "ethereum" ? _utilcrypto.ethereumEncode.call(void 0, address) : _utilcrypto.encodeAddress.call(void 0, address, _nullishCoalesce(ss58Format, () => ( __privateGet(this, _ss58))));
2408
+ });
2409
+ options.type = options.type || "ed25519";
2410
+ if (!["ecdsa", "ethereum", "ed25519", "sr25519"].includes(options.type || "undefined")) {
2411
+ throw new Error(`Expected a keyring type of either 'ed25519', 'sr25519', 'ethereum' or 'ecdsa', found '${options.type || "unknown"}`);
2412
+ }
2413
+ __privateSet(this, _pairs, new Pairs());
2414
+ __privateSet(this, _ss58, options.ss58Format);
2415
+ __privateSet(this, _type, options.type);
2416
+ }
2417
+ /**
2418
+ * @description retrieve the pairs (alias for getPairs)
2419
+ */
2420
+ get pairs() {
2421
+ return this.getPairs();
2422
+ }
2423
+ /**
2424
+ * @description retrieve the publicKeys (alias for getPublicKeys)
2425
+ */
2426
+ get publicKeys() {
2427
+ return this.getPublicKeys();
2428
+ }
2429
+ /**
2430
+ * @description Returns the type of the keyring, ed25519, sr25519 or ecdsa
2431
+ */
2432
+ get type() {
2433
+ return __privateGet(this, _type);
2434
+ }
2435
+ /**
2436
+ * @name addPair
2437
+ * @summary Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
2438
+ */
2439
+ addPair(pair) {
2440
+ return __privateGet(this, _pairs).add(pair);
2441
+ }
2442
+ /**
2443
+ * @name addFromAddress
2444
+ * @summary Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary
2445
+ * @description Allows user to explicitly provide separate inputs including account address or public key, and optionally
2446
+ * the associated account metadata, and the default encoded value as arguments (that may be obtained from the json file
2447
+ * of an account backup), and then generates a keyring pair from them that it passes to
2448
+ * `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
2449
+ */
2450
+ addFromAddress(address, meta = {}, encoded = null, type = this.type, ignoreChecksum, encType) {
2451
+ const publicKey = this.decodeAddress(address, ignoreChecksum);
2452
+ return this.addPair(createPair({ toSS58: this.encodeAddress, type }, { publicKey, secretKey: new Uint8Array() }, meta, encoded, encType));
2453
+ }
2454
+ /**
2455
+ * @name addFromJson
2456
+ * @summary Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
2457
+ * @description Allows user to provide a json object argument that contains account information (that may be obtained from the json file
2458
+ * of an account backup), and then generates a keyring pair from it that it passes to
2459
+ * `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
2460
+ */
2461
+ addFromJson(json, ignoreChecksum) {
2462
+ return this.addPair(this.createFromJson(json, ignoreChecksum));
2463
+ }
2464
+ /**
2465
+ * @name addFromMnemonic
2466
+ * @summary Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary
2467
+ * @description Allows user to provide a mnemonic (seed phrase that is provided when account is originally created)
2468
+ * argument and a metadata argument that contains account information (that may be obtained from the json file
2469
+ * of an account backup), and then generates a keyring pair from it that it passes to
2470
+ * `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
2471
+ */
2472
+ addFromMnemonic(mnemonic, meta = {}, type = this.type, wordlist) {
2473
+ return this.addFromUri(mnemonic, meta, type, wordlist);
2474
+ }
2475
+ /**
2476
+ * @name addFromPair
2477
+ * @summary Stores an account created from an explicit publicKey/secreteKey combination
2478
+ */
2479
+ addFromPair(pair, meta = {}, type = this.type) {
2480
+ return this.addPair(this.createFromPair(pair, meta, type));
2481
+ }
2482
+ /**
2483
+ * @name addFromSeed
2484
+ * @summary Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
2485
+ * @description Stores in a keyring pair dictionary the public key of the pair as a key and the pair as the associated value.
2486
+ * Allows user to provide the account seed as an argument, and then generates a keyring pair from it that it passes to
2487
+ * `addPair` to store in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
2488
+ */
2489
+ addFromSeed(seed, meta = {}, type = this.type) {
2490
+ return this.addPair(createPair({ toSS58: this.encodeAddress, type }, PairFromSeed[type](seed), meta, null));
2491
+ }
2492
+ /**
2493
+ * @name addFromUri
2494
+ * @summary Creates an account via an suri
2495
+ * @description Extracts the phrase, path and password from a SURI format for specifying secret keys `<secret>/<soft-key>//<hard-key>///<password>` (the `///password` may be omitted, and `/<soft-key>` and `//<hard-key>` maybe repeated and mixed). The secret can be a hex string, mnemonic phrase or a string (to be padded)
2496
+ */
2497
+ addFromUri(suri, meta = {}, type = this.type, wordlist) {
2498
+ return this.addPair(this.createFromUri(suri, meta, type, wordlist));
2499
+ }
2500
+ /**
2501
+ * @name createFromJson
2502
+ * @description Creates a pair from a JSON keyfile
2503
+ */
2504
+ createFromJson({ address, encoded, encoding: { content, type, version }, meta }, ignoreChecksum) {
2505
+ if (version === "3" && content[0] !== "pkcs8") {
2506
+ throw new Error(`Unable to decode non-pkcs8 type, [${content.join(",")}] found}`);
2507
+ }
2508
+ const cryptoType = version === "0" || !Array.isArray(content) ? this.type : content[1];
2509
+ const encType = !Array.isArray(type) ? [type] : type;
2510
+ if (!["ed25519", "sr25519", "ecdsa", "ethereum"].includes(cryptoType)) {
2511
+ throw new Error(`Unknown crypto type ${cryptoType}`);
2512
+ }
2513
+ const publicKey = _util.isHex.call(void 0, address) ? _util.hexToU8a.call(void 0, address) : this.decodeAddress(address, ignoreChecksum);
2514
+ const decoded = _util.isHex.call(void 0, encoded) ? _util.hexToU8a.call(void 0, encoded) : _utilcrypto.base64Decode.call(void 0, encoded);
2515
+ return createPair({ toSS58: this.encodeAddress, type: cryptoType }, { publicKey, secretKey: new Uint8Array() }, meta, decoded, encType);
2516
+ }
2517
+ /**
2518
+ * @name createFromPair
2519
+ * @summary Creates a pair from an explicit publicKey/secreteKey combination
2520
+ */
2521
+ createFromPair(pair, meta = {}, type = this.type) {
2522
+ return createPair({ toSS58: this.encodeAddress, type }, pair, meta, null);
2523
+ }
2524
+ /**
2525
+ * @name createFromUri
2526
+ * @summary Creates a Keypair from an suri
2527
+ * @description This creates a pair from the suri, but does not add it to the keyring
2528
+ */
2529
+ createFromUri(_suri, meta = {}, type = this.type, wordlist) {
2530
+ const suri = _suri.startsWith("//") ? `${DEV_PHRASE}${_suri}` : _suri;
2531
+ const { derivePath, password, path: path2, phrase } = _utilcrypto.keyExtractSuri.call(void 0, suri);
2532
+ let seed;
2533
+ const isPhraseHex = _util.isHex.call(void 0, phrase, 256);
2534
+ if (isPhraseHex) {
2535
+ seed = _util.hexToU8a.call(void 0, phrase);
2536
+ } else {
2537
+ const parts = phrase.split(" ");
2538
+ if ([12, 15, 18, 21, 24].includes(parts.length)) {
2539
+ seed = type === "ethereum" ? _utilcrypto.mnemonicToLegacySeed.call(void 0, phrase, "", false, 64) : _utilcrypto.mnemonicToMiniSecret.call(void 0, phrase, password, wordlist);
2540
+ } else {
2541
+ if (phrase.length > 32) {
2542
+ throw new Error("specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes");
2543
+ }
2544
+ seed = _util.stringToU8a.call(void 0, phrase.padEnd(32));
2545
+ }
2546
+ }
2547
+ const derived = type === "ethereum" ? isPhraseHex ? PairFromSeed[type](seed) : _utilcrypto.hdEthereum.call(void 0, seed, derivePath.substring(1)) : _utilcrypto.keyFromPath.call(void 0, PairFromSeed[type](seed), path2, type);
2548
+ return createPair({ toSS58: this.encodeAddress, type }, derived, meta, null);
2549
+ }
2550
+ /**
2551
+ * @name getPair
2552
+ * @summary Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address
2553
+ * @description Returns a keyring pair value from the keyring pair dictionary by performing
2554
+ * a key lookup using the provided account address or public key (after decoding it).
2555
+ */
2556
+ getPair(address) {
2557
+ return __privateGet(this, _pairs).get(address);
2558
+ }
2559
+ /**
2560
+ * @name getPairs
2561
+ * @summary Retrieves all account keyring pairs from the Keyring Pair Dictionary
2562
+ * @description Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.
2563
+ */
2564
+ getPairs() {
2565
+ return __privateGet(this, _pairs).all();
2566
+ }
2567
+ /**
2568
+ * @name getPublicKeys
2569
+ * @summary Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary
2570
+ * @description Returns an array list of all the public keys associated with each of the keyring pair values that are stored in the keyring pair dictionary.
2571
+ */
2572
+ getPublicKeys() {
2573
+ return __privateGet(this, _pairs).all().map(pairToPublic);
2574
+ }
2575
+ /**
2576
+ * @name removePair
2577
+ * @description Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
2578
+ */
2579
+ removePair(address) {
2580
+ __privateGet(this, _pairs).remove(address);
2581
+ }
2582
+ /**
2583
+ * @name setSS58Format;
2584
+ * @description Sets the ss58 format for the keyring
2585
+ */
2586
+ setSS58Format(ss58) {
2587
+ __privateSet(this, _ss58, ss58);
2588
+ }
2589
+ /**
2590
+ * @name toJson
2591
+ * @summary Returns a JSON object associated with the input argument that contains metadata assocated with an account
2592
+ * @description Returns a JSON object containing the metadata associated with an account
2593
+ * when valid address or public key and when the account passphrase is provided if the account secret
2594
+ * is not already unlocked and available in memory. Note that in [Polkadot-JS Apps](https://github.com/polkadot-js/apps) the user
2595
+ * may backup their account to a JSON file that contains this information.
2596
+ */
2597
+ toJson(address, passphrase) {
2598
+ return __privateGet(this, _pairs).get(address).toJson(passphrase);
2599
+ }
2600
+ };
2601
+ _pairs = new WeakMap();
2602
+ _type = new WeakMap();
2603
+ _ss58 = new WeakMap();
2604
+
2605
+
2119
2606
 
2120
2607
 
2121
2608
 
@@ -2207,5 +2694,5 @@ async function setWorker(account) {
2207
2694
 
2208
2695
 
2209
2696
 
2210
- exports.API_EXTENSIONS = API_EXTENSIONS; exports.API_RPC = API_RPC; exports.API_TYPES = API_TYPES; exports.AccountSourceType = AccountSourceType; exports.ApiPromise = _api2.ApiPromise; exports.CryptoType = CryptoType; exports.DEBUG = DEBUG; exports.DEFAULT_COMPUTE_PAYLOAD = DEFAULT_COMPUTE_PAYLOAD; exports.DEFAULT_EMPTY_PAYLOAD = DEFAULT_EMPTY_PAYLOAD; exports.FileFromMetadataRef = FileFromMetadataRef; exports.HttpProvider = _api2.HttpProvider; exports.MCryptFs = MCryptFs; exports.MCryptFsReader = MCryptFsReader; exports.MCryptFsWriter = MCryptFsWriter; exports.PALI_DECIMALS = PALI_DECIMALS; exports.PALI_SYMBOL = PALI_SYMBOL; exports.PALLIORA_RPC_URL = PALLIORA_RPC_URL; exports.PALLIORA_WS = PALLIORA_WS; exports.TX_WAIT_FINALIZATION = TX_WAIT_FINALIZATION; exports.WsProvider = _api2.WsProvider; exports.addStake = addStake; exports.base64ToUint8Array = base64ToUint8Array; exports.clearTokenCache = clearTokenCache; exports.configure = configure; exports.createAccount = createAccount; exports.createAgreement = createAgreement; exports.createGuardianGroup = createGuardianGroup; exports.createGuardianGroupAndWatch = createGuardianGroupAndWatch; exports.createSimpleAgreement = createSimpleAgreement; exports.dataContract = dataContract; exports.debugLog = debugLog; exports.decodeAggregateKey = decodeAggregateKey; exports.decodeField = decodeField; exports.decodePowersOfTau = decodePowersOfTau; exports.decrypt = decrypt; exports.ecncryptTest = encrypt; exports.encodeCiphertext = encodeCiphertext; exports.encrypt = encrypt2; exports.fetchAndDecodeExtrinsic = fetchAndDecodeExtrinsic; exports.fetchTokenProperties = fetchTokenProperties; exports.formatBalanceWithTokenProperties = formatBalanceWithTokenProperties; exports.formatPaliAmount = formatPaliAmount; exports.fromAtomicPaliAmount = fromAtomicPaliAmount; exports.fundAccount = fundAccount; exports.gen_shared_key = gen_shared_key; exports.gen_stretched_key = gen_stretched_key; exports.generateRandomBytes = generateRandomBytes; exports.getAgreementCreatedRequestId = getAgreementCreatedRequestId; exports.getApi = getApi; exports.getCachedTokenProperties = getCachedTokenProperties; exports.getEncKeyring = getEncKeyring; exports.getFileMetadataCall = getFileMetadataCall; exports.getGuardianAddress = getGuardianAddress; exports.getGuardianList = getGuardianList; exports.getGuardianNwParams = getGuardianNwParams; exports.getGuardianParticipants = getGuardianParticipants; exports.getKeyring = getKeyring; exports.hexToUint8Array = hexToUint8Array; exports.inferenceCompute = inferenceCompute; exports.joinGuardian = joinGuardian; exports.joinIdleStaker = joinIdleStaker; exports.joinValidator = joinValidator; exports.newStake = newStake; exports.pairFromPrivateKeyHex = pairFromPrivateKeyHex; exports.payoutStake = payoutStake; exports.provider = provider; exports.reduceStake = reduceStake; exports.registerDataAgreement = registerDataAgreement; exports.removeStake = removeStake; exports.rotateAndSetKeys = rotateAndSetKeys; exports.runAgent = runAgent; exports.scanForBlockEvent = scanForBlockEvent; exports.setIdentity = setIdentity; exports.setWorker = setWorker; exports.signAndSend = signAndSend; exports.simpleCompute = simpleCompute; exports.submitData = submitData; exports.submitTEData = submitTEData; exports.submitTEDataWithCipher = submitTEDataWithCipher; exports.testCrypt = testCrypt; exports.toAtomicPaliAmount = toAtomicPaliAmount; exports.tokenToBigint = tokenToBigint; exports.transfer = transfer; exports.uint8ArrayToBase64 = uint8ArrayToBase64; exports.uploadData = uploadData; exports.uploadDataLegacy = uploadDataLegacy; exports.utilCrypto = utilCrypto; exports.wasmCrypto = wasmCrypto; exports.watchForSubmissionReceipt = watchForSubmissionReceipt; exports.withdrawStake = withdrawStake; exports.writeMetadata = writeMetadata;
2697
+ exports.API_EXTENSIONS = API_EXTENSIONS; exports.API_RPC = API_RPC; exports.API_TYPES = API_TYPES; exports.AccountSourceType = AccountSourceType; exports.ApiPromise = _api2.ApiPromise; exports.CryptoType = CryptoType; exports.DEBUG = DEBUG; exports.DEFAULT_COMPUTE_PAYLOAD = DEFAULT_COMPUTE_PAYLOAD; exports.DEFAULT_EMPTY_PAYLOAD = DEFAULT_EMPTY_PAYLOAD; exports.FileFromMetadataRef = FileFromMetadataRef; exports.HttpProvider = _api2.HttpProvider; exports.Keyring = Keyring3; exports.MCryptFs = MCryptFs; exports.MCryptFsReader = MCryptFsReader; exports.MCryptFsWriter = MCryptFsWriter; exports.PALI_DECIMALS = PALI_DECIMALS; exports.PALI_SYMBOL = PALI_SYMBOL; exports.PALLIORA_RPC_URL = PALLIORA_RPC_URL; exports.PALLIORA_WS = PALLIORA_WS; exports.TX_WAIT_FINALIZATION = TX_WAIT_FINALIZATION; exports.WsProvider = _api2.WsProvider; exports.addStake = addStake; exports.base64ToUint8Array = base64ToUint8Array; exports.clearTokenCache = clearTokenCache; exports.configure = configure; exports.createAccount = createAccount; exports.createAgreement = createAgreement; exports.createGuardianGroup = createGuardianGroup; exports.createGuardianGroupAndWatch = createGuardianGroupAndWatch; exports.createSimpleAgreement = createSimpleAgreement; exports.dataContract = dataContract; exports.debugLog = debugLog; exports.decodeAggregateKey = decodeAggregateKey; exports.decodeField = decodeField; exports.decodePowersOfTau = decodePowersOfTau; exports.decrypt = decrypt; exports.ecncryptTest = encrypt; exports.encodeCiphertext = encodeCiphertext; exports.encrypt = encrypt2; exports.fetchAndDecodeExtrinsic = fetchAndDecodeExtrinsic; exports.fetchTokenProperties = fetchTokenProperties; exports.formatBalanceWithTokenProperties = formatBalanceWithTokenProperties; exports.formatPaliAmount = formatPaliAmount; exports.fromAtomicPaliAmount = fromAtomicPaliAmount; exports.fundAccount = fundAccount; exports.gen_shared_key = gen_shared_key; exports.gen_stretched_key = gen_stretched_key; exports.generateRandomBytes = generateRandomBytes; exports.getAgreementCreatedRequestId = getAgreementCreatedRequestId; exports.getApi = getApi; exports.getCachedTokenProperties = getCachedTokenProperties; exports.getEncKeyring = getEncKeyring; exports.getFileMetadataCall = getFileMetadataCall; exports.getGuardianAddress = getGuardianAddress; exports.getGuardianList = getGuardianList; exports.getGuardianNwParams = getGuardianNwParams; exports.getGuardianParticipants = getGuardianParticipants; exports.getKeyring = getKeyring; exports.hexToUint8Array = hexToUint8Array; exports.inferenceCompute = inferenceCompute; exports.joinGuardian = joinGuardian; exports.joinIdleStaker = joinIdleStaker; exports.joinValidator = joinValidator; exports.newStake = newStake; exports.pairFromPrivateKeyHex = pairFromPrivateKeyHex; exports.payoutStake = payoutStake; exports.provider = provider; exports.reduceStake = reduceStake; exports.registerDataAgreement = registerDataAgreement; exports.removeStake = removeStake; exports.rotateAndSetKeys = rotateAndSetKeys; exports.runAgent = runAgent; exports.scanForBlockEvent = scanForBlockEvent; exports.setIdentity = setIdentity; exports.setWorker = setWorker; exports.signAndSend = signAndSend; exports.simpleCompute = simpleCompute; exports.submitData = submitData; exports.submitTEData = submitTEData; exports.submitTEDataWithCipher = submitTEDataWithCipher; exports.testCrypt = testCrypt; exports.toAtomicPaliAmount = toAtomicPaliAmount; exports.tokenToBigint = tokenToBigint; exports.transfer = transfer; exports.uint8ArrayToBase64 = uint8ArrayToBase64; exports.uploadData = uploadData; exports.uploadDataLegacy = uploadDataLegacy; exports.utilCrypto = utilCrypto; exports.wasmCrypto = wasmCrypto; exports.watchForSubmissionReceipt = watchForSubmissionReceipt; exports.withdrawStake = withdrawStake; exports.writeMetadata = writeMetadata;
2211
2698
  //# sourceMappingURL=index.cjs.map