@aeternity/aepp-sdk 11.0.0 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/aepp-sdk.browser-script.js +1 -1
  2. package/dist/aepp-sdk.browser-script.js.map +1 -1
  3. package/dist/aepp-sdk.browser.js +1 -1
  4. package/dist/aepp-sdk.browser.js.map +1 -1
  5. package/dist/aepp-sdk.js +1 -1
  6. package/dist/aepp-sdk.js.map +1 -1
  7. package/es/ae/contract.mjs +1 -1
  8. package/es/ae/contract.mjs.map +1 -1
  9. package/es/channel/index.mjs +1 -1
  10. package/es/channel/index.mjs.map +1 -1
  11. package/es/channel/internal.mjs +3 -4
  12. package/es/channel/internal.mjs.map +1 -1
  13. package/es/contract/aci.mjs +1 -1
  14. package/es/contract/aci.mjs.map +1 -1
  15. package/es/encoder.d.ts +26 -0
  16. package/es/tx/builder/constants.mjs +108 -0
  17. package/es/tx/builder/constants.mjs.map +1 -0
  18. package/es/tx/builder/helpers.mjs +10 -52
  19. package/es/tx/builder/helpers.mjs.map +1 -1
  20. package/es/tx/builder/schema.mjs +4 -107
  21. package/es/tx/builder/schema.mjs.map +1 -1
  22. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +1 -1
  23. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -1
  24. package/es/utils/crypto.mjs +2 -12
  25. package/es/utils/crypto.mjs.map +1 -1
  26. package/es/utils/encoder.mjs +106 -0
  27. package/es/utils/encoder.mjs.map +1 -0
  28. package/package.json +4 -2
  29. package/src/ae/contract.js +1 -1
  30. package/src/channel/index.js +6 -1
  31. package/src/channel/internal.js +5 -6
  32. package/src/contract/aci.js +1 -1
  33. package/src/tx/builder/constants.js +100 -0
  34. package/src/tx/builder/helpers.js +7 -53
  35. package/src/tx/builder/schema.js +1 -98
  36. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -1
  37. package/src/utils/crypto.js +2 -12
  38. package/src/utils/encoder.ts +101 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/crypto.js"],"names":["nacl","aesjs","shajs","str2buf","encode","decode","hash","NotImplementedError","Ecb","ModeOfOperation","ecb","getAddressFromPriv","secret","keys","sign","keyPair","fromSecretKey","publicBuffer","from","publicKey","isAddressValid","address","prefix","e","sha256hash","input","update","digest","salt","Math","floor","random","Number","MAX_SAFE_INTEGER","encodeUnsigned","value","binary","allocUnsafe","writeUInt32BE","slice","findIndex","i","encodeContractAddress","owner","nonce","concat","generateKeyPairFromSecret","generateKeyPair","raw","secretBuffer","secretKey","toString","encryptKey","password","binaryData","hashedPasswordBytes","aesEcb","encrypt","decryptKey","encrypted","encryptedBytes","decrypt","data","privateKey","detached","verify","str","signature","Uint8Array","messageToHash","message","p","msg","length","signMessage","verifyMessage","isValidKeypair"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AAEA,OAAOA,IAAP,MAAiB,WAAjB;AACA,OAAOC,KAAP,MAAkB,QAAlB;AACA,OAAOC,KAAP,MAAkB,QAAlB;SAESC,O;SACAC,M,EAAQC,M;SACRC,I;SACAC,mB;;AAIT,MAAMC,GAAG,GAAGP,KAAK,CAACQ,eAAN,CAAsBC,GAAlC;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,kBAAT,CAA6BC,MAA7B,EAAqC;AAC1C,QAAMC,IAAI,GAAGb,IAAI,CAACc,IAAL,CAAUC,OAAV,CAAkBC,aAAlB,CAAgCb,OAAO,CAACS,MAAD,CAAvC,CAAb;;AACA,QAAMK,YAAY,GAAG,QAAOC,IAAP,CAAYL,IAAI,CAACM,SAAjB,CAArB;;AACA,SAAOf,MAAM,CAACa,YAAD,EAAe,IAAf,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SA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tB,EAA+BP,UAA/B,EAA2C;AAChD,SAAOjD,IAAI,CAACuD,aAAa,CAACC,OAAD,CAAd,EAAyBP,UAAzB,CAAX;AACD;AAED,OAAO,SAASY,aAAT,CAAwBT,GAAxB,EAA6BC,SAA7B,EAAwChD,SAAxC,EAAmD;AACxD,SAAO8C,MAAM,CAACI,aAAa,CAACH,GAAD,CAAd,EAAqBC,SAArB,EAAgChD,SAAhC,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASyD,cAAT,CAAyBb,UAAzB,EAAqC5C,SAArC,EAAgD;AACrD,QAAMmD,OAAO,GAAG,QAAOpD,IAAP,CAAY,YAAZ,CAAhB;;AACA,QAAMiD,SAAS,GAAGrD,IAAI,CAACwD,OAAD,EAAUP,UAAV,CAAtB;AACA,SAAOE,MAAM,CAACK,OAAD,EAAUH,SAAV,EAAqBhD,SAArB,CAAb;AACD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Crypto module\n * @module @aeternity/aepp-sdk/es/utils/crypto\n * @example import { Crypto } from '@aeternity/aepp-sdk'\n */\n\nimport nacl from 'tweetnacl'\nimport aesjs from 'aes-js'\nimport shajs from 'sha.js'\n\nimport { str2buf } from './bytes'\nimport { encode, decode } from '../tx/builder/helpers'\nimport { hash } from './crypto-ts'\nimport { NotImplementedError } from './errors'\n\nexport * from './crypto-ts'\n\nconst Ecb = aesjs.ModeOfOperation.ecb\n\n/**\n * Generate address from secret key\n * @rtype (secret: String) => tx: Promise[String]\n * @param {String} secret - Private key\n * @return {String} Public key\n */\nexport function getAddressFromPriv (secret) {\n const keys = nacl.sign.keyPair.fromSecretKey(str2buf(secret))\n const publicBuffer = Buffer.from(keys.publicKey)\n return encode(publicBuffer, 'ak')\n}\n\n/**\n * Check if address is valid\n * @rtype (input: String) => valid: Boolean\n * @param {String} address - Address\n * @param {String} prefix Transaction prefix. Default: 'ak'\n * @return {Boolean} valid\n */\nexport function isAddressValid (address, prefix = 'ak') {\n try {\n decode(address, prefix)\n return true\n } catch (e) {\n return false\n }\n}\n\n/**\n * Calculate SHA256 hash of `input`\n * @rtype (input: String) => hash: String\n * @param {String} input - Data to hash\n * @return {String} Hash\n */\nexport function sha256hash (input) {\n return shajs('sha256').update(input).digest()\n}\n\n/**\n * Generate a random salt (positive integer)\n * @rtype () => salt: Number\n * @return {Number} random salt\n */\nexport function salt () {\n return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER))\n}\n\n/**\n * Converts a positive integer to the smallest possible\n * representation in a binary digit representation\n * @rtype (value: Number) => Buffer\n * @param {Number} value - Value to encode\n * @return {Buffer} - Encoded data\n */\nexport function encodeUnsigned (value) {\n const binary = Buffer.allocUnsafe(4)\n binary.writeUInt32BE(value)\n return binary.slice(binary.findIndex(i => i !== 0))\n}\n\n// Todo Duplicated in tx builder. remove\n/**\n * Compute contract address\n * @rtype (owner: String, nonce: Number) => String\n * @param {String} owner - Address of contract owner\n * @param {Number} nonce - Round when contract was created\n * @return {String} - Contract address\n */\nexport function encodeContractAddress (owner, nonce) {\n const publicKey = decode(owner, 'ak')\n const binary = Buffer.concat([publicKey, encodeUnsigned(nonce)])\n return encode(hash(binary), 'ct')\n}\n\n// KEY-PAIR HELPERS\n\n/**\n * Generate keyPair from secret key\n * @rtype (secret: Uint8Array) => KeyPair\n * @param {Uint8Array} secret - secret key\n * @return {Object} - Object with Private(privateKey) and Public(publicKey) keys\n */\nexport function generateKeyPairFromSecret (secret) {\n return nacl.sign.keyPair.fromSecretKey(secret)\n}\n\n/**\n * Generate a random ED25519 keypair\n * @rtype (raw: Boolean) => {publicKey: String | Buffer, secretKey: String | Buffer}\n * @param {Boolean} raw - Whether to return raw (binary) keys\n * @return {Object} Key pair\n */\nexport function generateKeyPair (raw = false) {\n // <node>/apps/aens/test/aens_test_utils.erl\n const keyPair = nacl.sign.keyPair()\n\n const publicBuffer = Buffer.from(keyPair.publicKey)\n const secretBuffer = Buffer.from(keyPair.secretKey)\n\n if (raw) {\n return {\n publicKey: publicBuffer,\n secretKey: secretBuffer\n }\n } else {\n return {\n publicKey: encode(publicBuffer, 'ak'),\n secretKey: secretBuffer.toString('hex')\n }\n }\n}\n\n/**\n * Encrypt given data using `password`\n * @rtype (password: String, binaryData: Buffer) => Uint8Array\n * @param {String} password - Password to encrypt with\n * @param {Buffer} binaryData - Data to encrypt\n * @return {Uint8Array} Encrypted data\n */\nexport function encryptKey (password, binaryData) {\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 * @rtype (password: String, encrypted: String) => Uint8Array\n * @param {String} password - Password to decrypt with\n * @param {String} encrypted - Data to decrypt\n * @return {Buffer} Decrypted data\n */\nexport function decryptKey (password, encrypted) {\n const encryptedBytes = Buffer.from(encrypted)\n const hashedPasswordBytes = sha256hash(password)\n const aesEcb = new Ecb(hashedPasswordBytes)\n return Buffer.from(aesEcb.decrypt(encryptedBytes))\n}\n\n// SIGNATURES\n\n/**\n * Generate signature\n * @rtype (data: String|Buffer, privateKey: Buffer) => Buffer\n * @param {String|Buffer} data - Data to sign\n * @param {String|Buffer} privateKey - Key to sign with\n * @return {Buffer|Uint8Array} Signature\n */\nexport function sign (data, privateKey) {\n return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey))\n}\n\n/**\n * Verify that signature was signed by public key\n * @rtype (str: String, signature: Buffer, publicKey: Buffer) => Boolean\n * @param {String|Buffer} str - Data to verify\n * @param {Buffer} signature - Signature to verify\n * @param {Buffer} publicKey - Key to verify against\n * @return {Boolean} Valid?\n */\nexport function verify (str, signature, publicKey) {\n return nacl.sign.detached.verify(new Uint8Array(str), signature, publicKey)\n}\n\nexport function messageToHash (message) {\n const p = Buffer.from('aeternity Signed Message:\\n', 'utf8')\n const msg = Buffer.from(message, 'utf8')\n if (msg.length >= 0xFD) throw new NotImplementedError('Message too long')\n return hash(Buffer.concat([Buffer.from([p.length]), p, Buffer.from([msg.length]), msg]))\n}\n\nexport function signMessage (message, privateKey) {\n return sign(messageToHash(message), privateKey)\n}\n\nexport function verifyMessage (str, signature, publicKey) {\n return verify(messageToHash(str), signature, publicKey)\n}\n\n/**\n * Check key pair for validity\n *\n * Sign a message, and then verifying that signature\n * @rtype (privateKey: Buffer, publicKey: Buffer) => Boolean\n * @param {Buffer} privateKey - Private key to verify\n * @param {Buffer} publicKey - Public key to verify\n * @return {Boolean} Valid?\n */\nexport function isValidKeypair (privateKey, publicKey) {\n const message = Buffer.from('TheMessage')\n const signature = sign(message, privateKey)\n return verify(message, signature, publicKey)\n}\n"],"file":"crypto.mjs"}
