@aeternity/aepp-sdk 13.2.1 → 13.2.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.
Files changed (84) 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 +82 -4343
  6. package/dist/aepp-sdk.js.map +1 -1
  7. package/es/Middleware.d.ts +1 -1
  8. package/es/Middleware.mjs +1 -1
  9. package/es/Middleware.mjs.map +1 -1
  10. package/es/Node.d.ts +1 -1
  11. package/es/Node.mjs +12 -3
  12. package/es/Node.mjs.map +1 -1
  13. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  14. package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -5
  15. package/es/aepp-wallet-communication/wallet-detector.mjs +9 -4
  16. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  17. package/es/contract/Contract.d.ts +1 -1
  18. package/es/contract/Contract.mjs +17 -7
  19. package/es/contract/Contract.mjs.map +1 -1
  20. package/es/contract/compiler/Cli.d.ts +7 -2
  21. package/es/contract/compiler/Cli.mjs +7 -2
  22. package/es/contract/compiler/Cli.mjs.map +1 -1
  23. package/es/deprecated.d.ts +10 -0
  24. package/es/deprecated.mjs +21 -1
  25. package/es/deprecated.mjs.map +1 -1
  26. package/es/index-browser.d.ts +2 -2
  27. package/es/index-browser.mjs +2 -2
  28. package/es/index-browser.mjs.map +1 -1
  29. package/es/tx/builder/constants.d.ts +2 -1
  30. package/es/tx/builder/constants.mjs +1 -0
  31. package/es/tx/builder/constants.mjs.map +1 -1
  32. package/es/tx/builder/field-types/ct-version.d.ts +1 -1
  33. package/es/tx/builder/field-types/ct-version.mjs +1 -1
  34. package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
  35. package/es/tx/builder/field-types/fee.mjs +1 -1
  36. package/es/tx/builder/field-types/fee.mjs.map +1 -1
  37. package/es/tx/builder/field-types/gas-price.mjs +1 -1
  38. package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
  39. package/es/utils/autorest.mjs +4 -4
  40. package/es/utils/autorest.mjs.map +1 -1
  41. package/es/utils/crypto.d.ts +1 -1
  42. package/es/utils/crypto.mjs +1 -1
  43. package/es/utils/crypto.mjs.map +1 -1
  44. package/es/utils/typed-data.d.ts +0 -2
  45. package/es/utils/typed-data.mjs +8 -24
  46. package/es/utils/typed-data.mjs.map +1 -1
  47. package/package.json +2 -2
  48. package/src/Middleware.ts +1 -1
  49. package/src/Node.ts +14 -3
  50. package/src/aepp-wallet-communication/rpc/types.ts +1 -1
  51. package/src/aepp-wallet-communication/wallet-detector.ts +10 -10
  52. package/src/contract/Contract.ts +11 -5
  53. package/src/contract/compiler/Cli.ts +7 -2
  54. package/src/deprecated.ts +19 -1
  55. package/src/index-browser.ts +4 -4
  56. package/src/tx/builder/constants.ts +1 -0
  57. package/src/tx/builder/field-types/ct-version.ts +1 -1
  58. package/src/tx/builder/field-types/fee.ts +1 -1
  59. package/src/tx/builder/field-types/gas-price.ts +1 -1
  60. package/src/utils/autorest.ts +4 -4
  61. package/src/utils/crypto.ts +1 -1
  62. package/src/utils/typed-data.ts +4 -30
  63. package/types-legacy/ts4.2/Middleware.d.ts +1 -1
  64. package/types-legacy/ts4.2/Node.d.ts +1 -1
  65. package/types-legacy/ts4.2/aepp-wallet-communication/wallet-detector.d.ts +2 -5
  66. package/types-legacy/ts4.2/contract/Contract.d.ts +1 -1
  67. package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +7 -2
  68. package/types-legacy/ts4.2/deprecated.d.ts +10 -0
  69. package/types-legacy/ts4.2/index-browser.d.ts +2 -2
  70. package/types-legacy/ts4.2/tx/builder/constants.d.ts +2 -1
  71. package/types-legacy/ts4.2/tx/builder/field-types/ct-version.d.ts +1 -1
  72. package/types-legacy/ts4.2/utils/crypto.d.ts +1 -1
  73. package/types-legacy/ts4.2/utils/typed-data.d.ts +0 -2
  74. package/types-legacy/ts4.5/Middleware.d.ts +1 -1
  75. package/types-legacy/ts4.5/Node.d.ts +1 -1
  76. package/types-legacy/ts4.5/aepp-wallet-communication/wallet-detector.d.ts +2 -5
  77. package/types-legacy/ts4.5/contract/Contract.d.ts +1 -1
  78. package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +7 -2
  79. package/types-legacy/ts4.5/deprecated.d.ts +10 -0
  80. package/types-legacy/ts4.5/index-browser.d.ts +2 -2
  81. package/types-legacy/ts4.5/tx/builder/constants.d.ts +2 -1
  82. package/types-legacy/ts4.5/tx/builder/field-types/ct-version.d.ts +1 -1
  83. package/types-legacy/ts4.5/utils/crypto.d.ts +1 -1
  84. package/types-legacy/ts4.5/utils/typed-data.d.ts +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.mjs","names":["nacl","_blakejsBlake2bJs","blake2b","_varuintBitcoin","encode","varuintEncode","concatBuffers","decode","Encoding","ArgumentError","getAddressFromPriv","secret","secretBuffer","_Buffer","from","keys","sign","keyPair","fromSecretKey","publicKey","AccountAddress","isAddressValid","address","prefix","arguments","length","undefined","actualPrefix","split","e","genSalt","random","BigUint64Array","randomBytes","buffer","Number","BigInt","MAX_SAFE_INTEGER","encodeUnsigned","value","binary","allocUnsafe","writeUInt32BE","slice","findIndex","i","hash","input","encodeContractAddress","owner","nonce","ContractAddress","generateKeyPairFromSecret","generateKeyPair","raw","publicBuffer","secretKey","toString","data","privateKey","detached","verify","signature","messagePrefix","messagePrefixLength","messageToHash","message","msg","signMessage","verifyMessage","isValidKeypair","publicKeyBuffer"],"sources":["../../src/utils/crypto.ts"],"sourcesContent":["import nacl, { SignKeyPair } from 'tweetnacl';\n// js extension is required for mjs build, not importing the whole package to reduce bundle size\n// eslint-disable-next-line import/extensions\nimport { blake2b } from 'blakejs/blake2b.js';\nimport { encode as varuintEncode } from 'varuint-bitcoin';\n\nimport { concatBuffers } from './other';\nimport {\n decode, encode, Encoded, Encoding,\n} from './encoder';\nimport { ArgumentError } from './errors';\n\n/**\n * Generate address from secret key\n * @param secret - Private key as hex string\n * @returns Public key encoded as address\n */\nexport function getAddressFromPriv(secret: string | Uint8Array): Encoded.AccountAddress {\n const secretBuffer = typeof secret === 'string' ? Buffer.from(secret, 'hex') : secret;\n const keys = nacl.sign.keyPair.fromSecretKey(secretBuffer);\n return encode(keys.publicKey, Encoding.AccountAddress);\n}\n\n/**\n * Check if address is valid\n * @param address - Address\n * @param prefix - Transaction prefix. Default: 'ak'\n * @returns is valid\n */\nexport function isAddressValid(\n address: string,\n prefix: Encoding = Encoding.AccountAddress,\n): boolean {\n try {\n decode(address as Encoded.Generic<typeof prefix>);\n const actualPrefix = address.split('_')[0];\n if (actualPrefix !== prefix) {\n throw new ArgumentError('Encoded string type', prefix, actualPrefix);\n }\n return true;\n } catch (e) {\n return false;\n }\n}\n\n/**\n * Generate a random salt (positive integer)\n * @returns random salt\n */\nexport function genSalt(): number {\n const [random] = new BigUint64Array(nacl.randomBytes(8).buffer);\n return Number(random % BigInt(Number.MAX_SAFE_INTEGER));\n}\n\n/**\n * Converts a positive integer to the smallest possible\n * representation in a binary digit representation\n * @param value - Value to encode\n * @returns Encoded number\n */\nexport function encodeUnsigned(value: number): Buffer {\n const binary = Buffer.allocUnsafe(4);\n binary.writeUInt32BE(value);\n return binary.slice(binary.findIndex((i) => i !== 0));\n}\n\n/**\n * Calculate 256bits Blake2b hash of `input`\n * @param input - Data to hash\n * @returns Hash\n */\nexport function hash(input: string | Uint8Array): Buffer {\n return Buffer.from(blake2b(input, undefined, 32)); // 256 bits\n}\n\n// Todo Duplicated in tx builder. remove\n/**\n * Compute contract address\n * @category contract\n * @param owner - Address of contract owner\n * @param nonce - Round when contract was created\n * @returns Contract address\n */\nexport function encodeContractAddress(\n owner: Encoded.AccountAddress,\n nonce: number,\n): Encoded.ContractAddress {\n const publicKey = decode(owner);\n const binary = concatBuffers([publicKey, encodeUnsigned(nonce)]);\n return encode(hash(binary), Encoding.ContractAddress);\n}\n\n// KEY-PAIR HELPERS\n\n/**\n * Generate keyPair from secret key\n * @param secret - secret key\n * @returns Object with Private(privateKey) and Public(publicKey) keys\n */\nexport function generateKeyPairFromSecret(secret: Uint8Array): SignKeyPair {\n return nacl.sign.keyPair.fromSecretKey(secret);\n}\n\n/**\n * Generate a random ED25519 keypair\n * @param raw - Whether to return raw (binary) keys\n * @returns Key pair\n */\nexport function generateKeyPair(raw: true): { publicKey: Buffer; secretKey: Buffer };\nexport function generateKeyPair(raw?: false): {\n publicKey: Encoded.AccountAddress; secretKey: string;\n};\nexport function generateKeyPair(raw = false): {\n publicKey: Encoded.AccountAddress | Buffer;\n secretKey: string | Buffer;\n} {\n const keyPair = nacl.sign.keyPair();\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 }\n return {\n publicKey: encode(publicBuffer, Encoding.AccountAddress),\n secretKey: secretBuffer.toString('hex'),\n };\n}\n\n// SIGNATURES\n\n/**\n * Generate signature\n * @param data - Data to sign\n * @param privateKey - Key to sign with\n * @returns Signature\n */\nexport function sign(data: string | Uint8Array, privateKey: string | Uint8Array): Uint8Array {\n return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey));\n}\n\n/**\n * Verify that signature was signed by public key\n * @param data - Data that was signed\n * @param signature - Signature of data\n * @param address - Address to verify against\n * @returns is data was signed by address\n */\nexport function verify(\n data: Uint8Array,\n signature: Uint8Array,\n address: Encoded.AccountAddress,\n): boolean {\n return nacl.sign.detached.verify(data, signature, decode(address));\n}\n\nconst messagePrefix = Buffer.from('aeternity Signed Message:\\n', 'utf8');\nexport const messagePrefixLength = varuintEncode(messagePrefix.length);\n\n// TODO: consider rename to hashMessage\nexport function messageToHash(message: string): Buffer {\n const msg = Buffer.from(message, 'utf8');\n return hash(concatBuffers([messagePrefixLength, messagePrefix, varuintEncode(msg.length), msg]));\n}\n\nexport function signMessage(message: string, privateKey: string | Buffer): Uint8Array {\n return sign(messageToHash(message), privateKey);\n}\n\n/**\n * Verify that message was signed by address\n * @param message - Message that was signed\n * @param signature - Signature of message\n * @param address - Address to verify against\n * @returns is data was signed by address\n */\n// TODO: deprecate in favour of `verify(messageToHash(message), ...`, also the name is confusing\n// it should contain \"signature\"\nexport function verifyMessage(\n message: string,\n signature: Uint8Array,\n address: Encoded.AccountAddress,\n): boolean {\n return verify(messageToHash(message), signature, address);\n}\n\n/**\n * Check key pair for validity\n *\n * Sign a message, and then verifying that signature\n * @param privateKey - Private key to verify\n * @param publicKey - Public key to verify as hex string\n * @returns Valid?\n */\nexport function isValidKeypair(\n privateKey: string | Uint8Array,\n publicKey: string | Uint8Array,\n): boolean {\n const message = Buffer.from('TheMessage');\n const signature = sign(message, privateKey);\n const publicKeyBuffer = typeof publicKey === 'string' ? Buffer.from(publicKey, 'hex') : publicKey;\n return verify(message, signature, encode(publicKeyBuffer, Encoding.AccountAddress));\n}\n"],"mappings":";;;;AAAA,OAAOA,IAAI,MAAuB,WAAW;AAC7C;AACA;AACA,OAAAC,iBAAA,MAAwB,oBAAoB;AAAC;EAAAC;AAAA,IAAAD,iBAAA;AAC7C,OAAAE,eAAA,MAAwC,iBAAiB;AAAC;EAAAC,MAAA,EAAAC;AAAA,IAAAF,eAAA;AAAA,SAEjDG,aAAa;AAAA,SAEpBC,MAAM,EAAEH,MAAM,EAAWI,QAAQ;AAAA,SAE1BC,aAAa;AAEtB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAACC,MAA2B,EAA0B;EACtF,MAAMC,YAAY,GAAG,OAAOD,MAAM,KAAK,QAAQ,GAAGE,OAAA,CAAOC,IAAI,CAACH,MAAM,EAAE,KAAK,CAAC,GAAGA,MAAM;EACrF,MAAMI,IAAI,GAAGf,IAAI,CAACgB,IAAI,CAACC,OAAO,CAACC,aAAa,CAACN,YAAY,C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A+B,EACtB;EACT,OAAOuC,MAAM,CAACI,aAAa,CAACC,OAAO,CAAC,EAAEJ,SAAS,EAAExC,OAAO,CAAC;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASgD,cAAcA,CAC5BX,UAA+B,EAC/BxC,SAA8B,EACrB;EACT,MAAM+C,OAAO,GAAGrD,OAAA,CAAOC,IAAI,CAAC,YAAY,CAAC;EACzC,MAAMgD,SAAS,GAAG9C,IAAI,CAACkD,OAAO,EAAEP,UAAU,CAAC;EAC3C,MAAMY,eAAe,GAAG,OAAOpD,SAAS,KAAK,QAAQ,GAAGN,OAAA,CAAOC,IAAI,CAACK,SAAS,EAAE,KAAK,CAAC,GAAGA,SAAS;EACjG,OAAO0C,MAAM,CAACK,OAAO,EAAEJ,SAAS,EAAE1D,MAAM,CAACmE,eAAe,EAAE/D,QAAQ,CAACY,cAAc,CAAC,CAAC;AACrF"}
