@aeternity/aepp-sdk 13.3.1 → 13.3.3
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/bin/aesophia_cli_8 +0 -0
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +50 -45
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdkAepp.mjs +1 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkWallet.mjs +4 -1
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/chain.d.ts +5 -5
- package/es/chain.mjs +18 -20
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.d.ts +1 -1
- package/es/channel/Base.mjs.map +1 -1
- package/es/channel/internal.d.ts +23 -17
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Contract.mjs +3 -0
- package/es/contract/Contract.mjs.map +1 -1
- package/es/oracle.d.ts +2 -2
- package/es/oracle.mjs +6 -10
- package/es/oracle.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-price.mjs +1 -4
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
- package/es/tx/builder/field-types/ttl.d.ts +3 -2
- package/es/tx/builder/field-types/ttl.mjs.map +1 -1
- package/es/tx/builder/helpers.mjs +9 -0
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +69 -46
- package/es/utils/hd-wallet.d.ts +2 -1
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -1
- package/es/utils/semver-satisfies.mjs +8 -9
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/package.json +5 -4
- package/src/AeSdkAepp.ts +1 -1
- package/src/AeSdkWallet.ts +2 -1
- package/src/chain.ts +28 -18
- package/src/channel/Base.ts +1 -1
- package/src/channel/internal.ts +24 -17
- package/src/contract/Contract.ts +3 -0
- package/src/oracle.ts +7 -7
- package/src/tx/builder/field-types/gas-price.ts +67 -70
- package/src/tx/builder/field-types/ttl.ts +1 -1
- package/src/tx/builder/helpers.ts +9 -0
- package/src/utils/hd-wallet.ts +5 -3
- package/src/utils/semver-satisfies.ts +14 -13
- package/types-legacy/ts4.2/chain.d.ts +5 -5
- package/types-legacy/ts4.2/channel/Base.d.ts +1 -1
- package/types-legacy/ts4.2/channel/internal.d.ts +23 -17
- package/types-legacy/ts4.2/oracle.d.ts +2 -2
- package/types-legacy/ts4.2/tx/builder/field-types/ttl.d.ts +3 -2
- package/types-legacy/ts4.2/tx/builder/schema.d.ts +69 -46
- package/types-legacy/ts4.2/utils/hd-wallet.d.ts +2 -1
- package/types-legacy/ts4.2/utils/semver-satisfies.d.ts +1 -1
- package/types-legacy/ts4.5/chain.d.ts +5 -5
- package/types-legacy/ts4.5/channel/Base.d.ts +1 -1
- package/types-legacy/ts4.5/channel/internal.d.ts +23 -17
- package/types-legacy/ts4.5/oracle.d.ts +2 -2
- package/types-legacy/ts4.5/tx/builder/field-types/ttl.d.ts +3 -2
- package/types-legacy/ts4.5/tx/builder/schema.d.ts +69 -46
- package/types-legacy/ts4.5/utils/hd-wallet.d.ts +2 -1
- package/types-legacy/ts4.5/utils/semver-satisfies.d.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hd-wallet.mjs","names":["nacl","_tweetnaclAuth","full","hmac","_bip32Path","fromString","aesjs","sha256hash","encode","Encoding","CryptographyError","concatBuffers","Ecb","ModeOfOperation","ecb","encryptKey","password","binaryData","hashedPasswordBytes","aesEcb","encrypt","decryptKey","encrypted","encryptedBytes","_Buffer","from","decrypt","DerivationError","constructor","message","name","ED25519_CURVE","HARDENED_OFFSET","deriveChild","secretKey","chainCode","index","indexBuffer","allocUnsafe","writeUInt32BE","data","alloc","I","IL","slice","IR","derivePathFromKey","path","key","segments","toPathArray","forEach","segment","i","reduce","parentKey","getMasterKeyFromSeed","seed","derivePathFromSeed","includes","masterKey","formatAccount","keys","publicKey","toString","AccountAddress","getKeyPair","sign","keyPair","fromSeed","generateSaveHDWalletFromSeed","walletKey","getSaveHDWalletAccounts","saveHDWallet","accountCount","Array","fill","undefined","map","_","idx","getHdWalletAccountFromSeed","accountIdx","derived"],"sources":["../../src/utils/hd-wallet.ts"],"sourcesContent":["import nacl from 'tweetnacl';\nimport { full as hmac } from 'tweetnacl-auth';\nimport { fromString } from 'bip32-path';\nimport aesjs from 'aes-js';\nimport { sha256hash, encode, Encoding } from './encoder';\nimport { CryptographyError } from './errors';\nimport { concatBuffers } from './other';\n\nconst Ecb = aesjs.ModeOfOperation.ecb;\n\n// TODO: use mnemonic encryption instead of AES\n/**\n * Encrypt given data using `password`\n * @param password - Password to encrypt with\n * @param binaryData - Data to encrypt\n * @returns Encrypted data\n */\nfunction encryptKey(password: string, binaryData: Uint8Array): Uint8Array {\n const hashedPasswordBytes = sha256hash(password);\n const aesEcb = new Ecb(hashedPasswordBytes);\n return aesEcb.encrypt(binaryData);\n}\n\n/**\n * Decrypt given data using `password`\n * @param password - Password to decrypt with\n * @param encrypted - Data to decrypt\n * @returns Decrypted data\n */\nfunction decryptKey(password: string, encrypted: Uint8Array): Uint8Array {\n const encryptedBytes = Buffer.from(encrypted);\n const hashedPasswordBytes = sha256hash(password);\n const aesEcb = new Ecb(hashedPasswordBytes);\n return aesEcb.decrypt(encryptedBytes);\n}\n\n/**\n * @category exception\n */\nexport class DerivationError extends CryptographyError {\n constructor(message: string) {\n super(message);\n this.name = 'DerivationError';\n }\n}\n\nconst ED25519_CURVE = Buffer.from('ed25519 seed');\nconst HARDENED_OFFSET = 0x80000000;\n\ninterface KeyTreeNode {\n secretKey: Uint8Array;\n chainCode: Uint8Array;\n}\n\ninterface HDWallet {\n secretKey: string;\n chainCode: string;\n}\n\ninterface Account {\n secretKey: string;\n publicKey: string;\n}\n\ntype Dec<N extends number> = [-1, 0, 1, 2, 3, 4][N];\ntype Bip32PathT<MaxLen extends number, H extends 'H' | 'h' | '\\''> = MaxLen extends -1\n ? `${number}${H}`\n : Bip32PathT<Dec<MaxLen>, H> | `${Bip32PathT<Dec<MaxLen>, H>}/${number}${H}`;\ntype Bip32Path<MaxLen extends number> =\n '' | Bip32PathT<MaxLen, 'H'> | Bip32PathT<MaxLen, 'h'> | Bip32PathT<MaxLen, '\\''>;\n\n/**\n * @category hd-wallet\n * @param keyTreeNode - A node of key tree\n * @param index - index of child node to derive\n */\nexport function deriveChild({ secretKey, chainCode }: KeyTreeNode, index: number): KeyTreeNode {\n if (index < HARDENED_OFFSET) {\n throw new DerivationError(`Segment ${index} is not hardened`);\n }\n const indexBuffer = Buffer.allocUnsafe(4);\n indexBuffer.writeUInt32BE(index, 0);\n\n const data = concatBuffers([Buffer.alloc(1, 0), secretKey, indexBuffer]);\n\n const I = hmac(data, chainCode);\n const IL = I.slice(0, 32);\n const IR = I.slice(32);\n return {\n secretKey: IL,\n chainCode: IR,\n };\n}\n\n/**\n * @category hd-wallet\n */\nexport function derivePathFromKey(path: Bip32Path<5>, key: KeyTreeNode): KeyTreeNode {\n const segments = path === '' ? [] : fromString(path).toPathArray();\n segments.forEach((segment, i) => {\n if (segment < HARDENED_OFFSET) {\n throw new DerivationError(`Segment #${i + 1} is not hardened`);\n }\n });\n\n return segments.reduce((parentKey, segment) => deriveChild(parentKey, segment), key);\n}\n\n/**\n * @category hd-wallet\n */\nexport function getMasterKeyFromSeed(seed: Uint8Array): KeyTreeNode {\n const I = hmac(seed, ED25519_CURVE);\n const IL = I.slice(0, 32);\n const IR = I.slice(32);\n return {\n secretKey: IL,\n chainCode: IR,\n };\n}\n\n/**\n * @category hd-wallet\n */\nexport function derivePathFromSeed(path: 'm' | `m/${Bip32Path<5>}`, seed: Uint8Array): KeyTreeNode {\n if (!['m', 'm/'].includes(path.slice(0, 2))) {\n throw new DerivationError('Root element is required');\n }\n const masterKey = getMasterKeyFromSeed(seed);\n return derivePathFromKey(path.slice(2) as Bip32Path<5>, masterKey);\n}\n\nfunction formatAccount(keys: nacl.SignKeyPair): Account {\n const { secretKey, publicKey } = keys;\n return {\n secretKey: Buffer.from(secretKey).toString('hex'),\n publicKey: encode(publicKey, Encoding.AccountAddress),\n };\n}\n\n/**\n * @category hd-wallet\n */\nexport function getKeyPair(secretKey: Uint8Array): nacl.SignKeyPair {\n return nacl.sign.keyPair.fromSeed(secretKey);\n}\n\n/**\n * @category hd-wallet\n */\nexport function generateSaveHDWalletFromSeed(seed: Uint8Array, password: string): HDWallet {\n const walletKey = derivePathFromSeed('m/44h/457h', seed);\n return {\n secretKey: Buffer.from(encryptKey(password, walletKey.secretKey)).toString('hex'),\n chainCode: Buffer.from(encryptKey(password, walletKey.chainCode)).toString('hex'),\n };\n}\n\n/**\n * @category hd-wallet\n */\nexport function getSaveHDWalletAccounts(\n saveHDWallet: HDWallet,\n password: string,\n accountCount: number,\n): Account[] {\n const walletKey = {\n secretKey: decryptKey(password, Buffer.from(saveHDWallet.secretKey, 'hex')),\n chainCode: decryptKey(password, Buffer.from(saveHDWallet.chainCode, 'hex')),\n };\n return (new Array(accountCount)).fill(undefined)\n .map((_, idx) => formatAccount(getKeyPair(derivePathFromKey(`${idx}h/0h/0h`, walletKey).secretKey)));\n}\n\n/**\n * @category hd-wallet\n */\nexport const getHdWalletAccountFromSeed = (\n seed: Uint8Array,\n accountIdx: number,\n): Account & { idx: number } => {\n const walletKey = derivePathFromSeed('m/44h/457h', seed);\n const derived = derivePathFromKey(`${accountIdx}h/0h/0h`, walletKey);\n const keyPair = getKeyPair(derived.secretKey);\n return {\n ...formatAccount(keyPair),\n idx: accountIdx,\n };\n};\n"],"mappings":";;;;AAAA,OAAOA,IAAI,MAAM,WAAW;AAC5B,OAAAC,cAAA,MAA6B,gBAAgB;AAAC;EAAAC,IAAA,EAAAC;AAAA,IAAAF,cAAA;AAC9C,OAAAG,UAAA,MAA2B,YAAY;AAAC;EAAAC;AAAA,IAAAD,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ACP,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"hd-wallet.mjs","names":["nacl","_tweetnaclAuth","full","hmac","_bip32Path","fromString","aesjs","sha256hash","encode","Encoding","CryptographyError","concatBuffers","Ecb","ModeOfOperation","ecb","encryptKey","password","binaryData","hashedPasswordBytes","aesEcb","encrypt","decryptKey","encrypted","encryptedBytes","_Buffer","from","decrypt","DerivationError","constructor","message","name","ED25519_CURVE","HARDENED_OFFSET","deriveChild","secretKey","chainCode","index","indexBuffer","allocUnsafe","writeUInt32BE","data","alloc","I","IL","slice","IR","derivePathFromKey","path","key","segments","toPathArray","forEach","segment","i","reduce","parentKey","getMasterKeyFromSeed","seed","derivePathFromSeed","includes","masterKey","formatAccount","keys","publicKey","toString","AccountAddress","getKeyPair","sign","keyPair","fromSeed","generateSaveHDWalletFromSeed","walletKey","getSaveHDWalletAccounts","saveHDWallet","accountCount","Array","fill","undefined","map","_","idx","getHdWalletAccountFromSeed","accountIdx","derived"],"sources":["../../src/utils/hd-wallet.ts"],"sourcesContent":["import nacl from 'tweetnacl';\nimport { full as hmac } from 'tweetnacl-auth';\nimport { fromString } from 'bip32-path';\nimport aesjs from 'aes-js';\nimport {\n sha256hash, encode, Encoding, Encoded,\n} from './encoder';\nimport { CryptographyError } from './errors';\nimport { concatBuffers } from './other';\n\nconst Ecb = aesjs.ModeOfOperation.ecb;\n\n// TODO: use mnemonic encryption instead of AES\n/**\n * Encrypt given data using `password`\n * @param password - Password to encrypt with\n * @param binaryData - Data to encrypt\n * @returns Encrypted data\n */\nfunction encryptKey(password: string, binaryData: Uint8Array): Uint8Array {\n const hashedPasswordBytes = sha256hash(password);\n const aesEcb = new Ecb(hashedPasswordBytes);\n return aesEcb.encrypt(binaryData);\n}\n\n/**\n * Decrypt given data using `password`\n * @param password - Password to decrypt with\n * @param encrypted - Data to decrypt\n * @returns Decrypted data\n */\nfunction decryptKey(password: string, encrypted: Uint8Array): Uint8Array {\n const encryptedBytes = Buffer.from(encrypted);\n const hashedPasswordBytes = sha256hash(password);\n const aesEcb = new Ecb(hashedPasswordBytes);\n return aesEcb.decrypt(encryptedBytes);\n}\n\n/**\n * @category exception\n */\nexport class DerivationError extends CryptographyError {\n constructor(message: string) {\n super(message);\n this.name = 'DerivationError';\n }\n}\n\nconst ED25519_CURVE = Buffer.from('ed25519 seed');\nconst HARDENED_OFFSET = 0x80000000;\n\ninterface KeyTreeNode {\n secretKey: Uint8Array;\n chainCode: Uint8Array;\n}\n\ninterface HDWallet {\n secretKey: string;\n chainCode: string;\n}\n\ninterface Account {\n secretKey: string; // TODO: use Encoded.AccountSecretKey instead hex\n publicKey: Encoded.AccountAddress;\n}\n\ntype Dec<N extends number> = [-1, 0, 1, 2, 3, 4][N];\ntype Bip32PathT<MaxLen extends number, H extends 'H' | 'h' | '\\''> = MaxLen extends -1\n ? `${number}${H}`\n : Bip32PathT<Dec<MaxLen>, H> | `${Bip32PathT<Dec<MaxLen>, H>}/${number}${H}`;\ntype Bip32Path<MaxLen extends number> =\n '' | Bip32PathT<MaxLen, 'H'> | Bip32PathT<MaxLen, 'h'> | Bip32PathT<MaxLen, '\\''>;\n\n/**\n * @category hd-wallet\n * @param keyTreeNode - A node of key tree\n * @param index - index of child node to derive\n */\nexport function deriveChild({ secretKey, chainCode }: KeyTreeNode, index: number): KeyTreeNode {\n if (index < HARDENED_OFFSET) {\n throw new DerivationError(`Segment ${index} is not hardened`);\n }\n const indexBuffer = Buffer.allocUnsafe(4);\n indexBuffer.writeUInt32BE(index, 0);\n\n const data = concatBuffers([Buffer.alloc(1, 0), secretKey, indexBuffer]);\n\n const I = hmac(data, chainCode);\n const IL = I.slice(0, 32);\n const IR = I.slice(32);\n return {\n secretKey: IL,\n chainCode: IR,\n };\n}\n\n/**\n * @category hd-wallet\n */\nexport function derivePathFromKey(path: Bip32Path<5>, key: KeyTreeNode): KeyTreeNode {\n const segments = path === '' ? [] : fromString(path).toPathArray();\n segments.forEach((segment, i) => {\n if (segment < HARDENED_OFFSET) {\n throw new DerivationError(`Segment #${i + 1} is not hardened`);\n }\n });\n\n return segments.reduce((parentKey, segment) => deriveChild(parentKey, segment), key);\n}\n\n/**\n * @category hd-wallet\n */\nexport function getMasterKeyFromSeed(seed: Uint8Array): KeyTreeNode {\n const I = hmac(seed, ED25519_CURVE);\n const IL = I.slice(0, 32);\n const IR = I.slice(32);\n return {\n secretKey: IL,\n chainCode: IR,\n };\n}\n\n/**\n * @category hd-wallet\n */\nexport function derivePathFromSeed(path: 'm' | `m/${Bip32Path<5>}`, seed: Uint8Array): KeyTreeNode {\n if (!['m', 'm/'].includes(path.slice(0, 2))) {\n throw new DerivationError('Root element is required');\n }\n const masterKey = getMasterKeyFromSeed(seed);\n return derivePathFromKey(path.slice(2) as Bip32Path<5>, masterKey);\n}\n\nfunction formatAccount(keys: nacl.SignKeyPair): Account {\n const { secretKey, publicKey } = keys;\n return {\n secretKey: Buffer.from(secretKey).toString('hex'),\n publicKey: encode(publicKey, Encoding.AccountAddress),\n };\n}\n\n/**\n * @category hd-wallet\n */\nexport function getKeyPair(secretKey: Uint8Array): nacl.SignKeyPair {\n return nacl.sign.keyPair.fromSeed(secretKey);\n}\n\n/**\n * @category hd-wallet\n */\nexport function generateSaveHDWalletFromSeed(seed: Uint8Array, password: string): HDWallet {\n const walletKey = derivePathFromSeed('m/44h/457h', seed);\n return {\n secretKey: Buffer.from(encryptKey(password, walletKey.secretKey)).toString('hex'),\n chainCode: Buffer.from(encryptKey(password, walletKey.chainCode)).toString('hex'),\n };\n}\n\n/**\n * @category hd-wallet\n */\nexport function getSaveHDWalletAccounts(\n saveHDWallet: HDWallet,\n password: string,\n accountCount: number,\n): Account[] {\n const walletKey = {\n secretKey: decryptKey(password, Buffer.from(saveHDWallet.secretKey, 'hex')),\n chainCode: decryptKey(password, Buffer.from(saveHDWallet.chainCode, 'hex')),\n };\n return (new Array(accountCount)).fill(undefined)\n .map((_, idx) => formatAccount(getKeyPair(derivePathFromKey(`${idx}h/0h/0h`, walletKey).secretKey)));\n}\n\n/**\n * @category hd-wallet\n */\nexport const getHdWalletAccountFromSeed = (\n seed: Uint8Array,\n accountIdx: number,\n): Account & { idx: number } => {\n const walletKey = derivePathFromSeed('m/44h/457h', seed);\n const derived = derivePathFromKey(`${accountIdx}h/0h/0h`, walletKey);\n const keyPair = getKeyPair(derived.secretKey);\n return {\n ...formatAccount(keyPair),\n idx: accountIdx,\n };\n};\n"],"mappings":";;;;AAAA,OAAOA,IAAI,MAAM,WAAW;AAC5B,OAAAC,cAAA,MAA6B,gBAAgB;AAAC;EAAAC,IAAA,EAAAC;AAAA,IAAAF,cAAA;AAC9C,OAAAG,UAAA,MAA2B,YAAY;AAAC;EAAAC;AAAA,IAAAD,UAAA;AACxC,OAAOE,KAAK,MAAM,QAAQ;AAAC,SAEzBC,UAAU,EAAEC,MAAM,EAAEC,QAAQ;AAAA,SAErBC,iBAAiB;AAAA,SACjBC,aAAa;AAEtB,MAAMC,GAAG,GAAGN,KAAK,CAACO,eAAe,CAACC,GAAG;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,UAAUA,CAACC,QAAgB,EAAEC,UAAsB,EAAc;EACxE,MAAMC,mBAAmB,GAAGX,UAAU,CAACS,QAAQ,CAAC;EAChD,MAAMG,MAAM,GAAG,IAAIP,GAAG,CAACM,mBAAmB,CAAC;EAC3C,OAAOC,MAAM,CAACC,OAAO,CAACH,UAAU,CAAC;AACnC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAASI,UAAUA,CAACL,QAAgB,EAAEM,SAAqB,EAAc;EACvE,MAAMC,cAAc,GAAGC,OAAA,CAAOC,IAAI,CAACH,SAAS,CAAC;EAC7C,MAAMJ,mBAAmB,GAAGX,UAAU,CAACS,QAAQ,CAAC;EAChD,MAAMG,MAAM,GAAG,IAAIP,GAAG,CAACM,mBAAmB,CAAC;EAC3C,OAAOC,MAAM,CAACO,OAAO,CAACH,cAAc,CAAC;AACvC;;AAEA;AACA;AACA;AACA,OAA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C,GAAI,SAAQ,EAAET,SAAS,CAAC,CAACrC,SAAS,CAAC,CAAC,CAAC;AACxG;;AAEA;AACA;AACA;AACA,OAAO,MAAM+C,0BAA0B,GAAGA,CACxCxB,IAAgB,EAChByB,UAAkB,KACY;EAC9B,MAAMX,SAAS,GAAGb,kBAAkB,CAAC,YAAY,EAAED,IAAI,CAAC;EACxD,MAAM0B,OAAO,GAAGrC,iBAAiB,CAAE,GAAEoC,UAAW,SAAQ,EAAEX,SAAS,CAAC;EACpE,MAAMH,OAAO,GAAGF,UAAU,CAACiB,OAAO,CAACjD,SAAS,CAAC;EAC7C,OAAO;IACL,GAAG2B,aAAa,CAACO,OAAO,CAAC;IACzBY,GAAG,EAAEE;EACP,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function semverSatisfies(version: string, geVersion: string, ltVersion
|
|
1
|
+
export default function semverSatisfies(version: string, geVersion: string, ltVersion?: string): boolean;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
function verCmp(a, b) {
|
|
2
2
|
const getComponents = v => v.split(/[-+]/)[0].split('.').map(i => +i);
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1;
|
|
3
|
+
const aComponents = getComponents(a);
|
|
4
|
+
const bComponents = getComponents(b);
|
|
5
|
+
const base = Math.max(...aComponents, ...bComponents) + 1;
|
|
7
6
|
const componentsToNumber = components => components.reverse().reduce((acc, n, idx) => acc + n * base ** idx, 0);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
7
|
+
return componentsToNumber(aComponents) - componentsToNumber(bComponents);
|
|
8
|
+
}
|
|
9
|
+
export default function semverSatisfies(version, geVersion, ltVersion) {
|
|
10
|
+
return verCmp(version, geVersion) >= 0 && (ltVersion == null || verCmp(version, ltVersion) < 0);
|
|
12
11
|
}
|
|
13
12
|
//# sourceMappingURL=semver-satisfies.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semver-satisfies.mjs","names":["
|
|
1
|
+
{"version":3,"file":"semver-satisfies.mjs","names":["verCmp","a","b","getComponents","v","split","map","i","aComponents","bComponents","base","Math","max","componentsToNumber","components","reverse","reduce","acc","n","idx","semverSatisfies","version","geVersion","ltVersion"],"sources":["../../src/utils/semver-satisfies.ts"],"sourcesContent":["function verCmp(a: string, b: string): number {\n const getComponents = (v: string): number[] => v\n .split(/[-+]/)[0].split('.').map((i) => +i);\n\n const aComponents = getComponents(a);\n const bComponents = getComponents(b);\n\n const base = Math.max(...aComponents, ...bComponents) + 1;\n const componentsToNumber = (components: number[]): number => components.reverse()\n .reduce((acc, n, idx) => acc + n * base ** idx, 0);\n\n return componentsToNumber(aComponents) - componentsToNumber(bComponents);\n}\n\nexport default function semverSatisfies(\n version: string,\n geVersion: string,\n ltVersion?: string,\n): boolean {\n return verCmp(version, geVersion) >= 0\n && (ltVersion == null || verCmp(version, ltVersion) < 0);\n}\n"],"mappings":"AAAA,SAASA,MAAMA,CAACC,CAAS,EAAEC,CAAS,EAAU;EAC5C,MAAMC,aAAa,GAAIC,CAAS,IAAeA,CAAC,CAC7CC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAACA,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAAEC,CAAC,IAAK,CAACA,CAAC,CAAC;EAE7C,MAAMC,WAAW,GAAGL,aAAa,CAACF,CAAC,CAAC;EACpC,MAAMQ,WAAW,GAAGN,aAAa,CAACD,CAAC,CAAC;EAEpC,MAAMQ,IAAI,GAAGC,IAAI,CAACC,GAAG,CAAC,GAAGJ,WAAW,EAAE,GAAGC,WAAW,CAAC,GAAG,CAAC;EACzD,MAAMI,kBAAkB,GAAIC,UAAoB,IAAaA,UAAU,CAACC,OAAO,CAAC,CAAC,CAC9EC,MAAM,CAAC,CAACC,GAAG,EAAEC,CAAC,EAAEC,GAAG,KAAKF,GAAG,GAAGC,CAAC,GAAGR,IAAI,IAAIS,GAAG,EAAE,CAAC,CAAC;EAEpD,OAAON,kBAAkB,CAACL,WAAW,CAAC,GAAGK,kBAAkB,CAACJ,WAAW,CAAC;AAC1E;AAEA,eAAe,SAASW,eAAeA,CACrCC,OAAe,EACfC,SAAiB,EACjBC,SAAkB,EACT;EACT,OAAOvB,MAAM,CAACqB,OAAO,EAAEC,SAAS,CAAC,IAAI,CAAC,KAChCC,SAAS,IAAI,IAAI,IAAIvB,MAAM,CAACqB,OAAO,EAAEE,SAAS,CAAC,GAAG,CAAC,CAAC;AAC5D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeternity/aepp-sdk",
|
|
3
|
-
"version": "13.3.
|
|
3
|
+
"version": "13.3.3",
|
|
4
4
|
"description": "SDK for the æternity blockchain",
|
|
5
5
|
"main": "dist/aepp-sdk.js",
|
|
6
6
|
"types": "es/index.d.ts",
|
|
@@ -79,9 +79,10 @@
|
|
|
79
79
|
"@aeternity/argon2": "^0.0.1",
|
|
80
80
|
"@aeternity/uuid": "^0.0.1",
|
|
81
81
|
"@azure/core-client": "^1.8.0",
|
|
82
|
-
"@azure/core-rest-pipeline": "
|
|
82
|
+
"@azure/core-rest-pipeline": "~1.14.0",
|
|
83
|
+
"@azure/logger": "~1.0.4",
|
|
83
84
|
"@babel/runtime-corejs3": "^7.24.0",
|
|
84
|
-
"@ledgerhq/hw-transport": "
|
|
85
|
+
"@ledgerhq/hw-transport": "~6.30.6",
|
|
85
86
|
"@types/aes-js": "^3.1.4",
|
|
86
87
|
"@types/json-bigint": "^1.0.4",
|
|
87
88
|
"@types/node": "~18.13",
|
|
@@ -111,7 +112,7 @@
|
|
|
111
112
|
},
|
|
112
113
|
"repository": {
|
|
113
114
|
"type": "git",
|
|
114
|
-
"url": "https://github.com/aeternity/aepp-sdk-js"
|
|
115
|
+
"url": "git+https://github.com/aeternity/aepp-sdk-js.git"
|
|
115
116
|
},
|
|
116
117
|
"devDependencies": {
|
|
117
118
|
"@babel/cli": "^7.23.9",
|
package/src/AeSdkAepp.ts
CHANGED
|
@@ -146,7 +146,7 @@ export default class AeSdkAepp extends AeSdkBase {
|
|
|
146
146
|
* @returns Addresses from wallet
|
|
147
147
|
*/
|
|
148
148
|
async askAddresses(): Promise<Encoded.AccountAddress[]> {
|
|
149
|
-
this.
|
|
149
|
+
this._ensureConnected();
|
|
150
150
|
return this.rpcClient.request(METHODS.address, undefined);
|
|
151
151
|
}
|
|
152
152
|
|
package/src/AeSdkWallet.ts
CHANGED
|
@@ -358,11 +358,12 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
358
358
|
* @returns Object with wallet information
|
|
359
359
|
*/
|
|
360
360
|
async getWalletInfo(): Promise<WalletInfo> {
|
|
361
|
+
const { origin } = window.location;
|
|
361
362
|
return {
|
|
362
363
|
id: this.id,
|
|
363
364
|
name: this.name,
|
|
364
365
|
networkId: await this.api.getNetworkId(),
|
|
365
|
-
origin:
|
|
366
|
+
origin: origin === 'file://' ? '*' : origin,
|
|
366
367
|
type: this._type,
|
|
367
368
|
};
|
|
368
369
|
}
|
package/src/chain.ts
CHANGED
|
@@ -21,15 +21,25 @@ import {
|
|
|
21
21
|
* @param type - Type
|
|
22
22
|
* @param options - Options
|
|
23
23
|
*/
|
|
24
|
-
export function _getPollInterval(
|
|
25
|
-
type: '
|
|
26
|
-
{ _expectedMineRate
|
|
27
|
-
{ _expectedMineRate?: number; _microBlockCycle?: number },
|
|
28
|
-
): number {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
export async function _getPollInterval(
|
|
25
|
+
type: 'key-block' | 'micro-block',
|
|
26
|
+
{ _expectedMineRate, _microBlockCycle, onNode }:
|
|
27
|
+
{ _expectedMineRate?: number; _microBlockCycle?: number; onNode: Node },
|
|
28
|
+
): Promise<number> {
|
|
29
|
+
const getVal = async (
|
|
30
|
+
t: string,
|
|
31
|
+
val: number | undefined,
|
|
32
|
+
devModeDef: number,
|
|
33
|
+
def: number,
|
|
34
|
+
): Promise<number | null> => {
|
|
35
|
+
if (t !== type) return null;
|
|
36
|
+
if (val != null) return val;
|
|
37
|
+
return await onNode?.getNetworkId() === 'ae_dev' ? devModeDef : def;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const base = await getVal('key-block', _expectedMineRate, 0, 180000)
|
|
41
|
+
?? await getVal('micro-block', _microBlockCycle, 0, 3000)
|
|
42
|
+
?? (() => { throw new InternalError(`Unknown type: ${type}`); })();
|
|
33
43
|
return Math.floor(base / 3);
|
|
34
44
|
}
|
|
35
45
|
|
|
@@ -53,7 +63,7 @@ export async function getHeight(
|
|
|
53
63
|
const onNode = unwrapProxy(options.onNode);
|
|
54
64
|
if (cached) {
|
|
55
65
|
const cache = heightCache.get(onNode);
|
|
56
|
-
if (cache != null && cache.time > Date.now() - _getPollInterval('block', options)) {
|
|
66
|
+
if (cache != null && cache.time > Date.now() - await _getPollInterval('key-block', options)) {
|
|
57
67
|
return cache.height;
|
|
58
68
|
}
|
|
59
69
|
}
|
|
@@ -77,21 +87,21 @@ export async function getHeight(
|
|
|
77
87
|
export async function poll(
|
|
78
88
|
th: Encoded.TxHash,
|
|
79
89
|
{
|
|
80
|
-
blocks = 5, interval,
|
|
90
|
+
blocks = 5, interval, ...options
|
|
81
91
|
}:
|
|
82
92
|
{ blocks?: number; interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],
|
|
83
93
|
): Promise<TransformNodeType<SignedTx>> {
|
|
84
|
-
interval ??= _getPollInterval('
|
|
94
|
+
interval ??= await _getPollInterval('micro-block', options);
|
|
85
95
|
let max;
|
|
86
96
|
do {
|
|
87
|
-
const tx = await onNode.getTransactionByHash(th);
|
|
97
|
+
const tx = await options.onNode.getTransactionByHash(th);
|
|
88
98
|
if (tx.blockHeight !== -1) return tx;
|
|
89
99
|
if (max == null) {
|
|
90
100
|
max = tx.tx.ttl !== 0 ? -1
|
|
91
|
-
: await getHeight({ ...options,
|
|
101
|
+
: await getHeight({ ...options, cached: true }) + blocks;
|
|
92
102
|
}
|
|
93
103
|
await pause(interval);
|
|
94
|
-
} while (max === -1 ? true : await getHeight({ ...options,
|
|
104
|
+
} while (max === -1 ? true : await getHeight({ ...options, cached: true }) < max);
|
|
95
105
|
throw new TxTimedOutError(blocks, th);
|
|
96
106
|
}
|
|
97
107
|
|
|
@@ -106,14 +116,14 @@ export async function poll(
|
|
|
106
116
|
*/
|
|
107
117
|
export async function awaitHeight(
|
|
108
118
|
height: number,
|
|
109
|
-
{ interval,
|
|
119
|
+
{ interval, ...options }:
|
|
110
120
|
{ interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],
|
|
111
121
|
): Promise<number> {
|
|
112
|
-
interval ??= Math.min(_getPollInterval('block', options), 5000);
|
|
122
|
+
interval ??= Math.min(await _getPollInterval('key-block', options), 5000);
|
|
113
123
|
let currentHeight;
|
|
114
124
|
do {
|
|
115
125
|
if (currentHeight != null) await pause(interval);
|
|
116
|
-
currentHeight = await getHeight(
|
|
126
|
+
currentHeight = await getHeight(options);
|
|
117
127
|
} while (currentHeight < height);
|
|
118
128
|
return currentHeight;
|
|
119
129
|
}
|
package/src/channel/Base.ts
CHANGED
|
@@ -257,7 +257,7 @@ export default class Channel {
|
|
|
257
257
|
* })
|
|
258
258
|
* ```
|
|
259
259
|
*/
|
|
260
|
-
async leave(): Promise<{ channelId: Encoded.
|
|
260
|
+
async leave(): Promise<{ channelId: Encoded.Channel; signedTx: Encoded.Transaction }> {
|
|
261
261
|
return this.enqueueAction(() => {
|
|
262
262
|
notify(this, 'channels.leave');
|
|
263
263
|
return { handler: handlers.awaitingLeave };
|
package/src/channel/internal.ts
CHANGED
|
@@ -52,7 +52,7 @@ export type SignTx = (tx: Encoded.Transaction, options?: SignOptions) => (
|
|
|
52
52
|
/**
|
|
53
53
|
* @see {@link https://github.com/aeternity/protocol/blob/6734de2e4c7cce7e5e626caa8305fb535785131d/node/api/channels_api_usage.md#channel-establishing-parameters}
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
interface CommonChannelOptions {
|
|
56
56
|
existingFsmId?: Encoded.Bytearray;
|
|
57
57
|
/**
|
|
58
58
|
* Channel url (for example: "ws://localhost:3001")
|
|
@@ -74,7 +74,7 @@ export interface ChannelOptions {
|
|
|
74
74
|
/**
|
|
75
75
|
* Initial deposit in favour of the responder by the initiator
|
|
76
76
|
*/
|
|
77
|
-
pushAmount: number;
|
|
77
|
+
pushAmount: BigNumber | number;
|
|
78
78
|
/**
|
|
79
79
|
* Amount of coins the initiator has committed to the channel
|
|
80
80
|
*/
|
|
@@ -92,17 +92,9 @@ export interface ChannelOptions {
|
|
|
92
92
|
*/
|
|
93
93
|
ttl?: number;
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
96
|
-
*/
|
|
97
|
-
host: string;
|
|
98
|
-
/**
|
|
99
|
-
* The port of the responders node
|
|
95
|
+
* The port of the responder's node
|
|
100
96
|
*/
|
|
101
97
|
port: number;
|
|
102
|
-
/**
|
|
103
|
-
* Participant role
|
|
104
|
-
*/
|
|
105
|
-
role: 'initiator' | 'responder';
|
|
106
98
|
/**
|
|
107
99
|
* How to calculate minimum depth (default: txfee)
|
|
108
100
|
*/
|
|
@@ -120,16 +112,16 @@ export interface ChannelOptions {
|
|
|
120
112
|
*/
|
|
121
113
|
gasPrice?: BigNumber | number;
|
|
122
114
|
|
|
123
|
-
signedTx?:
|
|
115
|
+
signedTx?: Encoded.Transaction;
|
|
124
116
|
/**
|
|
125
117
|
* Existing channel id (required if reestablishing a channel)
|
|
126
118
|
*/
|
|
127
|
-
existingChannelId?:
|
|
119
|
+
existingChannelId?: Encoded.Channel;
|
|
128
120
|
/**
|
|
129
121
|
* Offchain transaction (required if reestablishing a channel)
|
|
130
122
|
*/
|
|
131
|
-
offChainTx?:
|
|
132
|
-
reconnectTx?:
|
|
123
|
+
offChainTx?: Encoded.Transaction;
|
|
124
|
+
reconnectTx?: Encoded.Transaction;
|
|
133
125
|
/**
|
|
134
126
|
* The time waiting for a new event to be initiated (default: 600000)
|
|
135
127
|
*/
|
|
@@ -174,7 +166,6 @@ export interface ChannelOptions {
|
|
|
174
166
|
* Applicable only for responder (default: timeout_idle's value)
|
|
175
167
|
*/
|
|
176
168
|
timeoutAwaitingOpen?: number;
|
|
177
|
-
statePassword?: string;
|
|
178
169
|
/**
|
|
179
170
|
* Log websocket communication and state changes
|
|
180
171
|
*/
|
|
@@ -183,9 +174,25 @@ export interface ChannelOptions {
|
|
|
183
174
|
* Function which verifies and signs transactions
|
|
184
175
|
*/
|
|
185
176
|
sign: SignTxWithTag;
|
|
186
|
-
offchainTx?:
|
|
177
|
+
offchainTx?: Encoded.Transaction;
|
|
187
178
|
}
|
|
188
179
|
|
|
180
|
+
export type ChannelOptions = CommonChannelOptions & ({
|
|
181
|
+
/**
|
|
182
|
+
* Participant role
|
|
183
|
+
*/
|
|
184
|
+
role: 'initiator';
|
|
185
|
+
/**
|
|
186
|
+
* Host of the responder's node
|
|
187
|
+
*/
|
|
188
|
+
host: string;
|
|
189
|
+
} | {
|
|
190
|
+
/**
|
|
191
|
+
* Participant role
|
|
192
|
+
*/
|
|
193
|
+
role: 'responder';
|
|
194
|
+
});
|
|
195
|
+
|
|
189
196
|
export interface ChannelHandler extends Function {
|
|
190
197
|
enter?: Function;
|
|
191
198
|
}
|
package/src/contract/Contract.ts
CHANGED
|
@@ -171,6 +171,9 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
171
171
|
break;
|
|
172
172
|
case 'error':
|
|
173
173
|
message = decode(returnValue).toString();
|
|
174
|
+
if (/Expected \d+ arguments, got \d+/.test(message)) {
|
|
175
|
+
throw new ContractError(`ACI doesn't match called contract. Error provided by node: ${message}`);
|
|
176
|
+
}
|
|
174
177
|
break;
|
|
175
178
|
default:
|
|
176
179
|
throw new InternalError(`Unknown return type: ${returnType}`);
|
package/src/oracle.ts
CHANGED
|
@@ -34,13 +34,12 @@ type OracleQueries = Awaited<ReturnType<Node['getOracleQueriesByPubkey']>>['orac
|
|
|
34
34
|
export function pollForQueries(
|
|
35
35
|
oracleId: Encoded.OracleAddress,
|
|
36
36
|
onQuery: (query: OracleQueries[number]) => void,
|
|
37
|
-
{ interval,
|
|
37
|
+
{ interval, ...options }: { interval?: number; onNode: Node }
|
|
38
38
|
& Parameters<typeof _getPollInterval>[1],
|
|
39
39
|
): () => void {
|
|
40
|
-
interval ??= _getPollInterval('microblock', options);
|
|
41
40
|
const knownQueryIds = new Set();
|
|
42
41
|
const checkNewQueries = async (): Promise<void> => {
|
|
43
|
-
const queries = ((await onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries ?? [])
|
|
42
|
+
const queries = ((await options.onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries ?? [])
|
|
44
43
|
.filter(({ id }) => !knownQueryIds.has(id));
|
|
45
44
|
queries.forEach((query) => {
|
|
46
45
|
knownQueryIds.add(query.id);
|
|
@@ -52,6 +51,7 @@ export function pollForQueries(
|
|
|
52
51
|
|
|
53
52
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
54
53
|
(async () => {
|
|
54
|
+
interval ??= await _getPollInterval('micro-block', options);
|
|
55
55
|
while (!stopped) { // eslint-disable-line no-unmodified-loop-condition
|
|
56
56
|
// TODO: allow to handle this error somehow
|
|
57
57
|
await checkNewQueries().catch(console.error);
|
|
@@ -74,19 +74,19 @@ export function pollForQueries(
|
|
|
74
74
|
export async function pollForQueryResponse(
|
|
75
75
|
oracleId: Encoded.OracleAddress,
|
|
76
76
|
queryId: Encoded.OracleQueryId,
|
|
77
|
-
{ interval,
|
|
77
|
+
{ interval, ...options }:
|
|
78
78
|
{ interval?: number; onNode: Node } & Parameters<typeof _getPollInterval>[1],
|
|
79
79
|
): Promise<string> {
|
|
80
|
-
interval ??= _getPollInterval('
|
|
80
|
+
interval ??= await _getPollInterval('micro-block', options);
|
|
81
81
|
let height;
|
|
82
82
|
let ttl;
|
|
83
83
|
let response;
|
|
84
84
|
do {
|
|
85
|
-
({ response, ttl } = await onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId));
|
|
85
|
+
({ response, ttl } = await options.onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId));
|
|
86
86
|
const responseBuffer = decode(response as Encoded.OracleResponse);
|
|
87
87
|
if (responseBuffer.length > 0) return responseBuffer.toString();
|
|
88
88
|
await pause(interval);
|
|
89
|
-
height = await getHeight({ ...options,
|
|
89
|
+
height = await getHeight({ ...options, cached: true });
|
|
90
90
|
} while (ttl >= height);
|
|
91
91
|
throw new RequestTimedOutError(height);
|
|
92
92
|
}
|
|
@@ -1,70 +1,67 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import coinAmount from './coin-amount';
|
|
3
|
-
import { ArgumentError, IllegalArgumentError } from '../../../utils/errors';
|
|
4
|
-
import { Int, MIN_GAS_PRICE } from '../constants';
|
|
5
|
-
import Node from '../../../Node';
|
|
6
|
-
import { AE_AMOUNT_FORMATS, formatAmount } from '../../../utils/amount-formatter';
|
|
7
|
-
import semverSatisfies from '../../../utils/semver-satisfies';
|
|
8
|
-
|
|
9
|
-
const gasPriceCache: WeakMap<Node, { time: number; gasPrice: bigint }> = new WeakMap();
|
|
10
|
-
|
|
11
|
-
export async function getCachedIncreasedGasPrice(node: Node): Promise<bigint> {
|
|
12
|
-
const cache = gasPriceCache.get(node);
|
|
13
|
-
if (cache != null && cache.time > Date.now() - 20 * 1000) {
|
|
14
|
-
return cache.gasPrice;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// TODO: remove after requiring node@6.13.0
|
|
18
|
-
const { nodeVersion } = await node._getCachedStatus();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return value;
|
|
69
|
-
},
|
|
70
|
-
};
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import coinAmount from './coin-amount';
|
|
3
|
+
import { ArgumentError, IllegalArgumentError } from '../../../utils/errors';
|
|
4
|
+
import { Int, MIN_GAS_PRICE } from '../constants';
|
|
5
|
+
import Node from '../../../Node';
|
|
6
|
+
import { AE_AMOUNT_FORMATS, formatAmount } from '../../../utils/amount-formatter';
|
|
7
|
+
import semverSatisfies from '../../../utils/semver-satisfies';
|
|
8
|
+
|
|
9
|
+
const gasPriceCache: WeakMap<Node, { time: number; gasPrice: bigint }> = new WeakMap();
|
|
10
|
+
|
|
11
|
+
export async function getCachedIncreasedGasPrice(node: Node): Promise<bigint> {
|
|
12
|
+
const cache = gasPriceCache.get(node);
|
|
13
|
+
if (cache != null && cache.time > Date.now() - 20 * 1000) {
|
|
14
|
+
return cache.gasPrice;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// TODO: remove after requiring node@6.13.0
|
|
18
|
+
const { nodeVersion } = await node._getCachedStatus();
|
|
19
|
+
if (!semverSatisfies(nodeVersion, '6.13.0')) return 0n;
|
|
20
|
+
|
|
21
|
+
const { minGasPrice, utilization } = (await node.getRecentGasPrices())[0];
|
|
22
|
+
let gasPrice = utilization < 70 ? 0n : BigInt(
|
|
23
|
+
new BigNumber(minGasPrice.toString()).times(1.01).integerValue().toFixed(),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const maxSafeGasPrice = BigInt(MIN_GAS_PRICE) * 100000n; // max microblock fee is 600ae or 35usd
|
|
27
|
+
if (gasPrice > maxSafeGasPrice) {
|
|
28
|
+
console.warn([
|
|
29
|
+
`Estimated gas price ${gasPrice} exceeds the maximum safe value for unknown reason.`,
|
|
30
|
+
`It will be limited to ${maxSafeGasPrice}.`,
|
|
31
|
+
'To overcome this restriction provide `gasPrice`/`fee` in options.',
|
|
32
|
+
].join(' '));
|
|
33
|
+
gasPrice = maxSafeGasPrice;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
gasPriceCache.set(node, { gasPrice, time: Date.now() });
|
|
37
|
+
return gasPrice;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// TODO: use withFormatting after using a single type for coins representation
|
|
41
|
+
export default {
|
|
42
|
+
...coinAmount,
|
|
43
|
+
|
|
44
|
+
async prepare(
|
|
45
|
+
value: Int | undefined,
|
|
46
|
+
params: {},
|
|
47
|
+
{ onNode, denomination }: {
|
|
48
|
+
onNode?: Node;
|
|
49
|
+
denomination?: AE_AMOUNT_FORMATS;
|
|
50
|
+
},
|
|
51
|
+
): Promise<Int | undefined> {
|
|
52
|
+
if (value != null) return value;
|
|
53
|
+
if (onNode == null) {
|
|
54
|
+
throw new ArgumentError('onNode', 'provided (or provide `gasPrice` instead)', onNode);
|
|
55
|
+
}
|
|
56
|
+
const gasPrice = await getCachedIncreasedGasPrice(onNode);
|
|
57
|
+
if (gasPrice === 0n) return undefined;
|
|
58
|
+
return formatAmount(gasPrice, { targetDenomination: denomination });
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
serializeAettos(value: string | undefined = MIN_GAS_PRICE.toString()): string {
|
|
62
|
+
if (+value < MIN_GAS_PRICE) {
|
|
63
|
+
throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger than ${MIN_GAS_PRICE}`);
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
@@ -23,7 +23,7 @@ export default {
|
|
|
23
23
|
onNode?: Node;
|
|
24
24
|
absoluteTtl?: boolean;
|
|
25
25
|
_isInternalBuild?: boolean;
|
|
26
|
-
} & Parameters<typeof _getPollInterval>[1],
|
|
26
|
+
} & Omit<Parameters<typeof _getPollInterval>[1], 'onNode'>,
|
|
27
27
|
) {
|
|
28
28
|
if (absoluteTtl !== true && value !== 0 && (value != null || _isInternalBuild === true)) {
|
|
29
29
|
if (onNode == null) throw new ArgumentError('onNode', 'provided', onNode);
|
|
@@ -70,6 +70,15 @@ export function nameToPunycode(maybeName: string): AensName {
|
|
|
70
70
|
if (/\p{Emoji_Presentation}/u.test(name)) {
|
|
71
71
|
throw new ArgumentError('aens name', 'not containing emoji', maybeName);
|
|
72
72
|
}
|
|
73
|
+
if (name[2] === '-' && name[3] === '-') {
|
|
74
|
+
throw new ArgumentError('aens name', 'without "-" char in both the third and fourth positions', maybeName);
|
|
75
|
+
}
|
|
76
|
+
if (name[0] === '-') {
|
|
77
|
+
throw new ArgumentError('aens name', 'starting with no "-" char', maybeName);
|
|
78
|
+
}
|
|
79
|
+
if (name.at(-1) === '-') {
|
|
80
|
+
throw new ArgumentError('aens name', 'ending with no "-" char', maybeName);
|
|
81
|
+
}
|
|
73
82
|
let punycode;
|
|
74
83
|
try {
|
|
75
84
|
const u = new URL(`http://${name}.${suffix}`);
|
package/src/utils/hd-wallet.ts
CHANGED
|
@@ -2,7 +2,9 @@ import nacl from 'tweetnacl';
|
|
|
2
2
|
import { full as hmac } from 'tweetnacl-auth';
|
|
3
3
|
import { fromString } from 'bip32-path';
|
|
4
4
|
import aesjs from 'aes-js';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
sha256hash, encode, Encoding, Encoded,
|
|
7
|
+
} from './encoder';
|
|
6
8
|
import { CryptographyError } from './errors';
|
|
7
9
|
import { concatBuffers } from './other';
|
|
8
10
|
|
|
@@ -58,8 +60,8 @@ interface HDWallet {
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
interface Account {
|
|
61
|
-
secretKey: string;
|
|
62
|
-
publicKey:
|
|
63
|
+
secretKey: string; // TODO: use Encoded.AccountSecretKey instead hex
|
|
64
|
+
publicKey: Encoded.AccountAddress;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
type Dec<N extends number> = [-1, 0, 1, 2, 3, 4][N];
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
version: string,
|
|
3
|
-
geVersion: string,
|
|
4
|
-
ltVersion: string,
|
|
5
|
-
): boolean {
|
|
1
|
+
function verCmp(a: string, b: string): number {
|
|
6
2
|
const getComponents = (v: string): number[] => v
|
|
7
3
|
.split(/[-+]/)[0].split('.').map((i) => +i);
|
|
8
4
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const ltComponents = getComponents(ltVersion);
|
|
5
|
+
const aComponents = getComponents(a);
|
|
6
|
+
const bComponents = getComponents(b);
|
|
12
7
|
|
|
13
|
-
const base = Math.max(...
|
|
8
|
+
const base = Math.max(...aComponents, ...bComponents) + 1;
|
|
14
9
|
const componentsToNumber = (components: number[]): number => components.reverse()
|
|
15
10
|
.reduce((acc, n, idx) => acc + n * base ** idx, 0);
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
return componentsToNumber(aComponents) - componentsToNumber(bComponents);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default function semverSatisfies(
|
|
16
|
+
version: string,
|
|
17
|
+
geVersion: string,
|
|
18
|
+
ltVersion?: string,
|
|
19
|
+
): boolean {
|
|
20
|
+
return verCmp(version, geVersion) >= 0
|
|
21
|
+
&& (ltVersion == null || verCmp(version, ltVersion) < 0);
|
|
21
22
|
}
|