1
+ {"version":3,"sources":["../../src/utils/crypto.js"],"names":["nacl","aesjs","str2buf","encode","decode","sha256hash","hash","NotImplementedError","Ecb","ModeOfOperation","ecb","getAddressFromPriv","secret","keys","sign","keyPair","fromSecretKey","publicBuffer","from","publicKey","isAddressValid","address","prefix","e","salt","Math","floor","random","Number","MAX_SAFE_INTEGER","encodeUnsigned","value","binary","allocUnsafe","writeUInt32BE","slice","findIndex","i","encodeContractAddress","owner","nonce","concat","generateKeyPairFromSecret","generateKeyPair","raw","secretBuffer","secretKey","toString","encryptKey","password","binaryData","hashedPasswordBytes","aesEcb","encrypt","decryptKey","encrypted","encryptedBytes","decrypt","data","privateKey","detached","verify","str","signature","Uint8Array","messageToHash","message","p","msg","length","signMessage","verifyMessage","isValidKeypair"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AAEA,OAAOA,IAAP,MAAiB,WAAjB;AACA,OAAOC,KAAP,MAAkB,QAAlB;SAESC,O;SACAC,M,EAAQC,M,EAAQC,U;SAChBC,I;SACAC,mB;;AAGT,SAASF,UAAT;AAEA,MAAMG,GAAG,GAAGP,KAAK,CAACQ,eAAN,CAAsBC,GAAlC;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,kBAAT,CAA6BC,MAA7B,EAAqC;AAC1C,QAAMC,IAAI,GAAGb,IAAI,CAACc,IAAL,CAAUC,OAAV,CAAkBC,aAAlB,CAAgCd,OAAO,CAACU,MAAD,CAAvC,CAAb;;AACA,QAAMK,YAAY,GAAG,QAAOC,IAAP,CAAYL,IAAI,CAACM,SAAjB,CAArB;;AACA,SAAOhB,MAAM,CAACc,YAAD,EAAe,IAAf,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,cAAT,CAAyBC,OAAzB,EAAiD;AAAA,MAAfC,MAAe,uEAAN,IAAM;;AACtD,MAAI;AACFlB,IAAAA,MAAM,CAACiB,OAAD,EAAUC,MAAV,CAAN;AACA,WAAO,IAAP;AACD,GAHD,CAGE,OAAOC,CAAP,EAAU;AACV,WAAO,KAAP;AACD;AACF;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,IAAT,GAAiB;AACtB,SAAOC,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACE,MAAL,KAAgBF,IAAI,CAACC,KAAL,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;AACA,SAAOE,MAAM,CAACK,OAAD,EAAUH,SAAV,EAAqB5C,SAArB,CAAb;AACD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Crypto module\n * @module @aeternity/aepp-sdk/es/utils/crypto\n * @example import { Crypto } from '@aeternity/aepp-sdk'\n */\n\nimport nacl from 'tweetnacl'\nimport aesjs from 'aes-js'\n\nimport { str2buf } from './bytes'\nimport { encode, decode, sha256hash } from './encoder'\nimport { hash } from './crypto-ts'\nimport { NotImplementedError } from './errors'\n\nexport * from './crypto-ts'\nexport { sha256hash }\n\nconst Ecb = aesjs.ModeOfOperation.ecb\n\n/**\n * Generate address from secret key\n * @rtype (secret: String) => tx: Promise[String]\n * @param {String} secret - Private key\n * @return {String} Public key\n */\nexport function getAddressFromPriv (secret) {\n const keys = nacl.sign.keyPair.fromSecretKey(str2buf(secret))\n const publicBuffer = Buffer.from(keys.publicKey)\n return encode(publicBuffer, 'ak')\n}\n\n/**\n * Check if address is valid\n * @rtype (input: String) => valid: Boolean\n * @param {String} address - Address\n * @param {String} prefix Transaction prefix. Default: 'ak'\n * @return {Boolean} valid\n */\nexport function isAddressValid (address, prefix = 'ak') {\n try {\n decode(address, prefix)\n return true\n } catch (e) {\n return false\n }\n}\n\n/**\n * Generate a random salt (positive integer)\n * @rtype () => salt: Number\n * @return {Number} random salt\n */\nexport function salt () {\n return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER))\n}\n\n/**\n * Converts a positive integer to the smallest possible\n * representation in a binary digit representation\n * @rtype (value: Number) => Buffer\n * @param {Number} value - Value to encode\n * @return {Buffer} - Encoded data\n */\nexport function encodeUnsigned (value) {\n const binary = Buffer.allocUnsafe(4)\n binary.writeUInt32BE(value)\n return binary.slice(binary.findIndex(i => i !== 0))\n}\n\n// Todo Duplicated in tx builder. remove\n/**\n * Compute contract address\n * @rtype (owner: String, nonce: Number) => String\n * @param {String} owner - Address of contract owner\n * @param {Number} nonce - Round when contract was created\n * @return {String} - Contract address\n */\nexport function encodeContractAddress (owner, nonce) {\n const publicKey = decode(owner, 'ak')\n const binary = Buffer.concat([publicKey, encodeUnsigned(nonce)])\n return encode(hash(binary), 'ct')\n}\n\n// KEY-PAIR HELPERS\n\n/**\n * Generate keyPair from secret key\n * @rtype (secret: Uint8Array) => KeyPair\n * @param {Uint8Array} secret - secret key\n * @return {Object} - Object with Private(privateKey) and Public(publicKey) keys\n */\nexport function generateKeyPairFromSecret (secret) {\n return nacl.sign.keyPair.fromSecretKey(secret)\n}\n\n/**\n * Generate a random ED25519 keypair\n * @rtype (raw: Boolean) => {publicKey: String | Buffer, secretKey: String | Buffer}\n * @param {Boolean} raw - Whether to return raw (binary) keys\n * @return {Object} Key pair\n */\nexport function generateKeyPair (raw = false) {\n // <node>/apps/aens/test/aens_test_utils.erl\n const keyPair = nacl.sign.keyPair()\n\n const publicBuffer = Buffer.from(keyPair.publicKey)\n const secretBuffer = Buffer.from(keyPair.secretKey)\n\n if (raw) {\n return {\n publicKey: publicBuffer,\n secretKey: secretBuffer\n }\n } else {\n return {\n publicKey: encode(publicBuffer, 'ak'),\n secretKey: secretBuffer.toString('hex')\n }\n }\n}\n\n/**\n * Encrypt given data using `password`\n * @rtype (password: String, binaryData: Buffer) => Uint8Array\n * @param {String} password - Password to encrypt with\n * @param {Buffer} binaryData - Data to encrypt\n * @return {Uint8Array} Encrypted data\n */\nexport function encryptKey (password, binaryData) {\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 * @rtype (password: String, encrypted: String) => Uint8Array\n * @param {String} password - Password to decrypt with\n * @param {String} encrypted - Data to decrypt\n * @return {Buffer} Decrypted data\n */\nexport function decryptKey (password, encrypted) {\n const encryptedBytes = Buffer.from(encrypted)\n const hashedPasswordBytes = sha256hash(password)\n const aesEcb = new Ecb(hashedPasswordBytes)\n return Buffer.from(aesEcb.decrypt(encryptedBytes))\n}\n\n// SIGNATURES\n\n/**\n * Generate signature\n * @rtype (data: String|Buffer, privateKey: Buffer) => Buffer\n * @param {String|Buffer} data - Data to sign\n * @param {String|Buffer} privateKey - Key to sign with\n * @return {Buffer|Uint8Array} Signature\n */\nexport function sign (data, privateKey) {\n return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey))\n}\n\n/**\n * Verify that signature was signed by public key\n * @rtype (str: String, signature: Buffer, publicKey: Buffer) => Boolean\n * @param {String|Buffer} str - Data to verify\n * @param {Buffer} signature - Signature to verify\n * @param {Buffer} publicKey - Key to verify against\n * @return {Boolean} Valid?\n */\nexport function verify (str, signature, publicKey) {\n return nacl.sign.detached.verify(new Uint8Array(str), signature, publicKey)\n}\n\nexport function messageToHash (message) {\n const p = Buffer.from('aeternity Signed Message:\\n', 'utf8')\n const msg = Buffer.from(message, 'utf8')\n if (msg.length >= 0xFD) throw new NotImplementedError('Message too long')\n return hash(Buffer.concat([Buffer.from([p.length]), p, Buffer.from([msg.length]), msg]))\n}\n\nexport function signMessage (message, privateKey) {\n return sign(messageToHash(message), privateKey)\n}\n\nexport function verifyMessage (str, signature, publicKey) {\n return verify(messageToHash(str), signature, publicKey)\n}\n\n/**\n * Check key pair for validity\n *\n * Sign a message, and then verifying that signature\n * @rtype (privateKey: Buffer, publicKey: Buffer) => Boolean\n * @param {Buffer} privateKey - Private key to verify\n * @param {Buffer} publicKey - Public key to verify\n * @return {Boolean} Valid?\n */\nexport function isValidKeypair (privateKey, publicKey) {\n const message = Buffer.from('TheMessage')\n const signature = sign(message, privateKey)\n return verify(message, signature, publicKey)\n}\n"],"file":"crypto.mjs"}
@@ -0,0 +1,106 @@
1
+ import _buffer from "buffer";
2
+ const {
3
+ Buffer: _Buffer
4
+ } = _buffer;
5
+ import * as bs58 from 'bs58';
6
+ import _shaJs from 'sha.js';
7
+ const {
8
+ sha256
9
+ } = _shaJs;
10
+ import { DecodeError, EncodeError, InvalidChecksumError, PayloadLengthError, PrefixMismatchError } from "./errors.mjs";
11
+ /**
12
+ * Calculate SHA256 hash of `input`
13
+ * @rtype (input: String) => hash: String
14
+ * @param {Buffer|String} input - Data to hash
15
+ * @return {String} Hash
16
+ */
17
+
18
+ export function sha256hash(input) {
19
+ return new sha256().update(input).digest();
20
+ } // based on https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md
21
+
22
+ const base64Types = ['ba', 'cb', 'or', 'ov', 'pi', 'ss', 'cs', 'ck', 'cv', 'st', 'tx'];
23
+ const base58Types = ['ak', 'bf', 'bs', 'bx', 'ch', 'cm', 'ct', 'kh', 'mh', 'nm', 'ok', 'oq', 'pp', 'sg', 'th']; // TODO: add all types with a fixed length
24
+
25
+ const typesLength = {
26
+ ak: 32,
27
+ ct: 32,
28
+ ok: 32
29
+ };
30
+
31
+ function ensureValidLength(data, type) {
32
+ if (!typesLength[type]) return;
33
+ if (data.length === typesLength[type]) return;
34
+ throw new PayloadLengthError(`Payload should be ${typesLength[type]} bytes, got ${data.length} instead`);
35
+ }
36
+
37
+ const getChecksum = payload => sha256hash(sha256hash(payload)).slice(0, 4);
38
+
39
+ const addChecksum = input => {
40
+ const payload = _Buffer.from(input);
41
+
42
+ return _Buffer.concat([payload, getChecksum(payload)]);
43
+ };
44
+
45
+ function getPayload(buffer) {
46
+ const payload = buffer.slice(0, -4);
47
+ if (!getChecksum(payload).equals(buffer.slice(-4))) throw new InvalidChecksumError();
48
+ return payload;
49
+ }
50
+
51
+ const base64 = {
52
+ encode: buffer => addChecksum(buffer).toString('base64'),
53
+ decode: string => getPayload(_Buffer.from(string, 'base64'))
54
+ };
55
+ const base58 = {
56
+ encode: buffer => bs58.encode(addChecksum(buffer)),
57
+ decode: string => getPayload(bs58.decode(string))
58
+ };
59
+ /**
60
+ * Decode data using the default encoding/decoding algorithm
61
+ * @function
62
+ * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
63
+ * @param {string} data An Base58/64check encoded and prefixed string (ex tx_..., sg_..., ak_....)
64
+ * @param {string} [requiredPrefix] Ensure that data have this prefix
65
+ * @return {Buffer} Decoded data
66
+ */
67
+
68
+ export function decode(data, requiredPrefix) {
69
+ const [prefix, encodedPayload, extra] = data.split('_');
70
+ if (!encodedPayload) throw new DecodeError(`Encoded string missing payload: ${data}`);
71
+ if (extra) throw new DecodeError(`Encoded string have extra parts: ${data}`);
72
+
73
+ if (requiredPrefix && requiredPrefix !== prefix) {
74
+ throw new PrefixMismatchError(prefix, requiredPrefix);
75
+ }
76
+
77
+ const decoder = base64Types.includes(prefix) && base64.decode || base58Types.includes(prefix) && base58.decode;
78
+
79
+ if (!decoder) {
80
+ throw new DecodeError(`Encoded string have unknown type: ${prefix}`);
81
+ }
82
+
83
+ const payload = decoder(encodedPayload);
84
+ ensureValidLength(payload, prefix);
85
+ return payload;
86
+ }
87
+ /**
88
+ * Encode data using the default encoding/decoding algorithm
89
+ * @function
90
+ * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
91
+ * @param {Buffer|String} data An decoded data
92
+ * @param {string} type Prefix of Transaction
93
+ * @return {String} Encoded string Base58check or Base64check data
94
+ */
95
+
96
+ export function encode(data, type) {
97
+ const encoder = base64Types.includes(type) && base64.encode || base58Types.includes(type) && base58.encode;
98
+
99
+ if (!encoder) {
100
+ throw new EncodeError(`Unknown type: ${type}`);
101
+ }
102
+
103
+ ensureValidLength(data, type);
104
+ return `${type}_${encoder(data)}`;
105
+ }
106
+ //# sourceMappingURL=encoder.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/encoder.ts"],"names":["bs58","DecodeError","EncodeError","InvalidChecksumError","PayloadLengthError","PrefixMismatchError","sha256hash","input","sha256","update","digest","base64Types","base58Types","typesLength","ak","ct","ok","ensureValidLength","data","type","length","getChecksum","payload","slice","addChecksum","from","concat","getPayload","buffer","equals","base64","encode","toString","decode","string","base58","requiredPrefix","prefix","encodedPayload","extra","split","decoder","includes","encoder"],"mappings":";;;;AAAA,OAAO,KAAKA,IAAZ,MAAsB,MAAtB;AACA,mBAAuB,QAAvB;;;;SAEEC,W,EACAC,W,EACAC,oB,EACAC,kB,EACAC,mB;AAGF;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CAAqBC,KAArB,EAA6C;AAClD,SAAO,IAAIC,MAAJ,GAAaC,MAAb,CAAoBF,KAApB,EAA2BG,MAA3B,EAAP;AACD,C,CAED;;AACA,MAAMC,WAAW,GAAG,CAAC,IAAD,EAAO,IAAP,EAAa,IAAb,EAAmB,IAAnB,EAAyB,IAAzB,EAA+B,IAA/B,EAAqC,IAArC,EAA2C,IAA3C,EAAiD,IAAjD,EAAuD,IAAvD,EAA6D,IAA7D,CAApB;AACA,MAAMC,WAAW,GAAG,CAAC,IAAD,EAAO,IAAP,EAAa,IAAb,EAAmB,IAAnB,EAAyB,IAAzB,EAA+B,IAA/B,EAAqC,IAArC,EAA2C,IAA3C,EAAiD,IAAjD,EAAuD,IAAvD,EAA6D,IAA7D,EAAmE,IAAnE,EAAyE,IAAzE,EAA+E,IAA/E,EAAqF,IAArF,CAApB,C,CACA;;AACA,MAAMC,WAAuC,GAAG;AAC9CC,EAAAA,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AASS,MAAT,CAAiBb,IAAjB,EAAwCC,IAAxC,EAAsD;AAC3D,QAAMwB,OAAO,GAAIhC,WAAW,CAAC+B,QAAZ,CAAqBvB,IAArB,KAA8BW,MAAM,CAACC,MAAtC,IACbnB,WAAW,CAAC8B,QAAZ,CAAqBvB,IAArB,KAA8BgB,MAAM,CAACJ,MADxC;;AAEA,MAAI,CAACY,OAAL,EAAc;AACZ,UAAM,IAAIzC,WAAJ,CAAiB,iBAAgBiB,IAAK,EAAtC,CAAN;AACD;;AACDF,EAAAA,iBAAiB,CAACC,IAAD,EAAOC,IAAP,CAAjB;AACA,SAAQ,GAAEA,IAAK,IAAGwB,OAAO,CAACzB,IAAD,CAAO,EAAhC;AACD","sourcesContent":["import * as bs58 from 'bs58'\nimport { sha256 } from 'sha.js'\nimport {\n DecodeError,\n EncodeError,\n InvalidChecksumError,\n PayloadLengthError,\n PrefixMismatchError\n} from './errors'\n\n/**\n * Calculate SHA256 hash of `input`\n * @rtype (input: String) => hash: String\n * @param {Buffer|String} input - Data to hash\n * @return {String} Hash\n */\nexport function sha256hash (input: Buffer | string) {\n return new sha256().update(input).digest()\n}\n\n// based on https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md\nconst base64Types = ['ba', 'cb', 'or', 'ov', 'pi', 'ss', 'cs', 'ck', 'cv', 'st', 'tx']\nconst base58Types = ['ak', 'bf', 'bs', 'bx', 'ch', 'cm', 'ct', 'kh', 'mh', 'nm', 'ok', 'oq', 'pp', 'sg', 'th']\n// TODO: add all types with a fixed length\nconst typesLength: { [name: string]: number } = {\n ak: 32,\n ct: 32,\n ok: 32\n} as const\n\nfunction ensureValidLength (data: Buffer | string, type: string) {\n if (!typesLength[type]) return\n if (data.length === typesLength[type]) return\n throw new PayloadLengthError(`Payload should be ${typesLength[type]} bytes, got ${data.length} instead`)\n}\n\nconst getChecksum = (payload: Buffer | string) => sha256hash(sha256hash(payload)).slice(0, 4)\n\nconst addChecksum = (input: Buffer | string) => {\n const payload = Buffer.from(input)\n return Buffer.concat([payload, getChecksum(payload)])\n}\n\nfunction getPayload (buffer: Buffer) {\n const payload = buffer.slice(0, -4)\n if (!getChecksum(payload).equals(buffer.slice(-4))) throw new InvalidChecksumError()\n return payload\n}\n\nconst base64 = {\n encode: (buffer: Buffer | string) => addChecksum(buffer).toString('base64'),\n decode: (string: string) => getPayload(Buffer.from(string, 'base64'))\n}\n\nconst base58 = {\n encode: (buffer: Buffer | string) => bs58.encode(addChecksum(buffer)),\n decode: (string: string) => getPayload(bs58.decode(string))\n}\n\n/**\n * Decode data using the default encoding/decoding algorithm\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {string} data An Base58/64check encoded and prefixed string (ex tx_..., sg_..., ak_....)\n * @param {string} [requiredPrefix] Ensure that data have this prefix\n * @return {Buffer} Decoded data\n */\nexport function decode (data: string, requiredPrefix?: string) {\n const [prefix, encodedPayload, extra] = data.split('_')\n if (!encodedPayload) throw new DecodeError(`Encoded string missing payload: ${data}`)\n if (extra) throw new DecodeError(`Encoded string have extra parts: ${data}`)\n if (requiredPrefix && requiredPrefix !== prefix) {\n throw new PrefixMismatchError(prefix, requiredPrefix)\n }\n const decoder = (base64Types.includes(prefix) && base64.decode) ||\n (base58Types.includes(prefix) && base58.decode)\n if (!decoder) {\n throw new DecodeError(`Encoded string have unknown type: ${prefix}`)\n }\n const payload = decoder(encodedPayload)\n ensureValidLength(payload, prefix)\n return payload\n}\n\n/**\n * Encode data using the default encoding/decoding algorithm\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Buffer|String} data An decoded data\n * @param {string} type Prefix of Transaction\n * @return {String} Encoded string Base58check or Base64check data\n */\nexport function encode (data: Buffer | string, type: string) {\n const encoder = (base64Types.includes(type) && base64.encode) ||\n (base58Types.includes(type) && base58.encode)\n if (!encoder) {\n throw new EncodeError(`Unknown type: ${type}`)\n }\n ensureValidLength(data, type)\n return `${type}_${encoder(data)}`\n}\n"],"file":"encoder.mjs"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeternity/aepp-sdk",
3
- "version": "11.0.0",
3
+ "version": "11.0.1",
4
4
  "description": "SDK for the æternity blockchain",