1
+ {"version":3,"file":"crypto.mjs","names":["nacl","_blakejsBlake2bJs","blake2b","_varuintBitcoin","encode","varuintEncode","concatBuffers","decode","Encoding","ArgumentError","getAddressFromPriv","secret","secretBuffer","_Buffer","from","keys","sign","keyPair","fromSecretKey","publicKey","AccountAddress","isAddressValid","address","prefix","arguments","length","undefined","actualPrefix","split","e","genSalt","random","BigUint64Array","randomBytes","buffer","Number","BigInt","MAX_SAFE_INTEGER","encodeUnsigned","value","binary","allocUnsafe","writeUInt32BE","slice","findIndex","i","hash","input","encodeContractAddress","owner","nonce","ContractAddress","generateKeyPairFromSecret","generateKeyPair","raw","publicBuffer","secretKey","toString","data","privateKey","detached","verify","signature","messagePrefix","messagePrefixLength","messageToHash","message","msg","signMessage","verifyMessage","isValidKeypair","publicKeyBuffer"],"sources":["../../src/utils/crypto.ts"],"sourcesContent":["import nacl, { SignKeyPair } from 'tweetnacl';\n// js extension is required for mjs build, not importing the whole package to reduce bundle size\n// eslint-disable-next-line import/extensions\nimport { blake2b } from 'blakejs/blake2b.js';\nimport { encode as varuintEncode } from 'varuint-bitcoin';\n\nimport { concatBuffers } from './other';\nimport {\n decode, encode, Encoded, Encoding,\n} from './encoder';\nimport { ArgumentError } from './errors';\n\n/**\n * Generate address from secret key\n * @param secret - Private key as hex string\n * @returns Public key encoded as address\n */\nexport function getAddressFromPriv(secret: string | Uint8Array): Encoded.AccountAddress {\n const secretBuffer = typeof secret === 'string' ? Buffer.from(secret, 'hex') : secret;\n const keys = nacl.sign.keyPair.fromSecretKey(secretBuffer);\n return encode(keys.publicKey, Encoding.AccountAddress);\n}\n\n/**\n * Check if address is valid\n * @param address - Address\n * @param prefix - Transaction prefix. Default: 'ak'\n * @returns is valid\n */\nexport function isAddressValid(\n address: string,\n prefix: Encoding = Encoding.AccountAddress,\n): boolean {\n try {\n decode(address as Encoded.Generic<typeof prefix>);\n const actualPrefix = address.split('_')[0];\n if (actualPrefix !== prefix) {\n throw new ArgumentError('Encoded string type', prefix, actualPrefix);\n }\n return true;\n } catch (e) {\n return false;\n }\n}\n\n/**\n * Generate a random salt (positive integer)\n * @returns random salt\n */\nexport function genSalt(): number {\n const [random] = new BigUint64Array(nacl.randomBytes(8).buffer);\n return Number(random % BigInt(Number.MAX_SAFE_INTEGER));\n}\n\n/**\n * Converts a positive integer to the smallest possible\n * representation in a binary digit representation\n * @param value - Value to encode\n * @returns Encoded number\n */\nexport function encodeUnsigned(value: number): Buffer {\n const binary = Buffer.allocUnsafe(4);\n binary.writeUInt32BE(value);\n return binary.slice(binary.findIndex((i) => i !== 0));\n}\n\n/**\n * Calculate 256bits Blake2b hash of `input`\n * @param input - Data to hash\n * @returns Hash\n */\nexport function hash(input: string | Uint8Array): Buffer {\n return Buffer.from(blake2b(input, undefined, 32)); // 256 bits\n}\n\n// Todo Duplicated in tx builder. remove\n/**\n * Compute contract address\n * @category contract\n * @param owner - Address of contract owner\n * @param nonce - Round when contract was created\n * @returns Contract address\n */\nexport function encodeContractAddress(\n owner: Encoded.AccountAddress,\n nonce: number,\n): Encoded.ContractAddress {\n const publicKey = decode(owner);\n const binary = concatBuffers([publicKey, encodeUnsigned(nonce)]);\n return encode(hash(binary), Encoding.ContractAddress);\n}\n\n// KEY-PAIR HELPERS\n\n/**\n * Generate keyPair from secret key\n * @param secret - secret key\n * @returns Object with Private(privateKey) and Public(publicKey) keys\n */\nexport function generateKeyPairFromSecret(secret: Uint8Array): SignKeyPair {\n return nacl.sign.keyPair.fromSecretKey(secret);\n}\n\n/**\n * Generate a random ED25519 keypair\n * @param raw - Whether to return raw (binary) keys\n * @returns Key pair\n */\nexport function generateKeyPair(raw: true): { publicKey: Buffer; secretKey: Buffer };\nexport function generateKeyPair(raw?: false): {\n publicKey: Encoded.AccountAddress; secretKey: string;\n};\nexport function generateKeyPair(raw = false): {\n publicKey: Encoded.AccountAddress | Buffer;\n secretKey: string | Buffer;\n} {\n const keyPair = nacl.sign.keyPair();\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 }\n return {\n publicKey: encode(publicBuffer, Encoding.AccountAddress),\n secretKey: secretBuffer.toString('hex'),\n };\n}\n\n// SIGNATURES\n\n/**\n * Generate signature\n * @param data - Data to sign\n * @param privateKey - Key to sign with\n * @returns Signature\n */\nexport function sign(data: string | Uint8Array, privateKey: string | Uint8Array): Uint8Array {\n return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey));\n}\n\n/**\n * Verify that signature was signed by public key\n * @param data - Data that was signed\n * @param signature - Signature of data\n * @param address - Address to verify against\n * @returns is data was signed by address\n */\nexport function verify(\n data: Uint8Array,\n signature: Uint8Array,\n address: Encoded.AccountAddress,\n): boolean {\n return nacl.sign.detached.verify(data, signature, decode(address));\n}\n\nconst messagePrefix = Buffer.from('aeternity Signed Message:\\n', 'utf8');\nexport const messagePrefixLength = varuintEncode(messagePrefix.length);\n\n// TODO: consider rename to hashMessage\nexport function messageToHash(message: string): Buffer {\n const msg = Buffer.from(message, 'utf8');\n return hash(concatBuffers([messagePrefixLength, messagePrefix, varuintEncode(msg.length), msg]));\n}\n\nexport function signMessage(message: string, privateKey: string | Buffer): Uint8Array {\n return sign(messageToHash(message), privateKey);\n}\n\n/**\n * Verify that message was signed by address\n * @param message - Message that was signed\n * @param signature - Signature of message\n * @param address - Address to verify against\n * @returns is data was signed by address\n */\n// TODO: deprecate in favour of `verify(messageToHash(message), ...`, also the name is confusing\n// it should contain \"signature\"\nexport function verifyMessage(\n message: string,\n signature: Uint8Array,\n address: Encoded.AccountAddress,\n): boolean {\n return verify(messageToHash(message), signature, address);\n}\n\n/**\n * Check key pair for validity\n *\n * Signs a message, and then verifies that signature\n * @param privateKey - Private key to verify\n * @param publicKey - Public key to verify as hex string\n * @returns Valid?\n */\nexport function isValidKeypair(\n privateKey: string | Uint8Array,\n publicKey: string | Uint8Array,\n): boolean {\n const message = Buffer.from('TheMessage');\n const signature = sign(message, privateKey);\n const publicKeyBuffer = typeof publicKey === 'string' ? Buffer.from(publicKey, 'hex') : publicKey;\n return verify(message, signature, encode(publicKeyBuffer, Encoding.AccountAddress));\n}\n"],"mappings":";;;;AAAA,OAAOA,IAAI,MAAuB,WAAW;AAC7C;AACA;AACA,OAAAC,iBAAA,MAAwB,oBAAoB;AAAC;EAAAC;AAAA,IAAAD,iBAAA;AAC7C,OAAAE,eAAA,MAAwC,iBAAiB;AAAC;EAAAC,MAAA,EAAAC;AAAA,IAAAF,eAAA;AAAA,SAEjDG,aAAa;AAAA,SAEpBC,MAAM,EAAEH,MAAM,EAAWI,QAAQ;AAAA,SAE1BC,aAAa;AAEtB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAACC,MAA2B,EAA0B;EACtF,MAAMC,YAAY,GAAG,OAAOD,MAAM,KAAK,QAAQ,GAAGE,OAAA,CAAOC,IAAI,CAACH,MAAM,EAAE,KAAK,CAAC,GAAGA,MAAM;EACrF,MAAMI,IAAI,GAAGf,IAAI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AASU,aAAaA,CAC3BH,OAAe,EACfJ,SAAqB,EACrBxC,OAA+B,EACtB;EACT,OAAOuC,MAAM,CAACI,aAAa,CAACC,OAAO,CAAC,EAAEJ,SAAS,EAAExC,OAAO,CAAC;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASgD,cAAcA,CAC5BX,UAA+B,EAC/BxC,SAA8B,EACrB;EACT,MAAM+C,OAAO,GAAGrD,OAAA,CAAOC,IAAI,CAAC,YAAY,CAAC;EACzC,MAAMgD,SAAS,GAAG9C,IAAI,CAACkD,OAAO,EAAEP,UAAU,CAAC;EAC3C,MAAMY,eAAe,GAAG,OAAOpD,SAAS,KAAK,QAAQ,GAAGN,OAAA,CAAOC,IAAI,CAACK,SAAS,EAAE,KAAK,CAAC,GAAGA,SAAS;EACjG,OAAO0C,MAAM,CAACK,OAAO,EAAEJ,SAAS,EAAE1D,MAAM,CAACmE,eAAe,EAAE/D,QAAQ,CAACY,cAAc,CAAC,CAAC;AACrF"}
@@ -36,8 +36,6 @@ export interface Domain {
36
36
  networkId?: string;
37
37
  contractAddress?: Encoded.ContractAddress;
38
38
  }
39
- export declare function encodeFateValue(value: unknown, aci: AciValue): Encoded.ContractBytearray;
40
- export declare function decodeFateValue(value: Encoded.ContractBytearray, aci: AciValue): Encoded.ContractBytearray;
41
39
  /**
42
40
  * Hashes domain object, can be used to inline domain hash to contract source code
43
41
  */
@@ -1,10 +1,8 @@
1
- // js extension is required for mjs build
2
- // @ts-expect-error see https://github.com/aeternity/aepp-calldata-js/issues/216
3
- // eslint-disable-next-line import/extensions
4
- import ContractByteArrayEncoder from '@aeternity/aepp-calldata/src/ContractByteArrayEncoder.js';
5
- // @ts-expect-error see https://github.com/aeternity/aepp-calldata-js/issues/216
6
- // eslint-disable-next-line import/extensions
7
- import AciTypeResolver from '@aeternity/aepp-calldata/src/AciTypeResolver.js';
1
+ import _aeternityAeppCalldata from '@aeternity/aepp-calldata';
2
+ const {
3
+ TypeResolver,
4
+ ContractByteArrayEncoder
5
+ } = _aeternityAeppCalldata;
8
6
  import canonicalize from 'canonicalize';
9
7
  import { decode } from "./encoder.mjs";