5
5
  "main": "dist/aepp-sdk.js",
6
6
  "types": "es/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "test:watch": "mocha './test/unit/' './test/integration/' --watch",
23
23
  "prepare": "npm run build",
24
24
  "prepublishOnly": "npm run docs:examples",
25
- "release": "standard-version --skip.tag"
25
+ "release": "standard-version --skip.tag --infile docs/CHANGELOG.md"
26
26
  },
27
27
  "license": "ISC",
28
28
  "keywords": [
@@ -70,9 +70,11 @@
70
70
  "@commitlint/cli": "^16.1.0",
71
71
  "@commitlint/config-conventional": "^16.0.0",
72
72
  "@types/bn.js": "^5.1.0",
73
+ "@types/bs58": "^4.0.1",
73
74
  "@types/chai": "^4.3.0",
74
75
  "@types/mocha": "^9.1.0",
75
76
  "@types/node": "^17.0.17",
77
+ "@types/sha.js": "^2.4.0",
76
78
  "@typescript-eslint/eslint-plugin": "^5.11.0",
77
79
  "@typescript-eslint/parser": "^5.11.0",
78
80
  "babel-loader": "^8.2.3",
@@ -106,7 +106,7 @@ async function createAensDelegationSignature ({ contractId, name }, opt = {}) {
106
106
  * const respondSig = await contract.createOracleDelegationSignature(params, queryId)
107
107
  */
108
108
  async function createOracleDelegationSignature ({ contractId, queryId }, opt = {}) {
109
- return this.delegateSignatureCommon([...queryId ? [queryId] : [], contractId], opt)
109
+ return this.delegateSignatureCommon([queryId ?? await this.address(opt), contractId], opt)
110
110
  }
111
111
 
112
112
  /**
@@ -863,7 +863,12 @@ async function reconnect (options, txParams) {
863
863
  */
864
864
  const Channel = AsyncInit.compose({
865
865
  async init (options) {
866
- initialize(this, options)
866
+ await initialize(
867
+ this,
868
+ options.existingFsmId ? handlers.awaitingReconnection : handlers.awaitingConnection,
869
+ handlers.channelOpen,
870
+ options
871
+ )
867
872
  },
868
873
  methods: {
869
874
  on,
@@ -19,7 +19,6 @@ import { w3cwebsocket as W3CWebSocket } from 'websocket'
19
19
  import { EventEmitter } from 'events'
20
20
  import JsonBig from '../utils/json-big'
21
21
  import { pascalToSnake } from '../utils/string'
22
- import { awaitingConnection, awaitingReconnection, channelOpen } from './handlers'
23
22
  import { ChannelCallError, ChannelPingTimedOutError, UnknownChannelStateError } from '../utils/errors'
24
23
 
25
24
  // Send ping message every 10 seconds
@@ -196,11 +195,11 @@ export function disconnect (channel) {
196
195
  clearTimeout(pongTimeoutId.get(channel))
197
196
  }
198
197
 
199
- export async function initialize (channel, { url, ...channelOptions }) {
198
+ export async function initialize (
199
+ channel, connectionHandler, openHandler, { url, ...channelOptions }
200
+ ) {
200
201
  options.set(channel, channelOptions)
201
- fsm.set(channel, {
202
- handler: channelOptions.existingFsmId ? awaitingReconnection : awaitingConnection
203
- })
202
+ fsm.set(channel, { handler: connectionHandler })
204
203
  eventEmitters.set(channel, new EventEmitter())
205
204
  sequence.set(channel, 0)
206
205
  rpcCallbacks.set(channel, new Map())
@@ -219,7 +218,7 @@ export async function initialize (channel, { url, ...channelOptions }) {
219
218
  resolve()
220
219
  changeStatus(channel, 'connected')
221
220
  if (channelOptions.reconnectTx) {
222
- enterState(channel, { handler: channelOpen })
221
+ enterState(channel, { handler: openHandler })
223
222
  setTimeout(async () => changeState(channel,
224
223
  (await call(channel, 'channels.get.offchain_state', {})).signed_tx
225
224
  ))
@@ -235,7 +235,7 @@ export default async function getContractInstance ({
235
235
  if (!fn) throw new MissingFunctionNameError()
236
236
  if (fn === 'init' && !opt.callStatic) throw new InvalidMethodInvocationError('"init" can be called only via dryRun')
237
237
  if (!contractId && fn !== 'init') throw new InvalidMethodInvocationError('You need to deploy contract before calling!')
238
- if (opt.amount > 0 && fnACI.payable === false) throw new NotPayableFunctionError(`You try to pay "${opt.amount}" to function "${fn}" which is not payable. Only payable function can accept coins`)
238
+ if (fn !== 'init' && opt.amount > 0 && fnACI.payable === false) throw new NotPayableFunctionError(`You try to pay "${opt.amount}" to function "${fn}" which is not payable. Only payable function can accept coins`)
239
239
 
240
240
  const callerId = await this.address(opt).catch(error => {
241
241
  if (opt.callStatic) return DRY_RUN_ACCOUNT.pub
@@ -0,0 +1,100 @@
1
+ import BigNumber from 'bignumber.js'
2
+ import { mapObject } from '../../utils/other'
3
+
4
+ // # AENS
5
+ export const NAME_TTL = 180000
6
+ // # max number of block into the future that the name is going to be available
7
+ // # https://github.com/aeternity/protocol/blob/epoch-v0.22.0/AENS.md#update
8
+ // # https://github.com/aeternity/protocol/blob/44a93d3aab957ca820183c3520b9daf6b0fedff4/AENS.md#aens-entry
9
+ export const NAME_MAX_TTL = 36000
10
+ export const NAME_MAX_CLIENT_TTL = 84600
11
+ export const CLIENT_TTL = NAME_MAX_CLIENT_TTL
12
+ // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67
13
+ export const NAME_FEE_MULTIPLIER = 1e14 // 100000000000000
14
+ export const NAME_FEE_BID_INCREMENT = 0.05 // # the increment is in percentage
15
+ // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L272
16
+ export const NAME_BID_TIMEOUT_BLOCKS = 480 // # ~1 day
17
+ // # this is the max length for a domain that requires a base fee to be paid
18
+ export const NAME_MAX_LENGTH_FEE = 31
19
+ export const NAME_BID_MAX_LENGTH = 12 // # this is the max length for a domain to be part of a bid
20
+ export const POINTER_KEY_BY_PREFIX = {
21
+ ak: 'account_pubkey',
22
+ ok: 'oracle_pubkey',
23
+ ct: 'contract_pubkey',
24
+ ch: 'channel'
25
+ }
26
+ // # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290
27
+ // # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times
28
+ // # bid ranges:
29
+ export const NAME_BID_RANGES = mapObject({
30
+ 31: 3,
31
+ 30: 5,
32
+ 29: 8,
33
+ 28: 13,
34
+ 27: 21,
35
+ 26: 34,
36
+ 25: 55,
37
+ 24: 89,
38
+ 23: 144,
39
+ 22: 233,
40
+ 21: 377,
41
+ 20: 610,
42
+ 19: 987,
43
+ 18: 1597,
44
+ 17: 2584,
45
+ 16: 4181,
46
+ 15: 6765,
47
+ 14: 10946,
48
+ 13: 17711,
49
+ 12: 28657,
50
+ 11: 46368,
51
+ 10: 75025,
52
+ 9: 121393,
53
+ 8: 196418,
54
+ 7: 317811,
55
+ 6: 514229,
56
+ 5: 832040,
57
+ 4: 1346269,
58
+ 3: 2178309,
59
+ 2: 3524578,
60
+ 1: 5702887
61
+ }, ([key, value]) => [key, new BigNumber(value).times(NAME_FEE_MULTIPLIER)])
62
+
63
+ // # ref: https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273
64
+ // # name bid timeouts
65
+ export const NAME_BID_TIMEOUTS = {
66
+ 13: BigNumber(0),
67
+ 12: BigNumber(NAME_BID_TIMEOUT_BLOCKS), // # 480 blocks
68
+ 8: BigNumber(31).times(NAME_BID_TIMEOUT_BLOCKS), // # 14880 blocks
69
+ 4: BigNumber(62).times(NAME_BID_TIMEOUT_BLOCKS) // # 29760 blocks
70
+ }
71
+
72
+ // # Tag constant for ids (type uint8)
73
+ // # see https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type
74
+ // # <<Tag:1/unsigned-integer-unit:8, Hash:32/binary-unit:8>>
75
+ const ID_TAG_ACCOUNT = 1
76
+ const ID_TAG_NAME = 2
77
+ const ID_TAG_COMMITMENT = 3
78
+ const ID_TAG_ORACLE = 4
79
+ const ID_TAG_CONTRACT = 5
80
+ const ID_TAG_CHANNEL = 6
81
+
82
+ export const ID_TAG = {
83
+ account: ID_TAG_ACCOUNT,
84
+ name: ID_TAG_NAME,
85
+ commitment: ID_TAG_COMMITMENT,
86
+ oracle: ID_TAG_ORACLE,
87
+ contract: ID_TAG_CONTRACT,
88
+ channel: ID_TAG_CHANNEL
89
+ }
90
+
91
+ export const PREFIX_ID_TAG = {
92
+ ak: ID_TAG.account,
93
+ nm: ID_TAG.name,
94
+ cm: ID_TAG.commitment,
95
+ ok: ID_TAG.oracle,
96
+ ct: ID_TAG.contract,
97
+ ch: ID_TAG.channel
98
+ }
99
+
100
+ export const ID_TAG_PREFIX = mapObject(PREFIX_ID_TAG, ([key, value]) => [value, key])
@@ -1,6 +1,7 @@
1
1
  import BigNumber from 'bignumber.js'
2
- import bs58 from 'bs58'
3
- import { hash, salt, sha256hash } from '../../utils/crypto'
2
+ import { encode as bs58Encode, decode as bs58Decode } from 'bs58'
3
+ import { hash, salt } from '../../utils/crypto'
4
+ import { encode, decode } from '../../utils/encoder'
4
5
  import { toBytes } from '../../utils/bytes'
5
6
  import {
6
7
  ID_TAG_PREFIX,
@@ -10,20 +11,15 @@ import {
10
11
  NAME_BID_TIMEOUTS,
11
12
  NAME_MAX_LENGTH_FEE,
12
13
  POINTER_KEY_BY_PREFIX
13
- } from './schema'
14
+ } from './constants'
14
15
  import { ceil } from '../../utils/bignumber'
15
16
  import {
16
- PrefixMismatchError,
17
- DecodeError,
18
- EncodeError,
19
- PayloadLengthError,
20
17
  TagNotFoundError,
21
18
  PrefixNotFoundError,
22
19
  InvalidNameError,
23
20
  IllegalBidFeeError,
24
21
  NoDefaultAensPointerError,
25
- ArgumentError,
26
- InvalidChecksumError
22
+ ArgumentError
27
23
  } from '../../utils/errors'
28
24
 
29
25
  /**
@@ -35,6 +31,8 @@ import {
35
31
 
36
32
  export const createSalt = salt
37
33
 
34
+ export { encode, decode }
35
+
38
36
  /**
39
37
  * Build a contract public key
40
38
  * @function
@@ -147,50 +145,6 @@ const base58 = {
147
145
  decode: string => getPayload(bs58.decode(string))
148
146
  }
149
147
 
150
- /**
151
- * Decode data using the default encoding/decoding algorithm
152
- * @function
153
- * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
154
- * @param {string} data An Base58/64check encoded and prefixed string (ex tx_..., sg_..., ak_....)
155
- * @param {string} [requiredPrefix] Ensure that data have this prefix
156
- * @return {Buffer} Decoded data
157
- */
158
- export function decode (data, requiredPrefix) {
159
- if (typeof data !== 'string') throw new DecodeError(`Encoded should be a string, got ${data} instead`)
160
- const [prefix, encodedPayload, extra] = data.split('_')
161
- if (!encodedPayload) throw new DecodeError(`Encoded string missing payload: ${data}`)
162
- if (extra) throw new DecodeError(`Encoded string have extra parts: ${data}`)
163
- if (requiredPrefix && requiredPrefix !== prefix) {
164
- throw new PrefixMismatchError(prefix, requiredPrefix)
165
- }
166
- const decoder = (base64Types.includes(prefix) && base64.decode) ||
167
- (base58Types.includes(prefix) && base58.decode)
168
- if (!decoder) {
169
- throw new DecodeError(`Encoded string have unknown type: ${prefix}`)
170
- }
171
- const payload = decoder(encodedPayload)
172
- ensureValidLength(payload, prefix)
173
- return payload
174
- }
175
-
176
- /**
177
- * Encode data using the default encoding/decoding algorithm
178
- * @function
179
- * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
180
- * @param {Buffer|String} data An decoded data
181
- * @param {string} type Prefix of Transaction
182
- * @return {String} Encoded string Base58check or Base64check data
183
- */
184
- export function encode (data, type) {
185
- const encoder = (base64Types.includes(type) && base64.encode) ||
186
- (base58Types.includes(type) && base58.encode)
187
- if (!encoder) {
188
- throw new EncodeError(`Unknown type: ${type}`)
189
- }
190
- ensureValidLength(data, type)
191
- return `${type}_${encoder(data)}`
192
- }
193
-
194
148
  /**
195
149
  * Utility function to create and _id type
196
150
  * @function
@@ -10,6 +10,7 @@
10
10
  import BigNumber from 'bignumber.js'
11
11
  import { Name, NameId, NameFee, Deposit } from './field-types'
12
12
 
13
+ export * from './constants'
13
14
  export const VSN = 1
14
15
  export const VSN_2 = 2
15
16
 
@@ -26,83 +27,6 @@ export const GAS_MAX = 1600000 - 21000
26
27
  export const MIN_GAS_PRICE = 1e9
27
28
  export const MAX_AUTH_FUN_GAS = 50000
28
29
  export const DRY_RUN_ACCOUNT = { pub: 'ak_11111111111111111111111111111111273Yts', amount: '100000000000000000000000000000000000' }
29
- // # AENS
30
- export const NAME_TTL = 180000
31
- // # max number of block into the future that the name is going to be available
32
- // # https://github.com/aeternity/protocol/blob/epoch-v0.22.0/AENS.md#update
33
- // # https://github.com/aeternity/protocol/blob/44a93d3aab957ca820183c3520b9daf6b0fedff4/AENS.md#aens-entry
34
- export const NAME_MAX_TTL = 36000
35
- export const NAME_MAX_CLIENT_TTL = 84600
36
- export const CLIENT_TTL = NAME_MAX_CLIENT_TTL
37
- // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67
38
- export const NAME_FEE_MULTIPLIER = 1e14 // 100000000000000
39
- export const NAME_FEE_BID_INCREMENT = 0.05 // # the increment is in percentage
40
- // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L272
41
- export const NAME_BID_TIMEOUT_BLOCKS = 480 // # ~1 day
42
- // # this is the max length for a domain that requires a base fee to be paid
43
- export const NAME_MAX_LENGTH_FEE = 31
44
- export const NAME_BID_MAX_LENGTH = 12 // # this is the max length for a domain to be part of a bid
45
- export const POINTER_KEY_BY_PREFIX = {
46
- ak: 'account_pubkey',
47
- ok: 'oracle_pubkey',
48
- ct: 'contract_pubkey',
49
- ch: 'channel'
50
- }
51
- // # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290
52
- // # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times
53
- // # bid ranges:
54
- export const NAME_BID_RANGES = {
55
- 31: BigNumber(3).times(NAME_FEE_MULTIPLIER),
56
- 30: BigNumber(5).times(NAME_FEE_MULTIPLIER),
57
- 29: BigNumber(8).times(NAME_FEE_MULTIPLIER),
58
- 28: BigNumber(13).times(NAME_FEE_MULTIPLIER),
59
- 27: BigNumber(21).times(NAME_FEE_MULTIPLIER),
60
- 26: BigNumber(34).times(NAME_FEE_MULTIPLIER),
61
- 25: BigNumber(55).times(NAME_FEE_MULTIPLIER),
62
- 24: BigNumber(89).times(NAME_FEE_MULTIPLIER),
63
- 23: BigNumber(144).times(NAME_FEE_MULTIPLIER),
64
- 22: BigNumber(233).times(NAME_FEE_MULTIPLIER),
65
- 21: BigNumber(377).times(NAME_FEE_MULTIPLIER),
66
- 20: BigNumber(610).times(NAME_FEE_MULTIPLIER),
67
- 19: BigNumber(987).times(NAME_FEE_MULTIPLIER),
68
- 18: BigNumber(1597).times(NAME_FEE_MULTIPLIER),
69
- 17: BigNumber(2584).times(NAME_FEE_MULTIPLIER),
70
- 16: BigNumber(4181).times(NAME_FEE_MULTIPLIER),
71
- 15: BigNumber(6765).times(NAME_FEE_MULTIPLIER),
72
- 14: BigNumber(10946).times(NAME_FEE_MULTIPLIER),
73
- 13: BigNumber(17711).times(NAME_FEE_MULTIPLIER),
74
- 12: BigNumber(28657).times(NAME_FEE_MULTIPLIER),
75
- 11: BigNumber(46368).times(NAME_FEE_MULTIPLIER),
76
- 10: BigNumber(75025).times(NAME_FEE_MULTIPLIER),
77
- 9: BigNumber(121393).times(NAME_FEE_MULTIPLIER),
78
- 8: BigNumber(196418).times(NAME_FEE_MULTIPLIER),
79
- 7: BigNumber(317811).times(NAME_FEE_MULTIPLIER),
80
- 6: BigNumber(514229).times(NAME_FEE_MULTIPLIER),
81
- 5: BigNumber(832040).times(NAME_FEE_MULTIPLIER),
82
- 4: BigNumber(1346269).times(NAME_FEE_MULTIPLIER),
83
- 3: BigNumber(2178309).times(NAME_FEE_MULTIPLIER),
84
- 2: BigNumber(3524578).times(NAME_FEE_MULTIPLIER),
85
- 1: BigNumber(5702887).times(NAME_FEE_MULTIPLIER)
86
- }
87
-
88
- // # ref: https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273
89
- // # name bid timeouts
90
- export const NAME_BID_TIMEOUTS = {
91
- 13: BigNumber(0),
92
- 12: BigNumber(NAME_BID_TIMEOUT_BLOCKS), // # 480 blocks
93
- 8: BigNumber(31).times(NAME_BID_TIMEOUT_BLOCKS), // # 14880 blocks
94
- 4: BigNumber(62).times(NAME_BID_TIMEOUT_BLOCKS) // # 29760 blocks
95
- }
96
-
97
- // # Tag constant for ids (type uint8)
98
- // # see https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type
99
- // # <<Tag:1/unsigned-integer-unit:8, Hash:32/binary-unit:8>>
100
- const ID_TAG_ACCOUNT = 1
101
- const ID_TAG_NAME = 2
102
- const ID_TAG_COMMITMENT = 3
103
- const ID_TAG_ORACLE = 4
104
- const ID_TAG_CONTRACT = 5
105
- const ID_TAG_CHANNEL = 6
106
30
 
107
31
  // # OBJECT tags
108
32
  // # see https://github.com/aeternity/protocol/blob/master/serializations.md#binary-serialization
@@ -157,9 +81,6 @@ const OBJECT_TAG_SOPHIA_BYTE_CODE = 70
157
81
  const TX_FIELD = (name, type, prefix) => [name, type, prefix]
158
82
  const TX_SCHEMA_FIELD = (schema, objectId) => [schema, objectId]
159
83
 
160
- const revertObject = (obj) => Object.entries(obj)
161
- .reduce((acc, [key, v]) => (acc[v] = key) && acc, {})
162
-
163
84
  /**
164
85
  * @constant
165
86
  * @description Object with transaction types
@@ -401,24 +322,6 @@ export const TX_FEE_OTHER_GAS = (txType, txSize, { relativeTtl, innerTxSize }) =
401
322
  }
402
323
  }
403
324
 
404
- export const ID_TAG = {
405
- account: ID_TAG_ACCOUNT,
406
- name: ID_TAG_NAME,
407
- commitment: ID_TAG_COMMITMENT,
408
- oracle: ID_TAG_ORACLE,
409
- contract: ID_TAG_CONTRACT,
410
- channel: ID_TAG_CHANNEL
411
- }
412
- export const PREFIX_ID_TAG = {
413
- ak: ID_TAG.account,
414
- nm: ID_TAG.name,
415
- cm: ID_TAG.commitment,
416
- ok: ID_TAG.oracle,
417
- ct: ID_TAG.contract,
418
- ch: ID_TAG.channel
419
- }
420
- export const ID_TAG_PREFIX = revertObject(PREFIX_ID_TAG)
421
-
422
325
  const BASE_TX = [
423
326
  TX_FIELD('tag', FIELD_TYPES.int),
424
327
  TX_FIELD('VSN', FIELD_TYPES.int)
@@ -20,7 +20,7 @@ import {
20
20
  ArgumentError,
21
21
  RpcConnectionError
22
22
  } from '../../errors'
23
- import { Node } from '../../../index'
23
+ import Node from '../../../node'
24
24
 
25
25
  const NOTIFICATIONS = {
26
26
  [METHODS.updateAddress]: (instance) =>
@@ -23,14 +23,14 @@
23
23
 
24
24
  import nacl from 'tweetnacl'
25
25
  import aesjs from 'aes-js'
26
- import shajs from 'sha.js'
27
26
 
28
27
  import { str2buf } from './bytes'
29
- import { encode, decode } from '../tx/builder/helpers'
28
+ import { encode, decode, sha256hash } from './encoder'
30
29
  import { hash } from './crypto-ts'
31
30
  import { NotImplementedError } from './errors'
32
31
 
33
32
  export * from './crypto-ts'
33
+ export { sha256hash }
34
34
 
35
35
  const Ecb = aesjs.ModeOfOperation.ecb
36
36
 
@@ -62,16 +62,6 @@ export function isAddressValid (address, prefix = 'ak') {
62
62
  }
63
63
  }
64
64
 
65
- /**
66
- * Calculate SHA256 hash of `input`
67
- * @rtype (input: String) => hash: String
68
- * @param {String} input - Data to hash
69
- * @return {String} Hash
70
- */
71
- export function sha256hash (input) {
72
- return shajs('sha256').update(input).digest()
73
- }
74
-
75
65
  /**
76
66
  * Generate a random salt (positive integer)
77
67
  * @rtype () => salt: Number