10
8
  import { hash, messagePrefixLength } from "./crypto.mjs";
@@ -19,22 +17,6 @@ export function hashJson(data) {
19
17
 
20
18
  // TODO: move this type to calldata library https://github.com/aeternity/aepp-calldata-js/issues/215
21
19
  // based on https://github.com/aeternity/aepp-calldata-js/blob/82b5a98f9b308482627da8d7484d213e9cf87151/src/AciTypeResolver.js#L129
22
- // TODO: replace with api on calldata side https://github.com/aeternity/aepp-calldata-js/issues/216
23
- export function encodeFateValue(value, aci) {
24
- const contractByteArrayEncoder = new ContractByteArrayEncoder();
25
- const aciTypeResolver = new AciTypeResolver([]);
26
- aciTypeResolver.isCustomType = () => false;
27
- return contractByteArrayEncoder.encode(aciTypeResolver.resolveType(aci), value);
28
- }
29
-
30
- // TODO: replace with api on calldata side https://github.com/aeternity/aepp-calldata-js/issues/216
31
- export function decodeFateValue(value, aci) {
32
- const contractByteArrayEncoder = new ContractByteArrayEncoder();
33
- const aciTypeResolver = new AciTypeResolver([]);
34
- aciTypeResolver.isCustomType = () => false;
35
- return contractByteArrayEncoder.decodeWithType(value, aciTypeResolver.resolveType(aci));
36
- }
37
-
38
20
  /**
39
21
  * Hashes domain object, can be used to inline domain hash to contract source code
40
22
  */
@@ -62,7 +44,9 @@ export function hashDomain(domain) {
62
44
  }
63
45
  }]
64
46
  };
65
- return hash(decode(encodeFateValue(domain, domainAci)));
47
+ const domainType = new TypeResolver().resolveType(domainAci, {});
48
+ const fateValue = new ContractByteArrayEncoder().encodeWithType(domain, domainType);
49
+ return hash(decode(fateValue));
66
50
  }
67
51
  export function hashTypedData(data, aci, domain) {
68
52
  return hash(concatBuffers([messagePrefixLength, new Uint8Array([0]), hashDomain(domain), hashJson(aci), hash(decode(data))]));
@@ -1 +1 @@
1
- {"version":3,"file":"typed-data.mjs","names":["ContractByteArrayEncoder","AciTypeResolver","canonicalize","decode","hash","messagePrefixLength","concatBuffers","hashJson","data","_canonicalize","encodeFateValue","value","aci","contractByteArrayEncoder","aciTypeResolver","isCustomType","encode","resolveType","decodeFateValue","decodeWithType","hashDomain","domain","domainAci","record","name","type","option","hashTypedData","Uint8Array"],"sources":["../../src/utils/typed-data.ts"],"sourcesContent":["// js extension is required for mjs build\n// @ts-expect-error see https://github.com/aeternity/aepp-calldata-js/issues/216\n// eslint-disable-next-line import/extensions\nimport ContractByteArrayEncoder from '@aeternity/aepp-calldata/src/ContractByteArrayEncoder.js';\n// @ts-expect-error see https://github.com/aeternity/aepp-calldata-js/issues/216\n// eslint-disable-next-line import/extensions\nimport AciTypeResolver from '@aeternity/aepp-calldata/src/AciTypeResolver.js';\nimport canonicalize from 'canonicalize';\nimport { Encoded, decode } from './encoder';\nimport { hash, messagePrefixLength } from './crypto';\nimport { concatBuffers } from './other';\n\n/**\n * Hashes arbitrary object, can be used to inline the aci hash to contract source code\n */\nexport function hashJson(data: unknown): Buffer {\n return hash(canonicalize(data) ?? '');\n}\n\n// TODO: move this type to calldata library https://github.com/aeternity/aepp-calldata-js/issues/215\n// based on https://github.com/aeternity/aepp-calldata-js/blob/82b5a98f9b308482627da8d7484d213e9cf87151/src/AciTypeResolver.js#L129\nexport type AciValue = 'void' | 'unit' | 'int' | 'bool' | 'string' | 'bits' | 'hash' | 'signature'\n| 'address' | 'contract_pubkey' | 'Chain.ttl' | 'Chain.ga_meta_tx' | 'Chain.paying_for_tx'\n| 'Chain.base_tx' | 'AENS.pointee' | 'AENS.name' | 'MCL_BLS12_381.fr' | 'MCL_BLS12_381.fp'\n| { 'Set.set': readonly [AciValue] }\n| { bytes: number }\n| { list: readonly [AciValue] }\n| { map: readonly [AciValue, AciValue] }\n| { tuple: readonly AciValue[] }\n| { record: ReadonlyArray<{ name: string; type: AciValue }> }\n| { variant: ReadonlyArray<{ [key: string]: readonly AciValue[] }> }\n| { option: readonly [AciValue] }\n| { oracle: readonly [AciValue, AciValue] }\n| { oracle_query: readonly [AciValue, AciValue] };\n\nexport interface Domain {\n name?: string;\n version?: number;\n networkId?: string;\n contractAddress?: Encoded.ContractAddress;\n}\n\n// TODO: replace with api on calldata side https://github.com/aeternity/aepp-calldata-js/issues/216\nexport function encodeFateValue(\n value: unknown,\n aci: AciValue,\n): Encoded.ContractBytearray {\n const contractByteArrayEncoder = new ContractByteArrayEncoder();\n const aciTypeResolver = new AciTypeResolver([]);\n aciTypeResolver.isCustomType = () => false;\n return contractByteArrayEncoder.encode(aciTypeResolver.resolveType(aci), value);\n}\n\n// TODO: replace with api on calldata side https://github.com/aeternity/aepp-calldata-js/issues/216\nexport function decodeFateValue(\n value: Encoded.ContractBytearray,\n aci: AciValue,\n): Encoded.ContractBytearray {\n const contractByteArrayEncoder = new ContractByteArrayEncoder();\n const aciTypeResolver = new AciTypeResolver([]);\n aciTypeResolver.isCustomType = () => false;\n return contractByteArrayEncoder.decodeWithType(value, aciTypeResolver.resolveType(aci));\n}\n\n/**\n * Hashes domain object, can be used to inline domain hash to contract source code\n */\nexport function hashDomain(domain: Domain): Buffer {\n const domainAci = {\n record: [{\n name: 'name',\n type: { option: ['string'] },\n }, {\n name: 'version',\n type: { option: ['int'] },\n }, {\n name: 'networkId',\n type: { option: ['string'] },\n }, {\n name: 'contractAddress',\n type: { option: ['contract_pubkey'] },\n }],\n } as const;\n return hash(decode(encodeFateValue(domain, domainAci)));\n}\n\nexport function hashTypedData(\n data: Encoded.ContractBytearray,\n aci: AciValue,\n domain: Domain,\n): Buffer {\n return hash(concatBuffers([\n messagePrefixLength, new Uint8Array([0]), hashDomain(domain), hashJson(aci), hash(decode(data)),\n ]));\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,wBAAwB,MAAM,0DAA0D;AAC/F;AACA;AACA,OAAOC,eAAe,MAAM,iDAAiD;AAC7E,OAAOC,YAAY,MAAM,cAAc;AAAC,SACtBC,MAAM;AAAA,SACfC,IAAI,EAAEC,mBAAmB;AAAA,SACzBC,aA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AAC,QAAQ;MAAE;IAC7B,CAAC,EAAE;MACDF,IAAI,EAAE,iBAAiB;MACvBC,IAAI,EAAE;QAAEC,MAAM,EAAE,CAAC,iBAAiB;MAAE;IACtC,CAAC;EACH,CAAU;EACV,OAAOtB,IAAI,CAACD,MAAM,CAACO,eAAe,CAACW,MAAM,EAAEC,SAAS,CAAC,CAAC,CAAC;AACzD;AAEA,OAAO,SAASK,aAAaA,CAC3BnB,IAA+B,EAC/BI,GAAa,EACbS,MAAc,EACN;EACR,OAAOjB,IAAI,CAACE,aAAa,CAAC,CACxBD,mBAAmB,EAAE,IAAIuB,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,EAAER,UAAU,CAACC,MAAM,CAAC,EAAEd,QAAQ,CAACK,GAAG,CAAC,EAAER,IAAI,CAACD,MAAM,CAACK,IAAI,CAAC,CAAC,CAChG,CAAC,CAAC;AACL"}
1
+ {"version":3,"file":"typed-data.mjs","names":["_aeternityAeppCalldata","TypeResolver","ContractByteArrayEncoder","canonicalize","decode","hash","messagePrefixLength","concatBuffers","hashJson","data","_canonicalize","hashDomain","domain","domainAci","record","name","type","option","domainType","resolveType","fateValue","encodeWithType","hashTypedData","aci","Uint8Array"],"sources":["../../src/utils/typed-data.ts"],"sourcesContent":["import { TypeResolver, ContractByteArrayEncoder } from '@aeternity/aepp-calldata';\nimport canonicalize from 'canonicalize';\nimport { Encoded, decode } from './encoder';\nimport { hash, messagePrefixLength } from './crypto';\nimport { concatBuffers } from './other';\n\n/**\n * Hashes arbitrary object, can be used to inline the aci hash to contract source code\n */\nexport function hashJson(data: unknown): Buffer {\n return hash(canonicalize(data) ?? '');\n}\n\n// TODO: move this type to calldata library https://github.com/aeternity/aepp-calldata-js/issues/215\n// based on https://github.com/aeternity/aepp-calldata-js/blob/82b5a98f9b308482627da8d7484d213e9cf87151/src/AciTypeResolver.js#L129\nexport type AciValue = 'void' | 'unit' | 'int' | 'bool' | 'string' | 'bits' | 'hash' | 'signature'\n| 'address' | 'contract_pubkey' | 'Chain.ttl' | 'Chain.ga_meta_tx' | 'Chain.paying_for_tx'\n| 'Chain.base_tx' | 'AENS.pointee' | 'AENS.name' | 'MCL_BLS12_381.fr' | 'MCL_BLS12_381.fp'\n| { 'Set.set': readonly [AciValue] }\n| { bytes: number }\n| { list: readonly [AciValue] }\n| { map: readonly [AciValue, AciValue] }\n| { tuple: readonly AciValue[] }\n| { record: ReadonlyArray<{ name: string; type: AciValue }> }\n| { variant: ReadonlyArray<{ [key: string]: readonly AciValue[] }> }\n| { option: readonly [AciValue] }\n| { oracle: readonly [AciValue, AciValue] }\n| { oracle_query: readonly [AciValue, AciValue] };\n\nexport interface Domain {\n name?: string;\n version?: number;\n networkId?: string;\n contractAddress?: Encoded.ContractAddress;\n}\n\n/**\n * Hashes domain object, can be used to inline domain hash to contract source code\n */\nexport function hashDomain(domain: Domain): Buffer {\n const domainAci = {\n record: [{\n name: 'name',\n type: { option: ['string'] },\n }, {\n name: 'version',\n type: { option: ['int'] },\n }, {\n name: 'networkId',\n type: { option: ['string'] },\n }, {\n name: 'contractAddress',\n type: { option: ['contract_pubkey'] },\n }],\n } as const;\n const domainType = new TypeResolver().resolveType(domainAci, {});\n const fateValue = new ContractByteArrayEncoder().encodeWithType(domain, domainType);\n return hash(decode(fateValue));\n}\n\nexport function hashTypedData(\n data: Encoded.ContractBytearray,\n aci: AciValue,\n domain: Domain,\n): Buffer {\n return hash(concatBuffers([\n messagePrefixLength, new Uint8Array([0]), hashDomain(domain), hashJson(aci), hash(decode(data)),\n ]));\n}\n"],"mappings":"AAAA,OAAAA,sBAAA,MAAuD,0BAA0B;AAAC;EAAAC,YAAA;EAAAC;AAAA,IAAAF,sBAAA;AAClF,OAAOG,YAAY,MAAM,cAAc;AAAC,SACtBC,MAAM;AAAA,SACfC,IAAI,EAAEC,mBAAmB;AAAA,SACzBC,aAAa;AAEtB;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAACC,IAAa,EAAU;EAAA,IAAAC,aAAA;EAC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@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeternity/aepp-sdk",
3
- "version": "13.2.1",
3
+ "version": "13.2.2",
4
4
  "description": "SDK for the æternity blockchain",
5
5
  "main": "dist/aepp-sdk.js",
6
6
  "types": "es/index.d.ts",
@@ -75,7 +75,7 @@
75
75
  "SDK"
76
76
  ],
77
77
  "dependencies": {
78
- "@aeternity/aepp-calldata": "^1.4.0",
78
+ "@aeternity/aepp-calldata": "^1.5.1",
79
79
  "@aeternity/argon2": "^0.0.1",
80
80
  "@aeternity/uuid": "^0.0.1",
81
81
  "@azure/core-client": "1.6.0",
package/src/Middleware.ts CHANGED
@@ -105,7 +105,7 @@ export default class Middleware
105
105
  /**
106
106
  * @param url - Url for middleware API
107
107
  * @param options - Options
108
- * @param options.ignoreVersion - Don't check node version
108
+ * @param options.ignoreVersion - Don't ensure that the middleware is supported
109
109
  * @param options.retryCount - Amount of extra requests to do in case of failure
110
110
  * @param options.retryOverallDelay - Time in ms to wait between all retries
111
111
  */
package/src/Node.ts CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  } from './utils/autorest';
8
8
  import { Node as NodeApi, NodeOptionalParams, ErrorModel } from './apis/node';
9
9
  import { mapObject } from './utils/other';
10
+ import { UnsupportedVersionError } from './utils/errors';
10
11
  import { Encoded } from './utils/encoder';
11
12
  import { ConsensusProtocolVersion } from './tx/builder/constants';
12
13
 
@@ -116,7 +117,7 @@ export default class Node extends (NodeTransformed as unknown as NodeTransformed
116
117
  /**
117
118
  * @param url - Url for node API
118
119
  * @param options - Options
119
- * @param options.ignoreVersion - Don't check node version
120
+ * @param options.ignoreVersion - Don't ensure that the node is supported
120
121
  * @param options.retryCount - Amount of extra requests to do in case of failure
121
122
  * @param options.retryOverallDelay - Time in ms to wait between all retries
122
123
  */
@@ -161,11 +162,12 @@ export default class Node extends (NodeTransformed as unknown as NodeTransformed
161
162
 
162
163
  async getNodeInfo(): Promise<NodeInfo> {
163
164
  const {
164
- nodeVersion: version,
165
+ nodeVersion,
165
166
  networkId: nodeNetworkId,
166
167
  protocols,
167
168
  topBlockHeight,
168
169
  } = await this.getStatus();
170
+
169
171
  const consensusProtocolVersion = protocols
170
172
  .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)
171
173
  .reduce(
@@ -173,10 +175,19 @@ export default class Node extends (NodeTransformed as unknown as NodeTransformed
173
175
  { effectiveAtHeight: -1, version: 0 },
174
176
  )
175
177
  .version;
178
+ if (ConsensusProtocolVersion[consensusProtocolVersion] == null) {
179
+ const version = consensusProtocolVersion.toString();
180
+ const versions = Object.values(ConsensusProtocolVersion)
181
+ .filter((el) => typeof el === 'number').map((el) => +el);
182
+ const geVersion = Math.min(...versions).toString();
183
+ const ltVersion = (Math.max(...versions) + 1).toString();
184
+ throw new UnsupportedVersionError('consensus protocol', version, geVersion, ltVersion);
185
+ }
186
+
176
187
  return {
177
188
  url: this.$host,
178
189
  nodeNetworkId,
179
- version,
190
+ version: nodeVersion,
180
191
  consensusProtocolVersion,
181
192
  };
182
193
  }
@@ -9,7 +9,7 @@ export interface WalletInfo {
9
9
  id: string;
10
10
  name: string;
11
11
  networkId: string;
12
- origin: string;
12
+ origin: string; // TODO: origin needs to be provided by transport
13
13
  type: WALLET_TYPE;
14
14
  }
15
15
 
@@ -1,14 +1,11 @@
1
1
  import BrowserConnection from './connection/Browser';
2
2
  import BrowserWindowMessageConnection from './connection/BrowserWindowMessage';
3
3
  import { MESSAGE_DIRECTION, METHODS } from './schema';
4
+ import { WalletInfo } from './rpc/types';
4
5
  import { UnsupportedPlatformError } from '../utils/errors';
5
6
 
6
7
  interface Wallet {
7
- info: {
8
- id: string;
9
- type: string;
10
- origin: string;
11
- };
8
+ info: WalletInfo;
12
9
  getConnection: () => BrowserWindowMessageConnection;
13
10
  }
14
11
  interface Wallets { [key: string]: Wallet }
@@ -28,7 +25,7 @@ export default (
28
25
  const wallets: Wallets = {};
29
26
 
30
27
  connection.connect((
31
- { method, params }: { method: string; params: Wallet['info'] },
28
+ { method, params }: { method: string; params: WalletInfo },
32
29
  origin: string,
33
30
  source: Window,
34
31
  ) => {
@@ -37,12 +34,15 @@ export default (
37
34
  const wallet = {
38
35
  info: params,
39
36
  getConnection() {
40
- const isExtension = params.type === 'extension';
41
37
  return new BrowserWindowMessageConnection({
42
- sendDirection: isExtension ? MESSAGE_DIRECTION.to_waellet : undefined,
43
- receiveDirection: isExtension ? MESSAGE_DIRECTION.to_aepp : undefined,
44
38
  target: source,
45
- origin: isExtension ? window.origin : params.origin,
39
+ ...params.type === 'extension' ? {
40
+ sendDirection: MESSAGE_DIRECTION.to_waellet,
41
+ receiveDirection: MESSAGE_DIRECTION.to_aepp,
42
+ ...window.origin !== 'null' && { origin: window.origin },
43
+ } : {
44
+ origin: params.origin,
45
+ },
46
46
  });
47
47
  },
48
48
  };
@@ -44,6 +44,7 @@ import {
44
44
  } from '../chain';
45
45
  import AccountBase from '../account/Base';
46
46
  import { TxUnpacked } from '../tx/builder/schema.generated';
47
+ import { isAccountNotFoundError } from '../utils/other';
47
48
 
48
49
  type ContractAci = NonNullable<Aci[0]['contract']>;
49
50
  type FunctionAci = ContractAci['functions'][0];
@@ -122,7 +123,7 @@ interface GetCallResultByHashReturnType<M extends ContractMethodsBase, Fn extend
122
123
  * const staticCallResult = await contractIns.$call('setState', [123], { callStatic: true })
123
124
  * ```
124
125
  * Also you can call contract like: `await contractIns.setState(123, options)`
125
- * Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is
126
+ * Then sdk decide to make on-chain or static call (dry-run API) transaction based on function is
126
127
  * stateful or not
127
128
  */
128
129
  class Contract<M extends ContractMethodsBase> {
@@ -252,12 +253,12 @@ class Contract<M extends ContractMethodsBase> {
252
253
  code: this.$options.bytecode,
253
254
  ownerId,
254
255
  });
255
- this.$options.address = buildContractIdByContractTx(tx);
256
256
  const { hash, ...other } = await this.#sendAndProcess(
257
257
  tx,
258
258
  'init',
259
259
  { ...opt, onAccount: opt.onAccount },
260
260
  );
261
+ this.$options.address = buildContractIdByContractTx(tx);
261
262
  return {
262
263
  ...other,
263
264
  ...other.result?.log != null && {
@@ -332,10 +333,15 @@ class Contract<M extends ContractMethodsBase> {
332
333
  const callData = this._calldata.encode(this._name, fn, params);
333
334
 
334
335
  if (callStatic === true) {
335
- if (opt.nonce == null && top != null) {
336
- const topKey = typeof top === 'number' ? 'height' : 'hash';
337
- opt.nonce = (await getAccount(callerId, { [topKey]: top, onNode })).nonce + 1;
336
+ if (opt.nonce == null) {
337
+ const topOption = top != null && { [typeof top === 'number' ? 'height' : 'hash']: top };
338
+ const account = await getAccount(callerId, { ...topOption, onNode }).catch((error) => {
339
+ if (!isAccountNotFoundError(error)) throw error;
340
+ return { kind: 'basic', nonce: 0 };
341
+ });
342
+ opt.nonce = account.kind === 'generalized' ? 0 : account.nonce + 1;
338
343
  }
344
+
339
345
  const txOpt = { ...opt, onNode, callData };
340
346
  let tx;
341
347
  if (fn === 'init') {
@@ -17,14 +17,19 @@ const getPackagePath = (): string => {
17
17
  };
18
18
 
19
19
  /**
20
- * A wrapper around aesophia_cli, available only in Node.js
21
- * Assumes that `escript` is available in PATH.
20
+ * A wrapper around aesophia_cli, available only in Node.js.
21
+ * Requires Erlang installed, assumes that `escript` is available in PATH.
22
22
  */
23
23
  export default class CompilerCli extends CompilerBase {
24
24
  #path: string;
25
25
 
26
26
  #ensureCompatibleVersion = Promise.resolve();
27
27
 
28
+ /**
29
+ * @param compilerPath - A path to aesophia_cli binary, by default uses the integrated one
30
+ * @param options - Options
31
+ * @param options.ignoreVersion - Don't ensure that the compiler is supported
32
+ */
28
33
  constructor(
29
34
  compilerPath = resolve(getPackagePath(), './bin/aesophia_cli'),
30
35
  { ignoreVersion }: { ignoreVersion?: boolean } = {},
package/src/deprecated.ts CHANGED
@@ -1,10 +1,12 @@
1
+ import { TypeResolver, ContractByteArrayEncoder } from '@aeternity/aepp-calldata';
2
+ import { AciValue } from './utils/typed-data';
3
+ import { Encoded } from './utils/encoder';
1
4
  import { RpcError } from './aepp-wallet-communication/schema';
2
5
 
3
6
  /**
4
7
  * @category exception
5
8
  * @deprecated this exception is not thrown anymore
6
9
  */
7
- // eslint-disable-next-line import/prefer-default-export
8
10
  export class RpcBroadcastError extends RpcError {
9
11
  static override code = 3;
10
12
 
@@ -21,3 +23,19 @@ export class RpcBroadcastError extends RpcError {
21
23
  * @deprecated use isAuctionName instead
22
24
  */
23
25
  export const NAME_BID_MAX_LENGTH = 12; // # this is the max length for a domain to be part of a bid
26
+
27
+ /**
28
+ * @deprecated use ContractByteArrayEncoder:encodeWithType from \@aeternity/aepp-calldata
29
+ */
30
+ export function encodeFateValue(value: unknown, aci: AciValue): Encoded.ContractBytearray {
31
+ const valueType = new TypeResolver().resolveType(aci, {});
32
+ return new ContractByteArrayEncoder().encodeWithType(value, valueType);
33
+ }
34
+
35
+ /**
36
+ * @deprecated use ContractByteArrayEncoder:decodeWithType from \@aeternity/aepp-calldata
37
+ */
38
+ export function decodeFateValue(value: Encoded.ContractBytearray, aci: AciValue): any {
39
+ const valueType = new TypeResolver().resolveType(aci, {});
40
+ return new ContractByteArrayEncoder().decodeWithType(value, valueType);
41
+ }
@@ -43,9 +43,7 @@ export {
43
43
  export {
44
44
  encode, decode, Encoding, Encoded,
45
45
  } from './utils/encoder';
46
- export {
47
- encodeFateValue, decodeFateValue, hashTypedData, hashDomain, hashJson,
48
- } from './utils/typed-data';
46
+ export { hashTypedData, hashDomain, hashJson } from './utils/typed-data';
49
47
  export {
50
48
  aensRevoke, aensUpdate, aensTransfer, aensQuery, aensClaim, aensPreclaim, aensBid,
51
49
  } from './aens';
@@ -111,4 +109,6 @@ export {
111
109
  TagNotFoundError, TxNotInChainError, AlreadyConnectedError, NoWalletConnectedError,
112
110
  RpcConnectionError,
113
111
  } from './utils/errors';
114
- export { RpcBroadcastError, NAME_BID_MAX_LENGTH } from './deprecated';
112
+ export {
113
+ RpcBroadcastError, NAME_BID_MAX_LENGTH, encodeFateValue, decodeFateValue,
114
+ } from './deprecated';
@@ -74,6 +74,7 @@ export enum VmVersion {
74
74
  Fate = 5,
75
75
  SophiaImprovementsLima = 6,
76
76
  Fate2 = 7,
77
+ Fate3 = 8,
77
78
  }
78
79
 
79
80
  /**
@@ -19,7 +19,7 @@ export const ProtocolToVmAbi = {
19
19
  },
20
20
  [ConsensusProtocolVersion.Ceres]: {
21
21
  'contract-create': {
22
- vmVersion: [VmVersion.Fate2], abiVersion: [AbiVersion.Fate],
22
+ vmVersion: [VmVersion.Fate3], abiVersion: [AbiVersion.Fate],
23
23
  },
24
24
  'contract-call': {
25
25
  vmVersion: [], abiVersion: [AbiVersion.Fate],
@@ -156,7 +156,7 @@ export default {
156
156
  const value = new BigNumber(_value ?? minFee);
157
157
  if (minFee.gt(value)) {
158
158
  if (_pickBiggerFee === true) return minFee.toFixed();
159
- throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger then ${minFee}`);
159
+ throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger than ${minFee}`);
160
160
  }
161
161
  return value.toFixed();
162
162
  },
@@ -7,7 +7,7 @@ export default {
7
7
 
8
8
  serializeAettos(value: string | undefined = MIN_GAS_PRICE.toString()): string {
9
9
  if (+value < MIN_GAS_PRICE) {
10
- throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger then ${MIN_GAS_PRICE}`);
10
+ throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger than ${MIN_GAS_PRICE}`);
11
11
  }
12
12
  return value;
13
13
  },
@@ -15,10 +15,10 @@ export const genRequestQueuesPolicy = (): AdditionalPolicyConfig => {
15
15
  request.headers.delete('__queue');
16
16
  const getResponse = async (): Promise<PipelineResponse> => next(request);
17
17
  if (key == null) return getResponse();
18
- const req = (requestQueues.get(key) ?? Promise.resolve()).then(getResponse, getResponse);
19
- // TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803
18
+ const req = (requestQueues.get(key) ?? Promise.resolve()).then(getResponse);
19
+ // TODO: remove pause after fixing https://github.com/aeternity/aeternity/issues/3803
20
20
  // gap to ensure that node won't reject the nonce
21
- requestQueues.set(key, req.then(async () => pause(750)));
21
+ requestQueues.set(key, req.then(async () => pause(750), () => {}));
22
22
  return req;
23
23
  },
24
24
  },
@@ -119,7 +119,7 @@ export const genRetryOnFailurePolicy = (
119
119
  policy: {
120
120
  name: 'retry-on-failure',
121
121
  async sendRequest(request, next) {
122
- const statusesToNotRetry = [200, 400, 403];
122
+ const statusesToNotRetry = [200, 400, 403, 500];
123
123
 
124
124
  const intervals = new Array(retryCount).fill(0)
125
125
  .map((_, idx) => ((idx + 1) / retryCount) ** 2);
@@ -190,7 +190,7 @@ export function verifyMessage(
190
190
  /**
191
191
  * Check key pair for validity
192
192
  *
193
- * Sign a message, and then verifying that signature
193
+ * Signs a message, and then verifies that signature
194
194
  * @param privateKey - Private key to verify
195
195
  * @param publicKey - Public key to verify as hex string
196
196
  * @returns Valid?
@@ -1,10 +1,4 @@
1
- // js extension is required for mjs build
2
- // @ts-expect-error see https://github.com/aeternity/aepp-calldata-js/issues/216
3
- // eslint-disable-next-line import/extensions
4
- import ContractByteArrayEncoder from '@aeternity/aepp-calldata/src/ContractByteArrayEncoder.js';
5
- // @ts-expect-error see https://github.com/aeternity/aepp-calldata-js/issues/216
6
- // eslint-disable-next-line import/extensions
7
- import AciTypeResolver from '@aeternity/aepp-calldata/src/AciTypeResolver.js';
1
+ import { TypeResolver, ContractByteArrayEncoder } from '@aeternity/aepp-calldata';
8
2
  import canonicalize from 'canonicalize';
9
3
  import { Encoded, decode } from './encoder';
10
4
  import { hash, messagePrefixLength } from './crypto';
@@ -40,28 +34,6 @@ export interface Domain {
40
34
  contractAddress?: Encoded.ContractAddress;
41
35
  }
42
36
 
43
- // TODO: replace with api on calldata side https://github.com/aeternity/aepp-calldata-js/issues/216
44
- export function encodeFateValue(
45
- value: unknown,
46
- aci: AciValue,
47
- ): Encoded.ContractBytearray {
48
- const contractByteArrayEncoder = new ContractByteArrayEncoder();
49
- const aciTypeResolver = new AciTypeResolver([]);
50
- aciTypeResolver.isCustomType = () => false;
51
- return contractByteArrayEncoder.encode(aciTypeResolver.resolveType(aci), value);
52
- }
53
-
54
- // TODO: replace with api on calldata side https://github.com/aeternity/aepp-calldata-js/issues/216
55
- export function decodeFateValue(
56
- value: Encoded.ContractBytearray,
57
- aci: AciValue,
58
- ): Encoded.ContractBytearray {
59
- const contractByteArrayEncoder = new ContractByteArrayEncoder();
60
- const aciTypeResolver = new AciTypeResolver([]);
61
- aciTypeResolver.isCustomType = () => false;
62
- return contractByteArrayEncoder.decodeWithType(value, aciTypeResolver.resolveType(aci));
63
- }
64
-
65
37
  /**
66
38
  * Hashes domain object, can be used to inline domain hash to contract source code
67
39
  */
@@ -81,7 +53,9 @@ export function hashDomain(domain: Domain): Buffer {
81
53
  type: { option: ['contract_pubkey'] },
82
54
  }],
83
55
  } as const;
84
- return hash(decode(encodeFateValue(domain, domainAci)));
56
+ const domainType = new TypeResolver().resolveType(domainAci, {});
57
+ const fateValue = new ContractByteArrayEncoder().encodeWithType(domain, domainType);
58
+ return hash(decode(fateValue));
85
59
  }
86
60
 
87
61
  export function hashTypedData(
@@ -33,7 +33,7 @@ export default class Middleware extends Middleware_base {
33
33
  /**
34
34
  * @param url - Url for middleware API
35
35
  * @param options - Options
36
- * @param options.ignoreVersion - Don't check node version
36
+ * @param options.ignoreVersion - Don't ensure that the middleware is supported
37
37
  * @param options.retryCount - Amount of extra requests to do in case of failure
38
38
  * @param options.retryOverallDelay - Time in ms to wait between all retries
39
39
  */
@@ -67,7 +67,7 @@ export default class Node extends Node_base {
67
67
  /**
68
68
  * @param url - Url for node API
69
69
  * @param options - Options
70
- * @param options.ignoreVersion - Don't check node version
70
+ * @param options.ignoreVersion - Don't ensure that the node is supported
71
71
  * @param options.retryCount - Amount of extra requests to do in case of failure
72
72
  * @param options.retryOverallDelay - Time in ms to wait between all retries
73
73
  */
@@ -1,11 +1,8 @@
1
1
  import BrowserConnection from './connection/Browser';
2
2
  import BrowserWindowMessageConnection from './connection/BrowserWindowMessage';
3
+ import { WalletInfo } from './rpc/types';
3
4
  interface Wallet {
4
- info: {
5
- id: string;
6
- type: string;
7
- origin: string;
8
- };
5
+ info: WalletInfo;
9
6
  getConnection: () => BrowserWindowMessageConnection;
10
7
  }
11
8
  interface Wallets {
@@ -81,7 +81,7 @@ interface GetCallResultByHashReturnType<M extends ContractMethodsBase, Fn extend
81
81
  * const staticCallResult = await contractIns.$call('setState', [123], { callStatic: true })
82
82
  * ```
83
83
  * Also you can call contract like: `await contractIns.setState(123, options)`
84
- * Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is
84
+ * Then sdk decide to make on-chain or static call (dry-run API) transaction based on function is
85
85
  * stateful or not
86
86
  */
87
87
  declare class Contract<M extends ContractMethodsBase> {
@@ -1,11 +1,16 @@
1
1
  import CompilerBase, { Aci } from './Base';
2
2
  import { Encoded } from '../../utils/encoder';
3
3
  /**
4
- * A wrapper around aesophia_cli, available only in Node.js
5
- * Assumes that `escript` is available in PATH.
4
+ * A wrapper around aesophia_cli, available only in Node.js.
5
+ * Requires Erlang installed, assumes that `escript` is available in PATH.
6
6
  */
7
7
  export default class CompilerCli extends CompilerBase {
8
8
  #private;
9
+ /**
10
+ * @param compilerPath - A path to aesophia_cli binary, by default uses the integrated one
11
+ * @param options - Options
12
+ * @param options.ignoreVersion - Don't ensure that the compiler is supported
13
+ */
9
14
  constructor(compilerPath?: string, { ignoreVersion }?: {
10
15
  ignoreVersion?: boolean;
11
16
  });
@@ -1,3 +1,5 @@
1
+ import { AciValue } from './utils/typed-data';
2
+ import { Encoded } from './utils/encoder';
1
3
  import { RpcError } from './aepp-wallet-communication/schema';
2
4
  /**
3
5
  * @category exception
@@ -12,3 +14,11 @@ export declare class RpcBroadcastError extends RpcError {
12
14
  * @deprecated use isAuctionName instead
13
15
  */
14
16
  export declare const NAME_BID_MAX_LENGTH = 12;
17
+ /**
18
+ * @deprecated use ContractByteArrayEncoder:encodeWithType from \@aeternity/aepp-calldata
19
+ */
20
+ export declare function encodeFateValue(value: unknown, aci: AciValue): Encoded.ContractBytearray;
21
+ /**
22
+ * @deprecated use ContractByteArrayEncoder:decodeWithType from \@aeternity/aepp-calldata
23
+ */
24
+ export declare function decodeFateValue(value: Encoded.ContractBytearray, aci: AciValue): any;