@aeternity/aepp-sdk 13.1.0 → 13.2.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 (159) 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 +2162 -1566
  6. package/dist/aepp-sdk.js.map +1 -1
  7. package/es/AeSdkAepp.mjs.map +1 -1
  8. package/es/AeSdkBase.d.ts +10 -0
  9. package/es/AeSdkBase.mjs +27 -0
  10. package/es/AeSdkBase.mjs.map +1 -1
  11. package/es/AeSdkMethods.mjs.map +1 -1
  12. package/es/AeSdkWallet.d.ts +1 -1
  13. package/es/AeSdkWallet.mjs +53 -20
  14. package/es/AeSdkWallet.mjs.map +1 -1
  15. package/es/Middleware.mjs.map +1 -1
  16. package/es/MiddlewareSubscriber.mjs +3 -3
  17. package/es/MiddlewareSubscriber.mjs.map +1 -1
  18. package/es/Node.mjs.map +1 -1
  19. package/es/account/Base.d.ts +44 -2
  20. package/es/account/Base.mjs +95 -1
  21. package/es/account/Base.mjs.map +1 -1
  22. package/es/account/Generalized.d.ts +3 -0
  23. package/es/account/Generalized.mjs +15 -0
  24. package/es/account/Generalized.mjs.map +1 -1
  25. package/es/account/Ledger.d.ts +3 -0
  26. package/es/account/Ledger.mjs +15 -0
  27. package/es/account/Ledger.mjs.map +1 -1
  28. package/es/account/LedgerFactory.mjs.map +1 -1
  29. package/es/account/Memory.d.ts +10 -0
  30. package/es/account/Memory.mjs +34 -0
  31. package/es/account/Memory.mjs.map +1 -1
  32. package/es/account/Rpc.d.ts +4 -0
  33. package/es/account/Rpc.mjs +29 -0
  34. package/es/account/Rpc.mjs.map +1 -1
  35. package/es/aens.mjs.map +1 -1
  36. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
  37. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  38. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
  39. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
  40. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  41. package/es/aepp-wallet-communication/rpc/types.d.ts +9 -0
  42. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  43. package/es/aepp-wallet-communication/schema.d.ts +1 -0
  44. package/es/aepp-wallet-communication/schema.mjs +20 -19
  45. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  46. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  47. package/es/apis/compiler/compiler.mjs.map +1 -1
  48. package/es/apis/middleware/middleware.mjs.map +1 -1
  49. package/es/apis/middleware/models/index.mjs +340 -124
  50. package/es/apis/middleware/models/index.mjs.map +1 -1
  51. package/es/apis/node/node.mjs.map +1 -1
  52. package/es/chain.mjs +1 -1
  53. package/es/chain.mjs.map +1 -1
  54. package/es/channel/Base.mjs.map +1 -1
  55. package/es/channel/Contract.mjs.map +1 -1
  56. package/es/channel/Spend.mjs.map +1 -1
  57. package/es/channel/handlers.mjs +2 -2
  58. package/es/channel/handlers.mjs.map +1 -1
  59. package/es/channel/internal.mjs +6 -6
  60. package/es/channel/internal.mjs.map +1 -1
  61. package/es/contract/Contract.mjs +1 -1
  62. package/es/contract/Contract.mjs.map +1 -1
  63. package/es/contract/compiler/Cli.mjs.map +1 -1
  64. package/es/contract/compiler/Http.mjs.map +1 -1
  65. package/es/contract/delegation-signature.d.ts +2 -1
  66. package/es/contract/delegation-signature.mjs +39 -8
  67. package/es/contract/delegation-signature.mjs.map +1 -1
  68. package/es/contract/ga.mjs.map +1 -1
  69. package/es/oracle.mjs.map +1 -1
  70. package/es/spend.d.ts +2 -1
  71. package/es/spend.mjs +4 -2
  72. package/es/spend.mjs.map +1 -1
  73. package/es/tx/builder/constants.mjs +26 -23
  74. package/es/tx/builder/constants.mjs.map +1 -1
  75. package/es/tx/builder/field-types/abi-version.mjs.map +1 -1
  76. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
  77. package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
  78. package/es/tx/builder/field-types/deposit.mjs.map +1 -1
  79. package/es/tx/builder/field-types/entry.mjs.map +1 -1
  80. package/es/tx/builder/field-types/fee.mjs.map +1 -1
  81. package/es/tx/builder/field-types/field.mjs.map +1 -1
  82. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
  83. package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
  84. package/es/tx/builder/field-types/index.d.ts +28 -150
  85. package/es/tx/builder/field-types/index.mjs +28 -56
  86. package/es/tx/builder/field-types/index.mjs.map +1 -1
  87. package/es/tx/builder/field-types/map.mjs.map +1 -1
  88. package/es/tx/builder/field-types/mptree.mjs +3 -3
  89. package/es/tx/builder/field-types/mptree.mjs.map +1 -1
  90. package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
  91. package/es/tx/builder/field-types/pointers.mjs.map +1 -1
  92. package/es/tx/builder/field-types/string.mjs.map +1 -1
  93. package/es/tx/builder/field-types/ttl.mjs.map +1 -1
  94. package/es/tx/builder/field-types/u-int.mjs +1 -1
  95. package/es/tx/builder/field-types/u-int.mjs.map +1 -1
  96. package/es/tx/builder/helpers.mjs.map +1 -1
  97. package/es/tx/builder/index.mjs.map +1 -1
  98. package/es/tx/builder/schema.mjs +11 -10
  99. package/es/tx/builder/schema.mjs.map +1 -1
  100. package/es/tx/execution-cost.mjs.map +1 -1
  101. package/es/tx/transaction-signer.mjs.map +1 -1
  102. package/es/tx/validator.mjs.map +1 -1
  103. package/es/utils/amount-formatter.mjs +7 -7
  104. package/es/utils/amount-formatter.mjs.map +1 -1
  105. package/es/utils/autorest.mjs.map +1 -1
  106. package/es/utils/bignumber.mjs.map +1 -1
  107. package/es/utils/bytes.mjs.map +1 -1
  108. package/es/utils/crypto.mjs.map +1 -1
  109. package/es/utils/encoder-types.mjs +3 -3
  110. package/es/utils/encoder-types.mjs.map +1 -1
  111. package/es/utils/encoder.mjs.map +1 -1
  112. package/es/utils/errors.mjs.map +1 -1
  113. package/es/utils/hd-wallet.mjs.map +1 -1
  114. package/es/utils/keystore.mjs.map +1 -1
  115. package/es/utils/other.mjs.map +1 -1
  116. package/es/utils/semver-satisfies.mjs.map +1 -1
  117. package/es/utils/string.mjs.map +1 -1
  118. package/es/utils/typed-data.mjs +0 -1
  119. package/es/utils/typed-data.mjs.map +1 -1
  120. package/package.json +35 -35
  121. package/src/AeSdkBase.ts +36 -0
  122. package/src/AeSdkWallet.ts +36 -12
  123. package/src/account/Base.ts +84 -3
  124. package/src/account/Generalized.ts +15 -0
  125. package/src/account/Ledger.ts +15 -0
  126. package/src/account/Memory.ts +53 -1
  127. package/src/account/Rpc.ts +35 -0
  128. package/src/aepp-wallet-communication/rpc/types.ts +10 -0
  129. package/src/aepp-wallet-communication/schema.ts +1 -0
  130. package/src/chain.ts +1 -1
  131. package/src/contract/Contract.ts +1 -1
  132. package/src/contract/delegation-signature.ts +37 -11
  133. package/src/spend.ts +2 -2
  134. package/src/tx/builder/field-types/index.ts +28 -58
  135. package/src/tx/builder/field-types/u-int.ts +1 -1
  136. package/types-legacy/ts4.2/AeSdkBase.d.ts +10 -0
  137. package/types-legacy/ts4.2/AeSdkWallet.d.ts +1 -1
  138. package/types-legacy/ts4.2/account/Base.d.ts +44 -2
  139. package/types-legacy/ts4.2/account/Generalized.d.ts +3 -0
  140. package/types-legacy/ts4.2/account/Ledger.d.ts +3 -0
  141. package/types-legacy/ts4.2/account/Memory.d.ts +10 -0
  142. package/types-legacy/ts4.2/account/Rpc.d.ts +4 -0
  143. package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +9 -0
  144. package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +1 -0
  145. package/types-legacy/ts4.2/contract/delegation-signature.d.ts +2 -1
  146. package/types-legacy/ts4.2/spend.d.ts +2 -1
  147. package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +28 -153
  148. package/types-legacy/ts4.5/AeSdkBase.d.ts +10 -0
  149. package/types-legacy/ts4.5/AeSdkWallet.d.ts +1 -1
  150. package/types-legacy/ts4.5/account/Base.d.ts +44 -2
  151. package/types-legacy/ts4.5/account/Generalized.d.ts +3 -0
  152. package/types-legacy/ts4.5/account/Ledger.d.ts +3 -0
  153. package/types-legacy/ts4.5/account/Memory.d.ts +10 -0
  154. package/types-legacy/ts4.5/account/Rpc.d.ts +4 -0
  155. package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +9 -0
  156. package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +1 -0
  157. package/types-legacy/ts4.5/contract/delegation-signature.d.ts +2 -1
  158. package/types-legacy/ts4.5/spend.d.ts +2 -1
  159. package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +28 -153
@@ -1 +1 @@
1
- {"version":3,"file":"MiddlewareSubscriber.mjs","names":["WebSocket","BaseError","UnexpectedTsError","InternalError","Source","MiddlewareSubscriberError","constructor","message","name","MiddlewareSubscriberDisconnected","closeEvent","_subscriptions","WeakMap","_requestQueue","_webSocket","_targets","_sendMessage","WeakSet","_sendSubscribe","_emit","_disconnect","_messageHandler","_subscribe","MiddlewareSubscriber","webSocket","_classPrivateFieldGet","url","_classPrivateMethodInitSpec","_classPrivateFieldInitSpec","get","_get_targets","set","writable","value","reconnect","_classPrivateMethodGet","_disconnect2","call","_classPrivateFieldSet","Promise","resolve","Object","assign","onopen","onerror","errorEvent","_emit2","undefined","error","onmessage","event","data","_messageHandler2","JSON","parse","onclose","all","map","target","_sendSubscribe2","subscribeKeyBlocks","cb","_subscribe2","Middleware","subscribeKeyBlocksNode","Node","subscribeKeyBlocksAll","All","subscribeMicroBlocks","subscribeMicroBlocksNode","subscribeMicroBlocksAll","subscribeTransactions","subscribeTransactionsNode","subscribeTransactionsAll","subscribeObject","subscribeObjectNode","subscribeObjectAll","Set","_ref","_sendMessage2","send","stringify","isSubscribe","payload","includes","op","push","condition","p","e","filter","_ref2","source","forEach","_ref3","onlyReset","arguments","length","close","Array","isArray","request","shift","t","subscription","size","has","item"],"sources":["../src/MiddlewareSubscriber.ts"],"sourcesContent":["/* eslint-disable max-classes-per-file */\nimport WebSocket from 'isomorphic-ws';\nimport { BaseError, UnexpectedTsError, InternalError } from './utils/errors';\nimport { Encoded } from './utils/encoder';\n\ninterface Message {\n payload: Object;\n source: Source.Middleware | Source.Node;\n subscription: 'KeyBlocks' | 'MicroBlocks' | 'Transactions' | 'Object';\n target?: string;\n}\n\nenum Source {\n Middleware = 'mdw',\n Node = 'node',\n All = 'all',\n}\n\nexport class MiddlewareSubscriberError extends BaseError {\n constructor(message: string) {\n super(message);\n this.name = 'MiddlewareSubscriberError';\n }\n}\n\nexport class MiddlewareSubscriberDisconnected extends MiddlewareSubscriberError {\n constructor(readonly closeEvent: WebSocket.CloseEvent) {\n super('Connection closed');\n this.name = 'MiddlewareSubscriberDisconnected';\n }\n}\n\nexport default class MiddlewareSubscriber {\n #subscriptions: Array<\n readonly [target: string, s: Source, cb: (p?: Object, e?: Error) => void]\n > = [];\n\n #requestQueue: Array<[isSubscribe: boolean, target: string]> = [];\n\n #webSocket?: WebSocket;\n\n get webSocket(): WebSocket | undefined {\n return this.#webSocket;\n }\n\n get #targets(): Set<string> {\n return new Set(this.#subscriptions.map(([target]) => target));\n }\n\n #sendMessage(message: any): void {\n if (this.#webSocket == null) throw new UnexpectedTsError();\n this.#webSocket.send(JSON.stringify(message));\n }\n\n #sendSubscribe(isSubscribe: boolean, target: string): void {\n if (this.#webSocket == null) return;\n const payload = ['KeyBlocks', 'MicroBlocks', 'Transactions'].includes(target)\n ? target : 'Object';\n this.#sendMessage({\n op: isSubscribe ? 'Subscribe' : 'Unsubscribe',\n payload,\n ...payload === 'Object' && { target },\n });\n this.#requestQueue.push([isSubscribe, target]);\n }\n\n #emit(condition: (target: string, source: Source) => boolean, p?: Object, e?: Error): void {\n this.#subscriptions\n .filter(([target, source]) => condition(target, source))\n .forEach(([, , cb]) => cb(p, e));\n }\n\n constructor(readonly url: string) {\n }\n\n #disconnect(onlyReset = false): void {\n if (this.#webSocket == null) return;\n if (!onlyReset) this.#webSocket.close();\n Object.assign(this.#webSocket, {\n onopen: undefined,\n onerror: undefined,\n onmessage: undefined,\n });\n this.#webSocket = undefined;\n }\n\n async reconnect(): Promise<void> {\n this.#disconnect();\n this.#webSocket = await new Promise((resolve) => {\n const webSocket = new WebSocket(this.url);\n Object.assign(webSocket, {\n onopen: () => resolve(webSocket),\n onerror: (errorEvent: WebSocket.ErrorEvent) => {\n this.#emit(() => true, undefined, errorEvent.error);\n },\n onmessage: (event: WebSocket.MessageEvent) => {\n if (typeof event.data !== 'string') {\n throw new InternalError(`Unknown incoming message type: ${typeof event.data}`);\n }\n this.#messageHandler(JSON.parse(event.data));\n },\n onclose: (event: WebSocket.CloseEvent) => {\n this.#emit(() => true, undefined, new MiddlewareSubscriberDisconnected(event));\n this.#disconnect(true);\n },\n });\n });\n await Promise.all([...this.#targets].map((target) => this.#sendSubscribe(true, target)));\n }\n\n #messageHandler(message: string | string[] | Message): void {\n if (typeof message === 'string' || Array.isArray(message)) {\n const request = this.#requestQueue.shift();\n if (request == null) throw new InternalError('Request queue is empty');\n const [isSubscribe, target] = request;\n let error;\n if (typeof message === 'string') error = new MiddlewareSubscriberError(message);\n if (message.includes(target) !== isSubscribe) {\n error = new InternalError(`Expected ${target} to be${isSubscribe ? '' : ' not'} included into ${message}`);\n }\n if (error != null) this.#emit((t) => target === t, undefined, error);\n return;\n }\n this.#emit(\n (target, source) => (target === message.subscription || target === message.target)\n && (source === message.source || source === Source.All),\n message.payload,\n );\n }\n\n #subscribe(target: string, source: Source, cb: (p?: Object, e?: Error) => void): () => void {\n const subscription = [target, source, cb] as const;\n if (this.#targets.size === 0) this.reconnect();\n if (!this.#targets.has(target)) this.#sendSubscribe(true, target);\n this.#subscriptions.push(subscription);\n return () => {\n this.#subscriptions = this.#subscriptions.filter((item) => item !== subscription);\n if (!this.#targets.has(target)) this.#sendSubscribe(false, target);\n if (this.#targets.size === 0) this.#disconnect();\n };\n }\n\n // TODO: replace p?: any with a proper type definition\n\n subscribeKeyBlocks(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('KeyBlocks', Source.Middleware, cb);\n }\n\n subscribeKeyBlocksNode(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('KeyBlocks', Source.Node, cb);\n }\n\n subscribeKeyBlocksAll(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('KeyBlocks', Source.All, cb);\n }\n\n subscribeMicroBlocks(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('MicroBlocks', Source.Middleware, cb);\n }\n\n subscribeMicroBlocksNode(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('MicroBlocks', Source.Node, cb);\n }\n\n subscribeMicroBlocksAll(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('MicroBlocks', Source.All, cb);\n }\n\n subscribeTransactions(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('Transactions', Source.Middleware, cb);\n }\n\n subscribeTransactionsNode(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('Transactions', Source.Node, cb);\n }\n\n subscribeTransactionsAll(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('Transactions', Source.All, cb);\n }\n\n subscribeObject(\n target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress\n | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress\n | Encoded.Name | `${string}.chain`,\n cb: (p?: any, e?: Error) => void,\n ): () => void {\n return this.#subscribe(target, Source.Middleware, cb);\n }\n\n subscribeObjectNode(\n target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress\n | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress\n | Encoded.Name | `${string}.chain`,\n cb: (p?: any, e?: Error) => void,\n ): () => void {\n return this.#subscribe(target, Source.Node, cb);\n }\n\n subscribeObjectAll(\n target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress\n | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress\n | Encoded.Name | `${string}.chain`,\n cb: (p?: any, e?: Error) => void,\n ): () => void {\n return this.#subscribe(target, Source.All, cb);\n }\n}\n"],"mappings":";;;;;;AAAA;AACA,OAAOA,SAAS,MAAM,eAAe;AAAC,SAC7BC,SAAS,EAAEC,iBAAiB,EAAEC,aAAa;AAAA,IAU/CC,MAAM;AAAA,WAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;AAAA,GAANA,MAAM,KAANA,MAAM;AAMX,OAAO,MAAMC,yBAAyB,SAASJ,SAAS,CAAC;EACvDK,WAAWA,CAACC,OAAe,EAAE;IAC3B,KAAK,CAACA,OAAO,CAAC;IACd,IAAI,CAACC,IAAI,GAAG,2BAA2B;EACzC;AACF;AAEA,OAAO,MAAMC,gCAAgC,SAASJ,yBAAyB,CAAC;EAC9EC,WAAWA,CAAUI,UAAgC,EAAE;IACrD,KAAK,CAAC,mBAAmB,CAAC;IAAC,KADRA,UAAgC,GAAhCA,UAAgC;IAEnD,IAAI,CAACF,IAAI,GAAG,kCAAkC;EAChD;AACF;AAAC,IAAAG,cAAA,oBAAAC,OAAA;AAAA,IAAAC,aAAA,oBAAAD,OAAA;AAAA,IAAAE,UAAA,oBAAAF,OAAA;AAAA,IAAAG,QAAA,oBAAAH,OAAA;AAAA,IAAAI,YAAA,oBAAAC,OAAA;AAAA,IAAAC,cAAA,oBAAAD,OAAA;AAAA,IAAAE,KAAA,oBAAAF,OAAA;AAAA,IAAAG,WAAA,oBAAAH,OAAA;AAAA,IAAAI,eAAA,oBAAAJ,OAAA;AAAA,IAAAK,UAAA,oBAAAL,OAAA;AAED,eAAe,MAAMM,oBAAoB,CAAC;EASxC,IAAIC,SAASA,CAAA,EAA0B;IACrC,OAAAC,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AEUJ,MAAc,EAAEkC,MAAc,EAAE/B,EAAmC,EAAc;EAC1F,MAAM2C,YAAY,GAAG,CAAC9C,MAAM,EAAEkC,MAAM,EAAE/B,EAAE,CAAU;EAClD,IAAIpC,qBAAA,KAAI,EAAAV,QAAA,EAAU0F,IAAI,KAAK,CAAC,EAAE,IAAI,CAACvE,SAAS,EAAE;EAC9C,IAAI,CAACT,qBAAA,KAAI,EAAAV,QAAA,EAAU2F,GAAG,CAAChD,MAAM,CAAC,EAAEvB,sBAAA,KAAI,EAAAjB,cAAA,EAAAyC,eAAA,EAAAtB,IAAA,CAAJ,IAAI,EAAgB,IAAI,EAAEqB,MAAM;EAChEjC,qBAAA,KAAI,EAAAd,cAAA,EAAgB2E,IAAI,CAACkB,YAAY,CAAC;EACtC,OAAO,MAAM;IACXlE,qBAAA,KAAI,EAAA3B,cAAA,EAAkBc,qBAAA,KAAI,EAAAd,cAAA,EAAgB+E,MAAM,CAAEiB,IAAI,IAAKA,IAAI,KAAKH,YAAY,CAAC;IACjF,IAAI,CAAC/E,qBAAA,KAAI,EAAAV,QAAA,EAAU2F,GAAG,CAAChD,MAAM,CAAC,EAAEvB,sBAAA,KAAI,EAAAjB,cAAA,EAAAyC,eAAA,EAAAtB,IAAA,CAAJ,IAAI,EAAgB,KAAK,EAAEqB,MAAM;IACjE,IAAIjC,qBAAA,KAAI,EAAAV,QAAA,EAAU0F,IAAI,KAAK,CAAC,EAAEtE,sBAAA,KAAI,EAAAf,WAAA,EAAAgB,YAAA,EAAAC,IAAA,CAAJ,IAAI;EACpC,CAAC;AACH"}
1
+ {"version":3,"file":"MiddlewareSubscriber.mjs","names":["WebSocket","BaseError","UnexpectedTsError","InternalError","Source","MiddlewareSubscriberError","constructor","message","name","MiddlewareSubscriberDisconnected","closeEvent","_subscriptions","WeakMap","_requestQueue","_webSocket","_targets","_sendMessage","WeakSet","_sendSubscribe","_emit","_disconnect","_messageHandler","_subscribe","MiddlewareSubscriber","webSocket","_classPrivateFieldGet","url","_classPrivateMethodInitSpec","_classPrivateFieldInitSpec","get","_get_targets","set","writable","value","reconnect","_classPrivateMethodGet","_disconnect2","call","_classPrivateFieldSet","Promise","resolve","Object","assign","onopen","onerror","errorEvent","_emit2","undefined","error","onmessage","event","data","_messageHandler2","JSON","parse","onclose","all","map","target","_sendSubscribe2","subscribeKeyBlocks","cb","_subscribe2","Middleware","subscribeKeyBlocksNode","Node","subscribeKeyBlocksAll","All","subscribeMicroBlocks","subscribeMicroBlocksNode","subscribeMicroBlocksAll","subscribeTransactions","subscribeTransactionsNode","subscribeTransactionsAll","subscribeObject","subscribeObjectNode","subscribeObjectAll","Set","_ref","_sendMessage2","send","stringify","isSubscribe","payload","includes","op","push","condition","p","e","filter","_ref2","source","forEach","_ref3","onlyReset","arguments","length","close","Array","isArray","request","shift","t","subscription","size","has","item"],"sources":["../src/MiddlewareSubscriber.ts"],"sourcesContent":["/* eslint-disable max-classes-per-file */\nimport WebSocket from 'isomorphic-ws';\nimport { BaseError, UnexpectedTsError, InternalError } from './utils/errors';\nimport { Encoded } from './utils/encoder';\n\ninterface Message {\n payload: Object;\n source: Source.Middleware | Source.Node;\n subscription: 'KeyBlocks' | 'MicroBlocks' | 'Transactions' | 'Object';\n target?: string;\n}\n\nenum Source {\n Middleware = 'mdw',\n Node = 'node',\n All = 'all',\n}\n\nexport class MiddlewareSubscriberError extends BaseError {\n constructor(message: string) {\n super(message);\n this.name = 'MiddlewareSubscriberError';\n }\n}\n\nexport class MiddlewareSubscriberDisconnected extends MiddlewareSubscriberError {\n constructor(readonly closeEvent: WebSocket.CloseEvent) {\n super('Connection closed');\n this.name = 'MiddlewareSubscriberDisconnected';\n }\n}\n\nexport default class MiddlewareSubscriber {\n #subscriptions: Array<\n readonly [target: string, s: Source, cb: (p?: Object, e?: Error) => void]\n > = [];\n\n #requestQueue: Array<[isSubscribe: boolean, target: string]> = [];\n\n #webSocket?: WebSocket;\n\n get webSocket(): WebSocket | undefined {\n return this.#webSocket;\n }\n\n get #targets(): Set<string> {\n return new Set(this.#subscriptions.map(([target]) => target));\n }\n\n #sendMessage(message: any): void {\n if (this.#webSocket == null) throw new UnexpectedTsError();\n this.#webSocket.send(JSON.stringify(message));\n }\n\n #sendSubscribe(isSubscribe: boolean, target: string): void {\n if (this.#webSocket == null) return;\n const payload = ['KeyBlocks', 'MicroBlocks', 'Transactions'].includes(target)\n ? target : 'Object';\n this.#sendMessage({\n op: isSubscribe ? 'Subscribe' : 'Unsubscribe',\n payload,\n ...payload === 'Object' && { target },\n });\n this.#requestQueue.push([isSubscribe, target]);\n }\n\n #emit(condition: (target: string, source: Source) => boolean, p?: Object, e?: Error): void {\n this.#subscriptions\n .filter(([target, source]) => condition(target, source))\n .forEach(([, , cb]) => cb(p, e));\n }\n\n constructor(readonly url: string) {\n }\n\n #disconnect(onlyReset = false): void {\n if (this.#webSocket == null) return;\n if (!onlyReset) this.#webSocket.close();\n Object.assign(this.#webSocket, {\n onopen: undefined,\n onerror: undefined,\n onmessage: undefined,\n });\n this.#webSocket = undefined;\n }\n\n async reconnect(): Promise<void> {\n this.#disconnect();\n this.#webSocket = await new Promise((resolve) => {\n const webSocket = new WebSocket(this.url);\n Object.assign(webSocket, {\n onopen: () => resolve(webSocket),\n onerror: (errorEvent: WebSocket.ErrorEvent) => {\n this.#emit(() => true, undefined, errorEvent.error);\n },\n onmessage: (event: WebSocket.MessageEvent) => {\n if (typeof event.data !== 'string') {\n throw new InternalError(`Unknown incoming message type: ${typeof event.data}`);\n }\n this.#messageHandler(JSON.parse(event.data));\n },\n onclose: (event: WebSocket.CloseEvent) => {\n this.#emit(() => true, undefined, new MiddlewareSubscriberDisconnected(event));\n this.#disconnect(true);\n },\n });\n });\n await Promise.all([...this.#targets].map((target) => this.#sendSubscribe(true, target)));\n }\n\n #messageHandler(message: string | string[] | Message): void {\n if (typeof message === 'string' || Array.isArray(message)) {\n const request = this.#requestQueue.shift();\n if (request == null) throw new InternalError('Request queue is empty');\n const [isSubscribe, target] = request;\n let error;\n if (typeof message === 'string') error = new MiddlewareSubscriberError(message);\n if (message.includes(target) !== isSubscribe) {\n error = new InternalError(`Expected ${target} to be${isSubscribe ? '' : ' not'} included into ${message}`);\n }\n if (error != null) this.#emit((t) => target === t, undefined, error);\n return;\n }\n this.#emit(\n (target, source) => (target === message.subscription || target === message.target)\n && (source === message.source || source === Source.All),\n message.payload,\n );\n }\n\n #subscribe(target: string, source: Source, cb: (p?: Object, e?: Error) => void): () => void {\n const subscription = [target, source, cb] as const;\n if (this.#targets.size === 0) this.reconnect();\n if (!this.#targets.has(target)) this.#sendSubscribe(true, target);\n this.#subscriptions.push(subscription);\n return () => {\n this.#subscriptions = this.#subscriptions.filter((item) => item !== subscription);\n if (!this.#targets.has(target)) this.#sendSubscribe(false, target);\n if (this.#targets.size === 0) this.#disconnect();\n };\n }\n\n // TODO: replace p?: any with a proper type definition\n\n subscribeKeyBlocks(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('KeyBlocks', Source.Middleware, cb);\n }\n\n subscribeKeyBlocksNode(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('KeyBlocks', Source.Node, cb);\n }\n\n subscribeKeyBlocksAll(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('KeyBlocks', Source.All, cb);\n }\n\n subscribeMicroBlocks(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('MicroBlocks', Source.Middleware, cb);\n }\n\n subscribeMicroBlocksNode(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('MicroBlocks', Source.Node, cb);\n }\n\n subscribeMicroBlocksAll(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('MicroBlocks', Source.All, cb);\n }\n\n subscribeTransactions(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('Transactions', Source.Middleware, cb);\n }\n\n subscribeTransactionsNode(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('Transactions', Source.Node, cb);\n }\n\n subscribeTransactionsAll(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('Transactions', Source.All, cb);\n }\n\n subscribeObject(\n target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress\n | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress\n | Encoded.Name | `${string}.chain`,\n cb: (p?: any, e?: Error) => void,\n ): () => void {\n return this.#subscribe(target, Source.Middleware, cb);\n }\n\n subscribeObjectNode(\n target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress\n | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress\n | Encoded.Name | `${string}.chain`,\n cb: (p?: any, e?: Error) => void,\n ): () => void {\n return this.#subscribe(target, Source.Node, cb);\n }\n\n subscribeObjectAll(\n target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress\n | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress\n | Encoded.Name | `${string}.chain`,\n cb: (p?: any, e?: Error) => void,\n ): () => void {\n return this.#subscribe(target, Source.All, cb);\n }\n}\n"],"mappings":";;;;;;AAAA;AACA,OAAOA,SAAS,MAAM,eAAe;AAAC,SAC7BC,SAAS,EAAEC,iBAAiB,EAAEC,aAAa;AAAA,IAU/CC,MAAM,0BAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAAA,OAANA,MAAM;AAAA,EAANA,MAAM;AAMX,OAAO,MAAMC,yBAAyB,SAASJ,SAAS,CAAC;EACvDK,WAAWA,CAACC,OAAe,EAAE;IAC3B,KAAK,CAACA,OAAO,CAAC;IACd,IAAI,CAACC,IAAI,GAAG,2BAA2B;EACzC;AACF;AAEA,OAAO,MAAMC,gCAAgC,SAASJ,yBAAyB,CAAC;EAC9EC,WAAWA,CAAUI,UAAgC,EAAE;IACrD,KAAK,CAAC,mBAAmB,CAAC;IAAC,KADRA,UAAgC,GAAhCA,UAAgC;IAEnD,IAAI,CAACF,IAAI,GAAG,kCAAkC;EAChD;AACF;AAAC,IAAAG,cA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qB,MAAM;IACjE,IAAIjC,qBAAA,KAAI,EAAAV,QAAA,EAAU0F,IAAI,KAAK,CAAC,EAAEtE,sBAAA,KAAI,EAAAf,WAAA,EAAAgB,YAAA,EAAAC,IAAA,CAAJ,IAAI;EACpC,CAAC;AACH"}
package/es/Node.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Node.mjs","names":["BigNumber","genRequestQueuesPolicy","genCombineGetRequestsPolicy","genErrorFormatterPolicy","genVersionCheckPolicy","genRetryOnFailurePolicy","Node","NodeApi","mapObject","bigIntPropertyNames","numberPropertyNames","_mapData","WeakSet","_encodeArg","_decodeRes","NodeTransformed","constructor","arguments","_classPrivateMethodInitSpec","sendOperationRequest","operationArguments","operationSpec","args","_ref","key","value","_classPrivateMethodGet","_encodeArg2","call","_decodeRes2","_mapData2","data","transform","Array","isArray","map","d","_ref6","some","k","bigInt","number","toFixed","toString","BigInt","_networkIdPromise","WeakMap","url","ignoreVersion","retryCount","retryOverallDelay","options","length","undefined","allowInsecureConnection","additionalPolicies","body","reason","_classPrivateFieldInitSpec","writable","statusPromise","getStatus","versionPromise","then","_ref2","nodeVersion","error","_classPrivateFieldSet","_ref3","networkId","pipeline","addPolicy","intAsString","getNetworkId","_classPrivateFieldGet2","_classPrivateFieldGet","_ref4","Error","getNodeInfo","version","nodeNetworkId","protocols","topBlockHeight","consensusProtocolVersion","filter","_ref5","effectiveAtHeight","reduce","acc","p","$host"],"sources":["../src/Node.ts"],"sourcesContent":["// eslint-disable-next-line max-classes-per-file\nimport BigNumber from 'bignumber.js';\nimport { OperationArguments, OperationSpec } from '@azure/core-client';\nimport {\n genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterPolicy,\n genVersionCheckPolicy, genRetryOnFailurePolicy,\n} from './utils/autorest';\nimport { Node as NodeApi, NodeOptionalParams, ErrorModel } from './apis/node';\nimport { mapObject } from './utils/other';\nimport { Encoded } from './utils/encoder';\nimport { ConsensusProtocolVersion } from './tx/builder/constants';\n\nconst bigIntPropertyNames = [\n 'balance', 'queryFee', 'fee', 'amount', 'nameFee', 'channelAmount',\n 'initiatorAmount', 'responderAmount', 'channelReserve', 'initiatorAmountFinal',\n 'responderAmountFinal', 'gasPrice', 'deposit',\n] as const;\n\nconst numberPropertyNames = [\n 'time', 'gas', 'gasUsed', 'nameSalt',\n 'nonce', 'nextNonce', 'height', 'blockHeight', 'topBlockHeight',\n 'ttl', 'nameTtl', 'clientTtl',\n 'inbound', 'outbound', 'peerCount', 'pendingTransactionsCount', 'effectiveAtHeight',\n 'version', 'solutions', 'round',\n] as const;\n\nclass NodeTransformed extends NodeApi {\n override async sendOperationRequest(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n ): Promise<any> {\n const args = mapObject(\n operationArguments,\n ([key, value]) => [key, this.#encodeArg(value)],\n ) as OperationArguments;\n return this.#decodeRes(await super.sendOperationRequest(args, operationSpec));\n }\n\n #mapData(data: any, transform: {\n bigInt: (v: any) => any;\n number: (v: any) => any;\n }): unknown {\n if (Array.isArray(data)) return data.map((d) => this.#mapData(d, transform));\n if (data != null && typeof data === 'object') {\n return mapObject(data, ([key, value]) => {\n if (value == null) return [key, value];\n if (bigIntPropertyNames.some((k) => k === key)) return [key, transform.bigInt(value)];\n if (numberPropertyNames.some((k) => k === key)) return [key, transform.number(value)];\n return [key, this.#mapData(value, transform)];\n });\n }\n return data;\n }\n\n #encodeArg(data: any): any {\n return this.#mapData(data, {\n bigInt: (value) => {\n if (value instanceof BigNumber) return value.toFixed();\n return value.toString();\n },\n number: (value) => value.toString(),\n });\n }\n\n #decodeRes(data: any): any {\n return this.#mapData(data, {\n bigInt: (value) => BigInt(value),\n number: (value) => +value,\n });\n }\n}\n\ntype BigIntPropertyNames = typeof bigIntPropertyNames[number];\ntype NumberPropertyNames = typeof numberPropertyNames[number];\ntype PreserveOptional<NewType, OrigType> =\n OrigType extends undefined ? NewType | undefined : NewType;\nexport type TransformNodeType<Type> =\n Type extends (...args: infer Args) => infer Ret\n ? (...args: TransformNodeType<Args>) => TransformNodeType<Ret>\n : Type extends [infer Item, ...infer Rest]\n ? [TransformNodeType<Item>, ...TransformNodeType<Rest>]\n : Type extends Array<infer Item>\n ? Array<TransformNodeType<Item>>\n : Type extends Promise<infer T>\n ? Promise<TransformNodeType<T>>\n : Type extends { [P in any]: any }\n ? {\n [Property in keyof Type]:\n Property extends BigIntPropertyNames\n ? PreserveOptional<bigint, Type[Property]>\n : Property extends NumberPropertyNames\n ? PreserveOptional<number, Type[Property]>\n : Property extends 'txHash'\n ? PreserveOptional<Encoded.TxHash, Type[Property]>\n : Property extends 'bytecode'\n ? PreserveOptional<Encoded.ContractBytearray, Type[Property]>\n : TransformNodeType<Type[Property]>\n }\n : Type;\ntype NodeTransformedApi = new (...args: ConstructorParameters<typeof NodeApi>) => {\n [Name in keyof InstanceType<typeof NodeApi>]:\n Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest'\n ? NodeApi[Name] : TransformNodeType<NodeApi[Name]>\n};\n\ninterface NodeInfo {\n url: string;\n nodeNetworkId: string;\n version: string;\n consensusProtocolVersion: ConsensusProtocolVersion;\n}\n\nexport default class Node extends (NodeTransformed as unknown as NodeTransformedApi) {\n #networkIdPromise?: Promise<string | Error>;\n\n /**\n * @param url - Url for node API\n * @param options - Options\n * @param options.ignoreVersion - Don't check node version\n * @param options.retryCount - Amount of extra requests to do in case of failure\n * @param options.retryOverallDelay - Time in ms to wait between all retries\n */\n constructor(\n url: string,\n {\n ignoreVersion = false, retryCount = 3, retryOverallDelay = 800, ...options\n }: NodeOptionalParams & {\n ignoreVersion?: boolean;\n retryCount?: number;\n retryOverallDelay?: number;\n } = {},\n ) {\n // eslint-disable-next-line constructor-super\n super(url, {\n allowInsecureConnection: true,\n additionalPolicies: [\n genRequestQueuesPolicy(),\n genCombineGetRequestsPolicy(),\n genRetryOnFailurePolicy(retryCount, retryOverallDelay),\n genErrorFormatterPolicy((body: ErrorModel) => ` ${body.reason}`),\n ],\n ...options,\n });\n if (!ignoreVersion) {\n const statusPromise = this.getStatus();\n const versionPromise = statusPromise.then(({ nodeVersion }) => nodeVersion, (error) => error);\n this.#networkIdPromise = statusPromise.then(({ networkId }) => networkId, (error) => error);\n this.pipeline.addPolicy(\n genVersionCheckPolicy('node', '/v3/status', versionPromise, '6.2.0', '7.0.0'),\n );\n }\n this.intAsString = true;\n }\n\n async getNetworkId(): Promise<string> {\n this.#networkIdPromise ??= this.getStatus().then(({ networkId }) => networkId);\n const networkId = await this.#networkIdPromise;\n if (networkId instanceof Error) throw networkId;\n return networkId;\n }\n\n async getNodeInfo(): Promise<NodeInfo> {\n const {\n nodeVersion: version,\n networkId: nodeNetworkId,\n protocols,\n topBlockHeight,\n } = await this.getStatus();\n const consensusProtocolVersion = protocols\n .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)\n .reduce(\n (acc, p) => (p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc),\n { effectiveAtHeight: -1, version: 0 },\n )\n .version;\n return {\n url: this.$host,\n nodeNetworkId,\n version,\n consensusProtocolVersion,\n };\n }\n}\n"],"mappings":";;;;;;AAAA;AACA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAGnCC,sBAAsB,EAAEC,2BAA2B,EAAEC,uBAAuB,EAC5EC,qBAAqB,EAAEC,uBAAuB;AAAA,SAEvCC,IAAI,IAAIC,OAAO;AAAA,SACfC,SAAS;AAIlB,MAAMC,mBAAmB,GAAG,CAC1B,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAClE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,sBAAsB,EAC9E,sBAAsB,EAAE,UAAU,EAAE,SAAS,CACrC;AAEV,MAAMC,mBAAmB,GAAG,CAC1B,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EACpC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAC/D,KAAK,EA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"}
1
+ {"version":3,"file":"Node.mjs","names":["BigNumber","genRequestQueuesPolicy","genCombineGetRequestsPolicy","genErrorFormatterPolicy","genVersionCheckPolicy","genRetryOnFailurePolicy","Node","NodeApi","mapObject","bigIntPropertyNames","numberPropertyNames","_mapData","WeakSet","_encodeArg","_decodeRes","NodeTransformed","constructor","arguments","_classPrivateMethodInitSpec","sendOperationRequest","operationArguments","operationSpec","args","_ref","key","value","_classPrivateMethodGet","_encodeArg2","call","_decodeRes2","_mapData2","data","transform","Array","isArray","map","d","_ref6","some","k","bigInt","number","toFixed","toString","BigInt","_networkIdPromise","WeakMap","url","ignoreVersion","retryCount","retryOverallDelay","options","length","undefined","allowInsecureConnection","additionalPolicies","body","reason","_classPrivateFieldInitSpec","writable","statusPromise","getStatus","versionPromise","then","_ref2","nodeVersion","error","_classPrivateFieldSet","_ref3","networkId","pipeline","addPolicy","intAsString","getNetworkId","_classPrivateFieldGet2","_classPrivateFieldGet","_ref4","Error","getNodeInfo","version","nodeNetworkId","protocols","topBlockHeight","consensusProtocolVersion","filter","_ref5","effectiveAtHeight","reduce","acc","p","$host"],"sources":["../src/Node.ts"],"sourcesContent":["// eslint-disable-next-line max-classes-per-file\nimport BigNumber from 'bignumber.js';\nimport { OperationArguments, OperationSpec } from '@azure/core-client';\nimport {\n genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterPolicy,\n genVersionCheckPolicy, genRetryOnFailurePolicy,\n} from './utils/autorest';\nimport { Node as NodeApi, NodeOptionalParams, ErrorModel } from './apis/node';\nimport { mapObject } from './utils/other';\nimport { Encoded } from './utils/encoder';\nimport { ConsensusProtocolVersion } from './tx/builder/constants';\n\nconst bigIntPropertyNames = [\n 'balance', 'queryFee', 'fee', 'amount', 'nameFee', 'channelAmount',\n 'initiatorAmount', 'responderAmount', 'channelReserve', 'initiatorAmountFinal',\n 'responderAmountFinal', 'gasPrice', 'deposit',\n] as const;\n\nconst numberPropertyNames = [\n 'time', 'gas', 'gasUsed', 'nameSalt',\n 'nonce', 'nextNonce', 'height', 'blockHeight', 'topBlockHeight',\n 'ttl', 'nameTtl', 'clientTtl',\n 'inbound', 'outbound', 'peerCount', 'pendingTransactionsCount', 'effectiveAtHeight',\n 'version', 'solutions', 'round',\n] as const;\n\nclass NodeTransformed extends NodeApi {\n override async sendOperationRequest(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n ): Promise<any> {\n const args = mapObject(\n operationArguments,\n ([key, value]) => [key, this.#encodeArg(value)],\n ) as OperationArguments;\n return this.#decodeRes(await super.sendOperationRequest(args, operationSpec));\n }\n\n #mapData(data: any, transform: {\n bigInt: (v: any) => any;\n number: (v: any) => any;\n }): unknown {\n if (Array.isArray(data)) return data.map((d) => this.#mapData(d, transform));\n if (data != null && typeof data === 'object') {\n return mapObject(data, ([key, value]) => {\n if (value == null) return [key, value];\n if (bigIntPropertyNames.some((k) => k === key)) return [key, transform.bigInt(value)];\n if (numberPropertyNames.some((k) => k === key)) return [key, transform.number(value)];\n return [key, this.#mapData(value, transform)];\n });\n }\n return data;\n }\n\n #encodeArg(data: any): any {\n return this.#mapData(data, {\n bigInt: (value) => {\n if (value instanceof BigNumber) return value.toFixed();\n return value.toString();\n },\n number: (value) => value.toString(),\n });\n }\n\n #decodeRes(data: any): any {\n return this.#mapData(data, {\n bigInt: (value) => BigInt(value),\n number: (value) => +value,\n });\n }\n}\n\ntype BigIntPropertyNames = typeof bigIntPropertyNames[number];\ntype NumberPropertyNames = typeof numberPropertyNames[number];\ntype PreserveOptional<NewType, OrigType> =\n OrigType extends undefined ? NewType | undefined : NewType;\nexport type TransformNodeType<Type> =\n Type extends (...args: infer Args) => infer Ret\n ? (...args: TransformNodeType<Args>) => TransformNodeType<Ret>\n : Type extends [infer Item, ...infer Rest]\n ? [TransformNodeType<Item>, ...TransformNodeType<Rest>]\n : Type extends Array<infer Item>\n ? Array<TransformNodeType<Item>>\n : Type extends Promise<infer T>\n ? Promise<TransformNodeType<T>>\n : Type extends { [P in any]: any }\n ? {\n [Property in keyof Type]:\n Property extends BigIntPropertyNames\n ? PreserveOptional<bigint, Type[Property]>\n : Property extends NumberPropertyNames\n ? PreserveOptional<number, Type[Property]>\n : Property extends 'txHash'\n ? PreserveOptional<Encoded.TxHash, Type[Property]>\n : Property extends 'bytecode'\n ? PreserveOptional<Encoded.ContractBytearray, Type[Property]>\n : TransformNodeType<Type[Property]>\n }\n : Type;\ntype NodeTransformedApi = new (...args: ConstructorParameters<typeof NodeApi>) => {\n [Name in keyof InstanceType<typeof NodeApi>]:\n Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest'\n ? NodeApi[Name] : TransformNodeType<NodeApi[Name]>\n};\n\ninterface NodeInfo {\n url: string;\n nodeNetworkId: string;\n version: string;\n consensusProtocolVersion: ConsensusProtocolVersion;\n}\n\nexport default class Node extends (NodeTransformed as unknown as NodeTransformedApi) {\n #networkIdPromise?: Promise<string | Error>;\n\n /**\n * @param url - Url for node API\n * @param options - Options\n * @param options.ignoreVersion - Don't check node version\n * @param options.retryCount - Amount of extra requests to do in case of failure\n * @param options.retryOverallDelay - Time in ms to wait between all retries\n */\n constructor(\n url: string,\n {\n ignoreVersion = false, retryCount = 3, retryOverallDelay = 800, ...options\n }: NodeOptionalParams & {\n ignoreVersion?: boolean;\n retryCount?: number;\n retryOverallDelay?: number;\n } = {},\n ) {\n // eslint-disable-next-line constructor-super\n super(url, {\n allowInsecureConnection: true,\n additionalPolicies: [\n genRequestQueuesPolicy(),\n genCombineGetRequestsPolicy(),\n genRetryOnFailurePolicy(retryCount, retryOverallDelay),\n genErrorFormatterPolicy((body: ErrorModel) => ` ${body.reason}`),\n ],\n ...options,\n });\n if (!ignoreVersion) {\n const statusPromise = this.getStatus();\n const versionPromise = statusPromise.then(({ nodeVersion }) => nodeVersion, (error) => error);\n this.#networkIdPromise = statusPromise.then(({ networkId }) => networkId, (error) => error);\n this.pipeline.addPolicy(\n genVersionCheckPolicy('node', '/v3/status', versionPromise, '6.2.0', '7.0.0'),\n );\n }\n this.intAsString = true;\n }\n\n async getNetworkId(): Promise<string> {\n this.#networkIdPromise ??= this.getStatus().then(({ networkId }) => networkId);\n const networkId = await this.#networkIdPromise;\n if (networkId instanceof Error) throw networkId;\n return networkId;\n }\n\n async getNodeInfo(): Promise<NodeInfo> {\n const {\n nodeVersion: version,\n networkId: nodeNetworkId,\n protocols,\n topBlockHeight,\n } = await this.getStatus();\n const consensusProtocolVersion = protocols\n .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)\n .reduce(\n (acc, p) => (p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc),\n { effectiveAtHeight: -1, version: 0 },\n )\n .version;\n return {\n url: this.$host,\n nodeNetworkId,\n version,\n consensusProtocolVersion,\n };\n }\n}\n"],"mappings":";;;;;;AAAA;AACA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAGnCC,sBAAsB,EAAEC,2BAA2B,EAAEC,uBAAuB,EAC5EC,qBAAqB,EAAEC,uBAAuB;AAAA,SAEvCC,IAAI,IAAIC,OAAO;AAAA,SACfC,SAAS;AAIlB,MAAMC,mBAAmB,GAAG,CAC1B,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAClE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,sBAAsB,EAC9E,sBAAsB,EAAE,UAAU,EAAE,SAAS,CACrC;AAEV,MAAMC,mBAAmB,GAAG,CAC1B,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EACpC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAC/D,KAAK,EAAE,SAAS,EAAE,WAAW,EAC7B,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,0BAA0B,EAAE,mBAAmB,EACnF,SAAS,EAAE,WAAW,EAAE,OAAO,CACvB;AAAC,IAAAC,QAAA,oBAAAC,OAAA;AAAA,IAAAC,UAAA,oBAAAD,OAAA;AAAA,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AA,IAAAC,sBAAA;IACpC,CAAAA,sBAAA,GAAAC,qBAAA,KAAI,EAAA9B,iBAAA,eAAA6B,sBAAA,cAAAA,sBAAA,GAAAP,qBAAA,CAAJ,IAAI,EAAAtB,iBAAA,EAAuB,IAAI,CAACgB,SAAS,CAAC,CAAC,CAACE,IAAI,CAACa,KAAA;MAAA,IAAC;QAAEP;MAAU,CAAC,GAAAO,KAAA;MAAA,OAAKP,SAAS;IAAA,EAAC;IAC9E,MAAMA,SAAS,GAAG,MAAAM,qBAAA,CAAM,IAAI,EAAA9B,iBAAA,CAAkB;IAC9C,IAAIwB,SAAS,YAAYQ,KAAK,EAAE,MAAMR,SAAS;IAC/C,OAAOA,SAAS;EAClB;EAEA,MAAMS,WAAWA,CAAA,EAAsB;IACrC,MAAM;MACJb,WAAW,EAAEc,OAAO;MACpBV,SAAS,EAAEW,aAAa;MACxBC,SAAS;MACTC;IACF,CAAC,GAAG,MAAM,IAAI,CAACrB,SAAS,CAAC,CAAC;IAC1B,MAAMsB,wBAAwB,GAAGF,SAAS,CACvCG,MAAM,CAACC,KAAA;MAAA,IAAC;QAAEC;MAAkB,CAAC,GAAAD,KAAA;MAAA,OAAKH,cAAc,IAAII,iBAAiB;IAAA,EAAC,CACtEC,MAAM,CACL,CAACC,GAAG,EAAEC,CAAC,KAAMA,CAAC,CAACH,iBAAiB,GAAGE,GAAG,CAACF,iBAAiB,GAAGG,CAAC,GAAGD,GAAI,EACnE;MAAEF,iBAAiB,EAAE,CAAC,CAAC;MAAEP,OAAO,EAAE;IAAE,CACtC,CAAC,CACAA,OAAO;IACV,OAAO;MACLhC,GAAG,EAAE,IAAI,CAAC2C,KAAK;MACfV,aAAa;MACbD,OAAO;MACPI;IACF,CAAC;EACH;AACF"}
@@ -1,7 +1,7 @@
1
1
  import { Encoded } from '../utils/encoder';
2
2
  import Node from '../Node';
3
3
  import CompilerBase from '../contract/compiler/Base';
4
- import { Int } from '../tx/builder/constants';
4
+ import { AensName, Int } from '../tx/builder/constants';
5
5
  import { AciValue, Domain } from '../utils/typed-data';
6
6
  interface AuthData {
7
7
  fee?: Int;
@@ -50,7 +50,49 @@ export default abstract class AccountBase {
50
50
  * @param options - Options
51
51
  * @returns Signature
52
52
  */
53
- abstract signTypedData(data: Encoded.ContractBytearray, aci: AciValue, options?: Domain & {
53
+ signTypedData(data: Encoded.ContractBytearray, aci: AciValue, options?: Domain & {
54
+ aeppOrigin?: string;
55
+ aeppRpcClientId?: string;
56
+ }): Promise<Encoded.Signature>;
57
+ /**
58
+ * Sign delegation of AENS, oracle operations to a contract
59
+ * @param contractAddress - Address of a contract to delegate permissions to
60
+ * @param options - Options
61
+ * @returns Signature
62
+ */
63
+ signDelegationToContract(contractAddress: Encoded.ContractAddress, options?: {
64
+ networkId?: string;
65
+ aeppOrigin?: string;
66
+ aeppRpcClientId?: string;
67
+ }): Promise<Encoded.Signature>;
68
+ /**
69
+ * Sign delegation of an AENS name to a contract
70
+ * @param contractAddress - Address of a contract to delegate permissions to
71
+ * @param name - AENS name to manage by a contract
72
+ * @param options - Options
73
+ * @returns Signature
74
+ */
75
+ signNameDelegationToContract(contractAddress: Encoded.ContractAddress, name: AensName, options?: {
76
+ networkId?: string;
77
+ aeppOrigin?: string;
78
+ aeppRpcClientId?: string;
79
+ }): Promise<Encoded.Signature>;
80
+ /**
81
+ * Sign delegation of oracle query to a contract
82
+ *
83
+ * Warning! Implementations needs to ensure that decoded oracle query id is not equal to decoded
84
+ * current account address unless https://github.com/aeternity/aesophia/issues/475 is fixed.
85
+ *
86
+ * Warning! Implementations needs to ensure that oracle query and contract exists unless
87
+ * https://github.com/aeternity/aesophia/issues/474 is fixed.
88
+ *
89
+ * @param contractAddress - Address of a contract to delegate permissions to
90
+ * @param oracleQueryId - Oracle query ID to reply by a contract
91
+ * @param options - Options
92
+ * @returns Signature
93
+ */
94
+ signOracleQueryDelegationToContract(contractAddress: Encoded.ContractAddress, oracleQueryId: Encoded.OracleQueryId, options?: {
95
+ networkId?: string;
54
96
  aeppOrigin?: string;
55
97
  aeppRpcClientId?: string;
56
98
  }): Promise<Encoded.Signature>;
@@ -1,6 +1,100 @@
1
+ import { NotImplementedError } from "../utils/errors.mjs";
1
2
  /**
2
3
  * Account is one of the three basic building blocks of an
3
4
  * {@link AeSdk} and provides access to a signing key pair.
4
5
  */
5
- export default class AccountBase {}
6
+ export default class AccountBase {
7
+ /**
8
+ * Sign encoded transaction
9
+ * @param tx - Transaction to sign
10
+ * @param options - Options
11
+ * @param options.innerTx - Sign as inner transaction for PayingFor
12
+ * @param options.authData - Object with gaMeta params
13
+ * @returns Signed transaction
14
+ */
15
+
16
+ /**
17
+ * Sign message
18
+ * @param message - Message to sign
19
+ * @param options - Options
20
+ * @returns Signature
21
+ */
22
+
23
+ /**
24
+ * Sign typed data
25
+ * @param type - Type of data to sign
26
+ * @param data - Encoded data to sign
27
+ * @param options - Options
28
+ * @returns Signature
29
+ */
30
+ // TODO: make abstract in the next major release
31
+ // eslint-disable-next-line class-methods-use-this
32
+ async signTypedData( /* eslint-disable @typescript-eslint/no-unused-vars */
33
+ data, aci, options
34
+ /* eslint-enable @typescript-eslint/no-unused-vars */) {
35
+ throw new NotImplementedError('signTypedData method');
36
+ }
37
+
38
+ /**
39
+ * Sign delegation of AENS, oracle operations to a contract
40
+ * @param contractAddress - Address of a contract to delegate permissions to
41
+ * @param options - Options
42
+ * @returns Signature
43
+ */
44
+ // TODO: make abstract in the next major release
45
+ // eslint-disable-next-line class-methods-use-this
46
+ async signDelegationToContract( /* eslint-disable @typescript-eslint/no-unused-vars */
47
+ contractAddress, options
48
+ /* eslint-enable @typescript-eslint/no-unused-vars */) {
49
+ throw new NotImplementedError('signDelegationToContract method');
50
+ }
51
+
52
+ /**
53
+ * Sign delegation of an AENS name to a contract
54
+ * @param contractAddress - Address of a contract to delegate permissions to
55
+ * @param name - AENS name to manage by a contract
56
+ * @param options - Options
57
+ * @returns Signature
58
+ */
59
+ // TODO: make abstract in the next major release
60
+ // eslint-disable-next-line class-methods-use-this
61
+ async signNameDelegationToContract( /* eslint-disable @typescript-eslint/no-unused-vars */
62
+ contractAddress, name, options
63
+ /* eslint-enable @typescript-eslint/no-unused-vars */) {
64
+ throw new NotImplementedError('signNameDelegationToContract method');
65
+ }
66
+
67
+ /**
68
+ * Sign delegation of oracle query to a contract
69
+ *
70
+ * Warning! Implementations needs to ensure that decoded oracle query id is not equal to decoded
71
+ * current account address unless https://github.com/aeternity/aesophia/issues/475 is fixed.
72
+ *
73
+ * Warning! Implementations needs to ensure that oracle query and contract exists unless
74
+ * https://github.com/aeternity/aesophia/issues/474 is fixed.
75
+ *
76
+ * @param contractAddress - Address of a contract to delegate permissions to
77
+ * @param oracleQueryId - Oracle query ID to reply by a contract
78
+ * @param options - Options
79
+ * @returns Signature
80
+ */
81
+ // TODO: make abstract in the next major release
82
+ // eslint-disable-next-line class-methods-use-this
83
+ async signOracleQueryDelegationToContract( /* eslint-disable @typescript-eslint/no-unused-vars */
84
+ contractAddress, oracleQueryId, options
85
+ /* eslint-enable @typescript-eslint/no-unused-vars */) {
86
+ throw new NotImplementedError('signOracleQueryDelegationToContract method');
87
+ }
88
+
89
+ /**
90
+ * Sign data blob
91
+ * @param data - Data blob to sign
92
+ * @param options - Options
93
+ * @returns Signature
94
+ */
95
+
96
+ /**
97
+ * Account address
98
+ */
99
+ }
6
100
  //# sourceMappingURL=Base.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Base.mjs","names":["AccountBase"],"sources":["../../src/account/Base.ts"],"sourcesContent":["import { Encoded } from '../utils/encoder';\nimport Node from '../Node';\nimport CompilerBase from '../contract/compiler/Base';\nimport { Int } from '../tx/builder/constants';\nimport { AciValue, Domain } from '../utils/typed-data';\n\ninterface AuthData {\n fee?: Int;\n gasLimit?: number;\n gasPrice?: Int;\n callData?: Encoded.ContractBytearray;\n sourceCode?: string;\n args?: any[];\n}\n\n/**\n * Account is one of the three basic building blocks of an\n * {@link AeSdk} and provides access to a signing key pair.\n */\nexport default abstract class AccountBase {\n /**\n * Sign encoded transaction\n * @param tx - Transaction to sign\n * @param options - Options\n * @param options.innerTx - Sign as inner transaction for PayingFor\n * @param options.authData - Object with gaMeta params\n * @returns Signed transaction\n */\n abstract signTransaction(\n tx: Encoded.Transaction,\n options: {\n innerTx?: boolean;\n networkId?: string;\n authData?: AuthData | ((tx: Encoded.Transaction) => Promise<AuthData>);\n onNode?: Node;\n onCompiler?: CompilerBase;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Encoded.Transaction>;\n\n /**\n * Sign message\n * @param message - Message to sign\n * @param options - Options\n * @returns Signature\n */\n abstract signMessage(\n message: string,\n options?: {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Uint8Array>;\n\n /**\n * Sign typed data\n * @param type - Type of data to sign\n * @param data - Encoded data to sign\n * @param options - Options\n * @returns Signature\n */\n abstract signTypedData(\n data: Encoded.ContractBytearray,\n aci: AciValue,\n options?: Domain & {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Encoded.Signature>;\n\n /**\n * Sign data blob\n * @param data - Data blob to sign\n * @param options - Options\n * @returns Signature\n */\n abstract sign(data: string | Uint8Array, options?: any): Promise<Uint8Array>;\n\n /**\n * Account address\n */\n readonly address!: Encoded.AccountAddress;\n}\n"],"mappings":"AAeA;AACA;AACA;AACA;AACA,eAAe,MAAeA,WAAW,CAAC"}
1
+ {"version":3,"file":"Base.mjs","names":["NotImplementedError","AccountBase","signTypedData","data","aci","options","signDelegationToContract","contractAddress","signNameDelegationToContract","name","signOracleQueryDelegationToContract","oracleQueryId"],"sources":["../../src/account/Base.ts"],"sourcesContent":["import { Encoded } from '../utils/encoder';\nimport Node from '../Node';\nimport CompilerBase from '../contract/compiler/Base';\nimport { AensName, Int } from '../tx/builder/constants';\nimport { AciValue, Domain } from '../utils/typed-data';\nimport { NotImplementedError } from '../utils/errors';\n\ninterface AuthData {\n fee?: Int;\n gasLimit?: number;\n gasPrice?: Int;\n callData?: Encoded.ContractBytearray;\n sourceCode?: string;\n args?: any[];\n}\n\n/**\n * Account is one of the three basic building blocks of an\n * {@link AeSdk} and provides access to a signing key pair.\n */\nexport default abstract class AccountBase {\n /**\n * Sign encoded transaction\n * @param tx - Transaction to sign\n * @param options - Options\n * @param options.innerTx - Sign as inner transaction for PayingFor\n * @param options.authData - Object with gaMeta params\n * @returns Signed transaction\n */\n abstract signTransaction(\n tx: Encoded.Transaction,\n options: {\n innerTx?: boolean;\n networkId?: string;\n authData?: AuthData | ((tx: Encoded.Transaction) => Promise<AuthData>);\n onNode?: Node;\n onCompiler?: CompilerBase;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Encoded.Transaction>;\n\n /**\n * Sign message\n * @param message - Message to sign\n * @param options - Options\n * @returns Signature\n */\n abstract signMessage(\n message: string,\n options?: {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Uint8Array>;\n\n /**\n * Sign typed data\n * @param type - Type of data to sign\n * @param data - Encoded data to sign\n * @param options - Options\n * @returns Signature\n */\n // TODO: make abstract in the next major release\n // eslint-disable-next-line class-methods-use-this\n async signTypedData(\n /* eslint-disable @typescript-eslint/no-unused-vars */\n data: Encoded.ContractBytearray,\n aci: AciValue,\n options?: Domain & {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n /* eslint-enable @typescript-eslint/no-unused-vars */\n ): Promise<Encoded.Signature> {\n throw new NotImplementedError('signTypedData method');\n }\n\n /**\n * Sign delegation of AENS, oracle operations to a contract\n * @param contractAddress - Address of a contract to delegate permissions to\n * @param options - Options\n * @returns Signature\n */\n // TODO: make abstract in the next major release\n // eslint-disable-next-line class-methods-use-this\n async signDelegationToContract(\n /* eslint-disable @typescript-eslint/no-unused-vars */\n contractAddress: Encoded.ContractAddress,\n options?: {\n networkId?: string;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n /* eslint-enable @typescript-eslint/no-unused-vars */\n ): Promise<Encoded.Signature> {\n throw new NotImplementedError('signDelegationToContract method');\n }\n\n /**\n * Sign delegation of an AENS name to a contract\n * @param contractAddress - Address of a contract to delegate permissions to\n * @param name - AENS name to manage by a contract\n * @param options - Options\n * @returns Signature\n */\n // TODO: make abstract in the next major release\n // eslint-disable-next-line class-methods-use-this\n async signNameDelegationToContract(\n /* eslint-disable @typescript-eslint/no-unused-vars */\n contractAddress: Encoded.ContractAddress,\n name: AensName,\n options?: {\n networkId?: string;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n /* eslint-enable @typescript-eslint/no-unused-vars */\n ): Promise<Encoded.Signature> {\n throw new NotImplementedError('signNameDelegationToContract method');\n }\n\n /**\n * Sign delegation of oracle query to a contract\n *\n * Warning! Implementations needs to ensure that decoded oracle query id is not equal to decoded\n * current account address unless https://github.com/aeternity/aesophia/issues/475 is fixed.\n *\n * Warning! Implementations needs to ensure that oracle query and contract exists unless\n * https://github.com/aeternity/aesophia/issues/474 is fixed.\n *\n * @param contractAddress - Address of a contract to delegate permissions to\n * @param oracleQueryId - Oracle query ID to reply by a contract\n * @param options - Options\n * @returns Signature\n */\n // TODO: make abstract in the next major release\n // eslint-disable-next-line class-methods-use-this\n async signOracleQueryDelegationToContract(\n /* eslint-disable @typescript-eslint/no-unused-vars */\n contractAddress: Encoded.ContractAddress,\n oracleQueryId: Encoded.OracleQueryId,\n options?: {\n networkId?: string;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n /* eslint-enable @typescript-eslint/no-unused-vars */\n ): Promise<Encoded.Signature> {\n throw new NotImplementedError('signOracleQueryDelegationToContract method');\n }\n\n /**\n * Sign data blob\n * @param data - Data blob to sign\n * @param options - Options\n * @returns Signature\n */\n abstract sign(data: string | Uint8Array, options?: any): Promise<Uint8Array>;\n\n /**\n * Account address\n */\n readonly address!: Encoded.AccountAddress;\n}\n"],"mappings":"SAKSA,mBAAmB;AAW5B;AACA;AACA;AACA;AACA,eAAe,MAAeC,WAAW,CAAC;EACxC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;;EAcE;AACF;AACA;AACA;AACA;AACA;;EASE;AACF;AACA;AACA;AACA;AACA;AACA;EACE;EACA;EACA,MAAMC,aAAaA,CAAA,CACjB;EACAC,IAA+B,EAC/BC,GAAa,EACbC;EAIA,uDAC4B;IAC5B,MAAM,IAAIL,mBAAmB,CAAC,sBAAsB,CAAC;EACvD;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE;EACA;EACA,MAAMM,wBAAwBA,CAAA,CAC5B;EACAC,eAAwC,EACxCF;EAKA,uDAC4B;IAC5B,MAAM,IAAIL,mBAAmB,CAAC,iCAAiC,CAAC;EAClE;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACE;EACA;EACA,MAAMQ,4BAA4BA,CAAA,CAChC;EACAD,eAAwC,EACxCE,IAAc,EACdJ;EAKA,uDAC4B;IAC5B,MAAM,IAAIL,mBAAmB,CAAC,qCAAqC,CAAC;EACtE;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE;EACA;EACA,MAAMU,mCAAmCA,CAAA,CACvC;EACAH,eAAwC,EACxCI,aAAoC,EACpCN;EAKA,uDAC4B;IAC5B,MAAM,IAAIL,mBAAmB,CAAC,4CAA4C,CAAC;EAC7E;;EAEA;AACF;AACA;AACA;AACA;AACA;;EAGE;AACF;AACA;AAEA"}
@@ -13,5 +13,8 @@ export default class AccountGeneralized extends AccountBase {
13
13
  sign(): Promise<Uint8Array>;
14
14
  signMessage(): Promise<Uint8Array>;
15
15
  signTypedData(): Promise<Encoded.Signature>;
16
+ signDelegationToContract(): Promise<Encoded.Signature>;
17
+ signNameDelegationToContract(): Promise<Encoded.Signature>;
18
+ signOracleQueryDelegationToContract(): Promise<Encoded.Signature>;
16
19
  signTransaction(tx: Encoded.Transaction, { authData, onCompiler, onNode }: Parameters<AccountBase['signTransaction']>[1]): Promise<Encoded.Transaction>;
17
20
  }
@@ -41,6 +41,21 @@ export default class AccountGeneralized extends AccountBase {
41
41
  async signTypedData() {
42
42
  throw new NotImplementedError('Can\'t sign using generalized account');
43
43
  }
44
+
45
+ // eslint-disable-next-line class-methods-use-this
46
+ async signDelegationToContract() {
47
+ throw new NotImplementedError('signing delegation to contract using generalized account');
48
+ }
49
+
50
+ // eslint-disable-next-line class-methods-use-this
51
+ async signNameDelegationToContract() {
52
+ throw new NotImplementedError('signing delegation to contract using generalized account');
53
+ }
54
+
55
+ // eslint-disable-next-line class-methods-use-this
56
+ async signOracleQueryDelegationToContract() {
57
+ throw new NotImplementedError('signing delegation to contract using generalized account');
58
+ }
44
59
  async signTransaction(tx, _ref) {
45
60
  let {
46
61
  authData,
@@ -1 +1 @@
1
- {"version":3,"file":"Generalized.mjs","names":["AccountBase","ArgumentError","InternalError","InvalidAuthDataError","NotImplementedError","decode","getAccount","Contract","buildTxAsync","buildTx","Tag","_authFun","WeakMap","AccountGeneralized","constructor","address","_classPrivateFieldInitSpec","writable","value","sign","signMessage","signTypedData","signTransaction","tx","_ref","authData","onCompiler","onNode","callData","sourceCode","args","fee","gasLimit","gasPrice","authCallData","_classPrivateFieldGet","account","kind","_classPrivateFieldSet","authFun","contract","initialize","_calldata","encode","_name","gaMetaTx","tag","GaMetaTx","SignedTx","encodedTx","signatures","gaId"],"sources":["../../src/account/Generalized.ts"],"sourcesContent":["import AccountBase from './Base';\nimport {\n ArgumentError,\n InternalError,\n InvalidAuthDataError,\n NotImplementedError,\n} from '../utils/errors';\nimport { decode, Encoded } from '../utils/encoder';\nimport { getAccount } from '../chain';\nimport Contract from '../contract/Contract';\nimport { buildTxAsync, buildTx } from '../tx/builder';\nimport { Tag } from '../tx/builder/constants';\n\n/**\n * Generalized account class\n */\nexport default class AccountGeneralized extends AccountBase {\n override readonly address: Encoded.AccountAddress;\n\n #authFun?: string;\n\n /**\n * @param address - Address of generalized account\n */\n constructor(address: Encoded.AccountAddress) {\n super();\n decode(address);\n this.address = address;\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('Can\\'t sign using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signMessage(): Promise<Uint8Array> {\n throw new NotImplementedError('Can\\'t sign using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signTypedData(): Promise<Encoded.Signature> {\n throw new NotImplementedError('Can\\'t sign using generalized account');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { authData, onCompiler, onNode }: Parameters<AccountBase['signTransaction']>[1],\n ): Promise<Encoded.Transaction> {\n if (authData == null || onCompiler == null || onNode == null) {\n throw new ArgumentError('authData, onCompiler, onNode', 'provided', null);\n }\n const {\n callData, sourceCode, args, fee, gasLimit, gasPrice,\n } = typeof authData === 'function' ? await authData(tx) : authData;\n\n const authCallData = callData ?? await (async () => {\n if (this.#authFun == null) {\n const account = await getAccount(this.address, { onNode });\n if (account.kind !== 'generalized') {\n throw new ArgumentError('account kind', 'generalized', account.kind);\n }\n this.#authFun = account.authFun;\n }\n if (this.#authFun == null) {\n throw new InternalError('Account in generalised, but authFun not provided');\n }\n\n if (sourceCode == null || args == null) {\n throw new InvalidAuthDataError('Auth data must contain sourceCode and args or callData.');\n }\n const contract = await Contract.initialize({ onCompiler, onNode, sourceCode });\n return contract._calldata.encode(contract._name, this.#authFun, args);\n })();\n\n const gaMetaTx = await buildTxAsync({\n tag: Tag.GaMetaTx,\n tx: { tag: Tag.SignedTx, encodedTx: decode(tx), signatures: [] },\n gaId: this.address,\n authData: authCallData,\n fee,\n gasLimit,\n gasPrice,\n onNode,\n });\n return buildTx({ tag: Tag.SignedTx, encodedTx: decode(gaMetaTx), signatures: [] });\n }\n}\n"],"mappings":";;;;OAAOA,WAAW;AAAA,SAEhBC,aAAa,EACbC,aAAa,EACbC,oBAAoB,EACpBC,mBAAmB;AAAA,SAEZC,MAAM;AAAA,SACNC,UAAU;AAAA,OACZC,QAAQ;AAAA,SACNC,YAAY,EAAEC,OAAO;AAAA,SACrB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E5C,MAAM,CAACwC,QAAQ,CAAC;MAAEK,UAAU,EAAE;IAAG,CAAC,CAAC;EACpF;AACF"}
1
+ {"version":3,"file":"Generalized.mjs","names":["AccountBase","ArgumentError","InternalError","InvalidAuthDataError","NotImplementedError","decode","getAccount","Contract","buildTxAsync","buildTx","Tag","_authFun","WeakMap","AccountGeneralized","constructor","address","_classPrivateFieldInitSpec","writable","value","sign","signMessage","signTypedData","signDelegationToContract","signNameDelegationToContract","signOracleQueryDelegationToContract","signTransaction","tx","_ref","authData","onCompiler","onNode","callData","sourceCode","args","fee","gasLimit","gasPrice","authCallData","_classPrivateFieldGet","account","kind","_classPrivateFieldSet","authFun","contract","initialize","_calldata","encode","_name","gaMetaTx","tag","GaMetaTx","SignedTx","encodedTx","signatures","gaId"],"sources":["../../src/account/Generalized.ts"],"sourcesContent":["import AccountBase from './Base';\nimport {\n ArgumentError,\n InternalError,\n InvalidAuthDataError,\n NotImplementedError,\n} from '../utils/errors';\nimport { decode, Encoded } from '../utils/encoder';\nimport { getAccount } from '../chain';\nimport Contract from '../contract/Contract';\nimport { buildTxAsync, buildTx } from '../tx/builder';\nimport { Tag } from '../tx/builder/constants';\n\n/**\n * Generalized account class\n */\nexport default class AccountGeneralized extends AccountBase {\n override readonly address: Encoded.AccountAddress;\n\n #authFun?: string;\n\n /**\n * @param address - Address of generalized account\n */\n constructor(address: Encoded.AccountAddress) {\n super();\n decode(address);\n this.address = address;\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('Can\\'t sign using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signMessage(): Promise<Uint8Array> {\n throw new NotImplementedError('Can\\'t sign using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signTypedData(): Promise<Encoded.Signature> {\n throw new NotImplementedError('Can\\'t sign using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signDelegationToContract(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation to contract using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signNameDelegationToContract(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation to contract using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signOracleQueryDelegationToContract(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation to contract using generalized account');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { authData, onCompiler, onNode }: Parameters<AccountBase['signTransaction']>[1],\n ): Promise<Encoded.Transaction> {\n if (authData == null || onCompiler == null || onNode == null) {\n throw new ArgumentError('authData, onCompiler, onNode', 'provided', null);\n }\n const {\n callData, sourceCode, args, fee, gasLimit, gasPrice,\n } = typeof authData === 'function' ? await authData(tx) : authData;\n\n const authCallData = callData ?? await (async () => {\n if (this.#authFun == null) {\n const account = await getAccount(this.address, { onNode });\n if (account.kind !== 'generalized') {\n throw new ArgumentError('account kind', 'generalized', account.kind);\n }\n this.#authFun = account.authFun;\n }\n if (this.#authFun == null) {\n throw new InternalError('Account in generalised, but authFun not provided');\n }\n\n if (sourceCode == null || args == null) {\n throw new InvalidAuthDataError('Auth data must contain sourceCode and args or callData.');\n }\n const contract = await Contract.initialize({ onCompiler, onNode, sourceCode });\n return contract._calldata.encode(contract._name, this.#authFun, args);\n })();\n\n const gaMetaTx = await buildTxAsync({\n tag: Tag.GaMetaTx,\n tx: { tag: Tag.SignedTx, encodedTx: decode(tx), signatures: [] },\n gaId: this.address,\n authData: authCallData,\n fee,\n gasLimit,\n gasPrice,\n onNode,\n });\n return buildTx({ tag: Tag.SignedTx, encodedTx: decode(gaMetaTx), signatures: [] });\n }\n}\n"],"mappings":";;;;OAAOA,WAAW;AAAA,SAEhBC,aAAa,EACbC,aAAa,EACbC,oBAAoB,EACpBC,mBAAmB;AAAA,SAEZC,MAAM;AAAA,SACNC,UAAU;AAAA,OACZC,QAAQ;AAAA,SACNC,YAAY,EAAEC,OAAO;AAAA,SACrBC,GAAG;AA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QAAQ;QAAEC,SAAS,EAAE/C,MAAM,CAACqB,EAAE,CAAC;QAAE2B,UAAU,EAAE;MAAG,CAAC;MAChEC,IAAI,EAAE,IAAI,CAACvC,OAAO;MAClBa,QAAQ,EAAES,YAAY;MACtBH,GAAG;MACHC,QAAQ;MACRC,QAAQ;MACRN;IACF,CAAC,CAAC;IACF,OAAOrB,OAAO,CAAC;MAAEwC,GAAG,EAAEvC,GAAG,CAACyC,QAAQ;MAAEC,SAAS,EAAE/C,MAAM,CAAC2C,QAAQ,CAAC;MAAEK,UAAU,EAAE;IAAG,CAAC,CAAC;EACpF;AACF"}
@@ -21,6 +21,9 @@ export default class AccountLedger extends AccountBase {
21
21
  constructor(transport: Transport, index: number, address: Encoded.AccountAddress);
22
22
  sign(): Promise<Uint8Array>;
23
23
  signTypedData(): Promise<Encoded.Signature>;
24
+ signDelegationToContract(): Promise<Encoded.Signature>;
25
+ signNameDelegationToContract(): Promise<Encoded.Signature>;
26
+ signOracleQueryDelegationToContract(): Promise<Encoded.Signature>;
24
27
  signTransaction(tx: Encoded.Transaction, { innerTx, networkId }?: {
25
28
  innerTx?: boolean;
26
29
  networkId?: string;
@@ -40,6 +40,21 @@ export default class AccountLedger extends AccountBase {
40
40
  async signTypedData() {
41
41
  throw new NotImplementedError('Typed data signing using Ledger HW');
42
42
  }
43
+
44
+ // eslint-disable-next-line class-methods-use-this
45
+ async signDelegationToContract() {
46
+ throw new NotImplementedError('signing delegation to contract using Ledger HW');
47
+ }
48
+
49
+ // eslint-disable-next-line class-methods-use-this
50
+ async signNameDelegationToContract() {
51
+ throw new NotImplementedError('signing delegation to contract using Ledger HW');
52
+ }
53
+
54
+ // eslint-disable-next-line class-methods-use-this
55
+ async signOracleQueryDelegationToContract() {
56
+ throw new NotImplementedError('signing delegation to contract using Ledger HW');
57
+ }
43
58
  async signTransaction(tx) {
44
59
  let {
45
60
  innerTx,
@@ -1 +1 @@
1
- {"version":3,"file":"Ledger.mjs","names":["AccountBase","ArgumentError","NotImplementedError","decode","buildTx","Tag","CLA","GET_ADDRESS","SIGN_TRANSACTION","GET_APP_CONFIGURATION","SIGN_PERSONAL_MESSAGE","AccountLedger","constructor","transport","index","address","scrambleKey","decorateAppAPIMethods","sign","signTypedData","signTransaction","tx","innerTx","networkId","arguments","length","undefined","rawTx","offset","headerLength","networkIdBuffer","_Buffer","from","toSend","maxChunkSize","chunkSize","buffer","alloc","bufferOffset","writeUInt32BE","writeUInt8","copy","push","response","reduce","previous","data","i","send","Promise","resolve","signatures","subarray","tag","SignedTx","encodedTx","signMessage","messageStr","message"],"sources":["../../src/account/Ledger.ts"],"sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\nimport AccountBase from './Base';\nimport { ArgumentError, NotImplementedError } from '../utils/errors';\nimport { decode, Encoded } from '../utils/encoder';\nimport { buildTx } from '../tx/builder';\nimport { Tag } from '../tx/builder/constants';\n\nexport const CLA = 0xe0;\nexport const GET_ADDRESS = 0x02;\nexport const SIGN_TRANSACTION = 0x04;\nexport const GET_APP_CONFIGURATION = 0x06;\nexport const SIGN_PERSONAL_MESSAGE = 0x08;\n\n/**\n * Ledger wallet account class\n */\nexport default class AccountLedger extends AccountBase {\n readonly transport: Transport;\n\n override readonly address: Encoded.AccountAddress;\n\n readonly index: number;\n\n /**\n * @param transport - Connection to Ledger to use\n * @param index - Index of account\n * @param address - Address of account\n */\n constructor(transport: Transport, index: number, address: Encoded.AccountAddress) {\n super();\n this.transport = transport;\n this.index = index;\n this.address = address;\n const scrambleKey = 'w0w';\n transport.decorateAppAPIMethods(this, ['signTransaction', 'signMessage'], scrambleKey);\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('RAW signing using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signTypedData(): Promise<Encoded.Signature> {\n throw new NotImplementedError('Typed data signing using Ledger HW');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { innerTx, networkId }: { innerTx?: boolean; networkId?: string } = {},\n ): Promise<Encoded.Transaction> {\n if (innerTx != null) throw new NotImplementedError('innerTx option in AccountLedger');\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n\n const rawTx = decode(tx);\n let offset = 0;\n const headerLength = 4 + 1 + 4;\n const networkIdBuffer = Buffer.from(networkId);\n const toSend = [];\n while (offset !== rawTx.length) {\n const maxChunkSize = offset === 0 ? 150 - headerLength - networkIdBuffer.length : 150;\n const chunkSize = offset + maxChunkSize > rawTx.length\n ? rawTx.length - offset : maxChunkSize;\n const buffer = Buffer.alloc(\n offset === 0 ? headerLength + networkIdBuffer.length + chunkSize : chunkSize,\n );\n if (offset === 0) {\n let bufferOffset = buffer.writeUInt32BE(this.index, 0);\n bufferOffset = buffer.writeUInt32BE(rawTx.length, bufferOffset);\n bufferOffset = buffer.writeUInt8(networkIdBuffer.length, bufferOffset);\n bufferOffset += networkIdBuffer.copy(\n buffer,\n bufferOffset,\n 0,\n networkIdBuffer.length,\n );\n rawTx.copy(buffer, bufferOffset, 0, 150 - bufferOffset);\n } else {\n rawTx.copy(buffer, 0, offset, offset + chunkSize);\n }\n toSend.push(buffer);\n offset += chunkSize;\n }\n const response = await toSend.reduce(\n async (previous, data, i) => {\n await previous;\n return this.transport.send(\n CLA,\n SIGN_TRANSACTION,\n i === 0 ? 0x00 : 0x80,\n 0x00,\n data,\n );\n },\n Promise.resolve(Buffer.alloc(0)),\n );\n const signatures = [response.subarray(0, 64)];\n\n return buildTx({ tag: Tag.SignedTx, encodedTx: rawTx, signatures });\n }\n\n override async signMessage(messageStr: string): Promise<Uint8Array> {\n let offset = 0;\n const message = Buffer.from(messageStr);\n const toSend = [];\n while (offset !== message.length) {\n const maxChunkSize = offset === 0 ? 150 - 4 - 4 : 150;\n const chunkSize = offset + maxChunkSize > message.length\n ? message.length - offset : maxChunkSize;\n const buffer = Buffer.alloc(offset === 0 ? 4 + 4 + chunkSize : chunkSize);\n if (offset === 0) {\n buffer.writeUInt32BE(this.index, 0);\n buffer.writeUInt32BE(message.length, 4);\n message.copy(buffer, 4 + 4, offset, offset + chunkSize);\n } else {\n message.copy(buffer, 0, offset, offset + chunkSize);\n }\n toSend.push(buffer);\n offset += chunkSize;\n }\n const response = await toSend.reduce(\n async (previous, data, i) => {\n await previous;\n return this.transport.send(\n CLA,\n SIGN_PERSONAL_MESSAGE,\n i === 0 ? 0x00 : 0x80,\n 0x00,\n data,\n );\n },\n Promise.resolve(Buffer.alloc(0)),\n );\n return response.subarray(0, 64);\n }\n}\n"],"mappings":";;;;OACOA,WAAW;AAAA,SACTC,aAAa,EAAEC,mBAAmB;AAAA,SAClCC,MAAM;AAAA,SACNC,OAAO;AAAA,SACPC,GAAG;AAEZ,OAAO,MAAMC,GAAG,GAAG,IAAI;AACvB,OAAO,MAAMC,WAAW,GAAG,IAAI;AAC/B,OAAO,MAAMC,gBAAgB,GAAG,IAAI;AACpC,OAAO,MAAMC,qBAAqB,GAAG,IAAI;AACzC,OAAO,MAAMC,qBAAqB,GAAG,IAAI;;AAEzC;AACA;AACA;AACA,eAAe,MAAMC,aAAa,SAASX,WAAW,CAAC;EAOrD;AACF;AACA;AACA;AACA;EACEY,WAAWA,CAACC,SAAoB,EAAEC,KAAa,EAAEC,OAA+B,EAAE;IAChF,KAAK,EAAE;IACP,IAAI,CAACF,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,OAAO,GAAGA,OAAO;IACtB,MAAMC,WAAW,GAAG,KAAK;IACzBH,SAAS,CAACI,qBAAqB,CAAC,IAAI,EAAE,CAAC,iBAAiB,EAAE,aAAa,CAAC,EAAED,WAAW,CAAC;EACxF;;EAEA;EACA,MAAeE,IAAIA,CAAA,EAAwB;IACzC,MAAM,IAAIhB,mBAAmB,CAAC,6BAA6B,CAAC;EAC9D;;EAEA;EACA,MAAeiB,aAAaA,CAAA,EAA+B;IACzD,MAAM,IAAIjB,mBAAmB,CAAC,oCAAoC,CAAC;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AC,CAAC,CACjC;IACD,OAAOM,QAAQ,CAACS,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC;EACjC;AACF"}
1
+ {"version":3,"file":"Ledger.mjs","names":["AccountBase","ArgumentError","NotImplementedError","decode","buildTx","Tag","CLA","GET_ADDRESS","SIGN_TRANSACTION","GET_APP_CONFIGURATION","SIGN_PERSONAL_MESSAGE","AccountLedger","constructor","transport","index","address","scrambleKey","decorateAppAPIMethods","sign","signTypedData","signDelegationToContract","signNameDelegationToContract","signOracleQueryDelegationToContract","signTransaction","tx","innerTx","networkId","arguments","length","undefined","rawTx","offset","headerLength","networkIdBuffer","_Buffer","from","toSend","maxChunkSize","chunkSize","buffer","alloc","bufferOffset","writeUInt32BE","writeUInt8","copy","push","response","reduce","previous","data","i","send","Promise","resolve","signatures","subarray","tag","SignedTx","encodedTx","signMessage","messageStr","message"],"sources":["../../src/account/Ledger.ts"],"sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\nimport AccountBase from './Base';\nimport { ArgumentError, NotImplementedError } from '../utils/errors';\nimport { decode, Encoded } from '../utils/encoder';\nimport { buildTx } from '../tx/builder';\nimport { Tag } from '../tx/builder/constants';\n\nexport const CLA = 0xe0;\nexport const GET_ADDRESS = 0x02;\nexport const SIGN_TRANSACTION = 0x04;\nexport const GET_APP_CONFIGURATION = 0x06;\nexport const SIGN_PERSONAL_MESSAGE = 0x08;\n\n/**\n * Ledger wallet account class\n */\nexport default class AccountLedger extends AccountBase {\n readonly transport: Transport;\n\n override readonly address: Encoded.AccountAddress;\n\n readonly index: number;\n\n /**\n * @param transport - Connection to Ledger to use\n * @param index - Index of account\n * @param address - Address of account\n */\n constructor(transport: Transport, index: number, address: Encoded.AccountAddress) {\n super();\n this.transport = transport;\n this.index = index;\n this.address = address;\n const scrambleKey = 'w0w';\n transport.decorateAppAPIMethods(this, ['signTransaction', 'signMessage'], scrambleKey);\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('RAW signing using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signTypedData(): Promise<Encoded.Signature> {\n throw new NotImplementedError('Typed data signing using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signDelegationToContract(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation to contract using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signNameDelegationToContract(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation to contract using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signOracleQueryDelegationToContract(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation to contract using Ledger HW');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { innerTx, networkId }: { innerTx?: boolean; networkId?: string } = {},\n ): Promise<Encoded.Transaction> {\n if (innerTx != null) throw new NotImplementedError('innerTx option in AccountLedger');\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n\n const rawTx = decode(tx);\n let offset = 0;\n const headerLength = 4 + 1 + 4;\n const networkIdBuffer = Buffer.from(networkId);\n const toSend = [];\n while (offset !== rawTx.length) {\n const maxChunkSize = offset === 0 ? 150 - headerLength - networkIdBuffer.length : 150;\n const chunkSize = offset + maxChunkSize > rawTx.length\n ? rawTx.length - offset : maxChunkSize;\n const buffer = Buffer.alloc(\n offset === 0 ? headerLength + networkIdBuffer.length + chunkSize : chunkSize,\n );\n if (offset === 0) {\n let bufferOffset = buffer.writeUInt32BE(this.index, 0);\n bufferOffset = buffer.writeUInt32BE(rawTx.length, bufferOffset);\n bufferOffset = buffer.writeUInt8(networkIdBuffer.length, bufferOffset);\n bufferOffset += networkIdBuffer.copy(\n buffer,\n bufferOffset,\n 0,\n networkIdBuffer.length,\n );\n rawTx.copy(buffer, bufferOffset, 0, 150 - bufferOffset);\n } else {\n rawTx.copy(buffer, 0, offset, offset + chunkSize);\n }\n toSend.push(buffer);\n offset += chunkSize;\n }\n const response = await toSend.reduce(\n async (previous, data, i) => {\n await previous;\n return this.transport.send(\n CLA,\n SIGN_TRANSACTION,\n i === 0 ? 0x00 : 0x80,\n 0x00,\n data,\n );\n },\n Promise.resolve(Buffer.alloc(0)),\n );\n const signatures = [response.subarray(0, 64)];\n\n return buildTx({ tag: Tag.SignedTx, encodedTx: rawTx, signatures });\n }\n\n override async signMessage(messageStr: string): Promise<Uint8Array> {\n let offset = 0;\n const message = Buffer.from(messageStr);\n const toSend = [];\n while (offset !== message.length) {\n const maxChunkSize = offset === 0 ? 150 - 4 - 4 : 150;\n const chunkSize = offset + maxChunkSize > message.length\n ? message.length - offset : maxChunkSize;\n const buffer = Buffer.alloc(offset === 0 ? 4 + 4 + chunkSize : chunkSize);\n if (offset === 0) {\n buffer.writeUInt32BE(this.index, 0);\n buffer.writeUInt32BE(message.length, 4);\n message.copy(buffer, 4 + 4, offset, offset + chunkSize);\n } else {\n message.copy(buffer, 0, offset, offset + chunkSize);\n }\n toSend.push(buffer);\n offset += chunkSize;\n }\n const response = await toSend.reduce(\n async (previous, data, i) => {\n await previous;\n return this.transport.send(\n CLA,\n SIGN_PERSONAL_MESSAGE,\n i === 0 ? 0x00 : 0x80,\n 0x00,\n data,\n );\n },\n Promise.resolve(Buffer.alloc(0)),\n );\n return response.subarray(0, 64);\n }\n}\n"],"mappings":";;;;OACOA,WAAW;AAAA,SACTC,aAAa,EAAEC,mBAAmB;AAAA,SAClCC,MAAM;AAAA,SACNC,OAAO;AAAA,SACPC,GAAG;AAEZ,OAAO,MAAMC,GAAG,GAAG,IAAI;AACvB,OAAO,MAAMC,WAAW,GAAG,IAAI;AAC/B,OAAO,MAAMC,gBAAgB,GAAG,IAAI;AACpC,OAAO,MAAMC,qBAAqB,GAAG,IAAI;AACzC,OAAO,MAAMC,qBAAqB,GAAG,IAAI;;AAEzC;AACA;AACA;AACA,eAAe,MAAMC,aAAa,SAASX,WAAW,CAAC;EAOrD;AACF;AACA;AACA;AACA;EACEY,WAAWA,CAACC,S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Q,MAAM,CAACG,aAAa,CAAC,IAAI,CAAC5B,KAAK,EAAE,CAAC,CAAC;QACnCyB,MAAM,CAACG,aAAa,CAACmB,OAAO,CAACjC,MAAM,EAAE,CAAC,CAAC;QACvCiC,OAAO,CAACjB,IAAI,CAACL,MAAM,EAAE,CAAC,GAAG,CAAC,EAAER,MAAM,EAAEA,MAAM,GAAGO,SAAS,CAAC;MACzD,CAAC,MAAM;QACLuB,OAAO,CAACjB,IAAI,CAACL,MAAM,EAAE,CAAC,EAAER,MAAM,EAAEA,MAAM,GAAGO,SAAS,CAAC;MACrD;MACAF,MAAM,CAACS,IAAI,CAACN,MAAM,CAAC;MACnBR,MAAM,IAAIO,SAAS;IACrB;IACA,MAAMQ,QAAQ,GAAG,MAAMV,MAAM,CAACW,MAAM,CAClC,OAAOC,QAAQ,EAAEC,IAAI,EAAEC,CAAC,KAAK;MAC3B,MAAMF,QAAQ;MACd,OAAO,IAAI,CAACnC,SAAS,CAACsC,IAAI,CACxB7C,GAAG,EACHI,qBAAqB,EACrBwC,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,IAAI,EACrB,IAAI,EACJD,IACF,CAAC;IACH,CAAC,EACDG,OAAO,CAACC,OAAO,CAACnB,OAAA,CAAOM,KAAK,CAAC,CAAC,CAAC,CACjC,CAAC;IACD,OAAOM,QAAQ,CAACS,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC;EACjC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"LedgerFactory.mjs","names":["AccountLedger","CLA","GET_ADDRESS","GET_APP_CONFIGURATION","UnsupportedVersionError","semverSatisfies","AccountLedgerFactory","constructor","transport","versionCheckPromise","getAppConfiguration","then","_ref","version","args","scrambleKey","decorateAppAPIMethods","response","send","join","getAddress","accountIndex","verify","arguments","length","undefined","buffer","_Buffer","alloc","writeUInt32BE","addressLength","subarray","toString","initialize","discover","node","index","result","account","push","getAccountByPubkey","address"],"sources":["../../src/account/LedgerFactory.ts"],"sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\nimport AccountLedger, { CLA, GET_ADDRESS, GET_APP_CONFIGURATION } from './Ledger';\nimport { UnsupportedVersionError } from '../utils/errors';\nimport { Encoded } from '../utils/encoder';\nimport semverSatisfies from '../utils/semver-satisfies';\nimport Node from '../Node';\n\n/**\n * A factory class that generates instances of AccountLedger based on provided transport.\n */\nexport default class AccountLedgerFactory {\n readonly transport: Transport;\n\n private readonly versionCheckPromise: Promise<void>;\n\n /**\n * @param transport - Connection to Ledger to use\n */\n constructor(transport: Transport) {\n this.transport = transport;\n this.versionCheckPromise = this.getAppConfiguration().then(({ version }) => {\n const args = [version, '0.4.4', '0.5.0'] as const;\n if (!semverSatisfies(...args)) throw new UnsupportedVersionError('app on ledger', ...args);\n });\n const scrambleKey = 'w0w';\n transport.decorateAppAPIMethods(this, ['getAddress', 'getAppConfiguration'], scrambleKey);\n }\n\n /**\n * @returns the version of app installed on Ledger wallet\n */\n async getAppConfiguration(): Promise<{ version: string }> {\n await this.versionCheckPromise;\n const response = await this.transport.send(CLA, GET_APP_CONFIGURATION, 0x00, 0x00);\n return {\n version: [response[1], response[2], response[3]].join('.'),\n };\n }\n\n /**\n * Get `ak_`-prefixed address for a given account index.\n * @param accountIndex - Index of account\n * @param verify - Ask user to confirm address by showing it on the device screen\n */\n async getAddress(accountIndex: number, verify = false): Promise<Encoded.AccountAddress> {\n await this.versionCheckPromise;\n const buffer = Buffer.alloc(4);\n buffer.writeUInt32BE(accountIndex, 0);\n const response = await this.transport.send(\n CLA,\n GET_ADDRESS,\n verify ? 0x01 : 0x00,\n 0x00,\n buffer,\n );\n const addressLength = response[0];\n return response.subarray(1, 1 + addressLength).toString('ascii') as Encoded.AccountAddress;\n }\n\n /**\n * Get an instance of AccountLedger for a given account index.\n * @param accountIndex - Index of account\n */\n async initialize(accountIndex: number): Promise<AccountLedger> {\n await this.versionCheckPromise;\n return new AccountLedger(this.transport, accountIndex, await this.getAddress(accountIndex));\n }\n\n /**\n * Discovers accounts on Ledger that already have been used (has any on-chain transactions).\n * It returns an empty array if none of accounts been used.\n * If a used account is preceded by an unused account then it would be ignored.\n * @param node - Instance of Node to get account information from\n */\n async discover(node: Node): Promise<AccountLedger[]> {\n let index = 0;\n const result = [];\n let account;\n do {\n if (account != null) result.push(account);\n account = await this.initialize(index);\n index += 1;\n } while (await node.getAccountByPubkey(account.address).then(() => true, () => false));\n return result;\n }\n}\n"],"mappings":";;;;OACOA,aAAa,IAAIC,GAAG,EAAEC,WAAW,EAAEC,qBAAqB;AAAA,SACtDC,uBAAuB;AAAA,OAEzBC,eAAe;AAGtB;AACA;AACA;AACA,eAAe,MAAMC,oBAAoB,CAAC;EAKxC;AACF;AACA;EACEC,WAAWA,CAACC,SAAoB,EAAE;IAChC,IAAI,CAACA,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,mBAAmB,GAAG,IAAI,CAACC,mBAAmB,EAAE,CAACC,IAAI,CAACC,IAAA,IAAiB;MAAA,IAAhB;QAAEC;MAAQ,CAAC,GAAAD,IAAA;MACrE,MAAME,IAAI,GAAG,CAACD,OAAO,EAAE,OAAO,EAAE,OAAO,CAAU;MACjD,IAAI,CAACR,eAAe,CAAC,GAAGS,IAAI,CAAC,EAAE,MAAM,IAAIV,uBAAuB,CAAC,eAAe,EAAE,GAAGU,IAAI,CAAC;IAC5F,CAAC,CAAC;IACF,MAAMC,WAAW,GAAG,KAAK;IACzBP,SAAS,CAACQ,qBAAqB,CAAC,IAAI,EAAE,CAAC,YAAY,EAAE,qBAAqB,CAAC,EAAED,WAAW,CAAC;EAC3F;;EAEA;AACF;AACA;EACE,MAAML,mBAAmBA,CAAA,EAAiC;IACxD,MAAM,IAAI,CAACD,mBAAmB;IAC9B,MAAMQ,QAAQ,GAAG,MAAM,IAAI,CAACT,SAAS,CAACU,IAAI,CAACjB,GAAG,EAAEE,qBAAqB,EAAE,IAAI,EAAE,IAAI,CAAC;IAClF,OAAO;MACLU,OAAO,EAAE,CAACI,QAAQ,CAAC,C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AO,GAAG,MAAM,IAAI,CAACL,UAAU,CAACG,KAAK,CAAC;MACtCA,KAAK,IAAI,CAAC;IACZ,CAAC,QAAQ,MAAMD,IAAI,CAACK,kBAAkB,CAACF,OAAO,CAACG,OAAO,CAAC,CAAC9B,IAAI,CAAC,MAAM,IAAI,EAAE,MAAM,KAAK,CAAC;IACrF,OAAO0B,MAAM;EACf;AACF"}
1
+ {"version":3,"file":"LedgerFactory.mjs","names":["AccountLedger","CLA","GET_ADDRESS","GET_APP_CONFIGURATION","UnsupportedVersionError","semverSatisfies","AccountLedgerFactory","constructor","transport","versionCheckPromise","getAppConfiguration","then","_ref","version","args","scrambleKey","decorateAppAPIMethods","response","send","join","getAddress","accountIndex","verify","arguments","length","undefined","buffer","_Buffer","alloc","writeUInt32BE","addressLength","subarray","toString","initialize","discover","node","index","result","account","push","getAccountByPubkey","address"],"sources":["../../src/account/LedgerFactory.ts"],"sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\nimport AccountLedger, { CLA, GET_ADDRESS, GET_APP_CONFIGURATION } from './Ledger';\nimport { UnsupportedVersionError } from '../utils/errors';\nimport { Encoded } from '../utils/encoder';\nimport semverSatisfies from '../utils/semver-satisfies';\nimport Node from '../Node';\n\n/**\n * A factory class that generates instances of AccountLedger based on provided transport.\n */\nexport default class AccountLedgerFactory {\n readonly transport: Transport;\n\n private readonly versionCheckPromise: Promise<void>;\n\n /**\n * @param transport - Connection to Ledger to use\n */\n constructor(transport: Transport) {\n this.transport = transport;\n this.versionCheckPromise = this.getAppConfiguration().then(({ version }) => {\n const args = [version, '0.4.4', '0.5.0'] as const;\n if (!semverSatisfies(...args)) throw new UnsupportedVersionError('app on ledger', ...args);\n });\n const scrambleKey = 'w0w';\n transport.decorateAppAPIMethods(this, ['getAddress', 'getAppConfiguration'], scrambleKey);\n }\n\n /**\n * @returns the version of app installed on Ledger wallet\n */\n async getAppConfiguration(): Promise<{ version: string }> {\n await this.versionCheckPromise;\n const response = await this.transport.send(CLA, GET_APP_CONFIGURATION, 0x00, 0x00);\n return {\n version: [response[1], response[2], response[3]].join('.'),\n };\n }\n\n /**\n * Get `ak_`-prefixed address for a given account index.\n * @param accountIndex - Index of account\n * @param verify - Ask user to confirm address by showing it on the device screen\n */\n async getAddress(accountIndex: number, verify = false): Promise<Encoded.AccountAddress> {\n await this.versionCheckPromise;\n const buffer = Buffer.alloc(4);\n buffer.writeUInt32BE(accountIndex, 0);\n const response = await this.transport.send(\n CLA,\n GET_ADDRESS,\n verify ? 0x01 : 0x00,\n 0x00,\n buffer,\n );\n const addressLength = response[0];\n return response.subarray(1, 1 + addressLength).toString('ascii') as Encoded.AccountAddress;\n }\n\n /**\n * Get an instance of AccountLedger for a given account index.\n * @param accountIndex - Index of account\n */\n async initialize(accountIndex: number): Promise<AccountLedger> {\n await this.versionCheckPromise;\n return new AccountLedger(this.transport, accountIndex, await this.getAddress(accountIndex));\n }\n\n /**\n * Discovers accounts on Ledger that already have been used (has any on-chain transactions).\n * It returns an empty array if none of accounts been used.\n * If a used account is preceded by an unused account then it would be ignored.\n * @param node - Instance of Node to get account information from\n */\n async discover(node: Node): Promise<AccountLedger[]> {\n let index = 0;\n const result = [];\n let account;\n do {\n if (account != null) result.push(account);\n account = await this.initialize(index);\n index += 1;\n } while (await node.getAccountByPubkey(account.address).then(() => true, () => false));\n return result;\n }\n}\n"],"mappings":";;;;OACOA,aAAa,IAAIC,GAAG,EAAEC,WAAW,EAAEC,qBAAqB;AAAA,SACtDC,uBAAuB;AAAA,OAEzBC,eAAe;AAGtB;AACA;AACA;AACA,eAAe,MAAMC,oBAAoB,CAAC;EAKxC;AACF;AACA;EACEC,WAAWA,CAACC,SAAoB,EAAE;IAChC,IAAI,CAACA,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,mBAAmB,GAAG,IAAI,CAACC,mBAAmB,CAAC,CAAC,CAACC,IAAI,CAACC,IAAA,IAAiB;MAAA,IAAhB;QAAEC;MAAQ,CAAC,GAAAD,IAAA;MACrE,MA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C;IACjC,OAAOA,QAAQ,CAACc,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAGD,aAAa,CAAC,CAACE,QAAQ,CAAC,OAAO,CAAC;EAClE;;EAEA;AACF;AACA;AACA;EACE,MAAMC,UAAUA,CAACZ,YAAoB,EAA0B;IAC7D,MAAM,IAAI,CAACZ,mBAAmB;IAC9B,OAAO,IAAIT,aAAa,CAAC,IAAI,CAACQ,SAAS,EAAEa,YAAY,EAAE,MAAM,IAAI,CAACD,UAAU,CAACC,YAAY,CAAC,CAAC;EAC7F;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,MAAMa,QAAQA,CAACC,IAAU,EAA4B;IACnD,IAAIC,KAAK,GAAG,CAAC;IACb,MAAMC,MAAM,GAAG,EAAE;IACjB,IAAIC,OAAO;IACX,GAAG;MACD,IAAIA,OAAO,IAAI,IAAI,EAAED,MAAM,CAACE,IAAI,CAACD,OAAO,CAAC;MACzCA,OAAO,GAAG,MAAM,IAAI,CAACL,UAAU,CAACG,KAAK,CAAC;MACtCA,KAAK,IAAI,CAAC;IACZ,CAAC,QAAQ,MAAMD,IAAI,CAACK,kBAAkB,CAACF,OAAO,CAACG,OAAO,CAAC,CAAC9B,IAAI,CAAC,MAAM,IAAI,EAAE,MAAM,KAAK,CAAC;IACrF,OAAO0B,MAAM;EACf;AACF"}
@@ -1,6 +1,7 @@
1
1
  import AccountBase from './Base';
2
2
  import { Encoded } from '../utils/encoder';
3
3
  import { AciValue } from '../utils/typed-data';
4
+ import { AensName } from '../tx/builder/constants';
4
5
  export declare function getBufferToSign(transaction: Encoded.Transaction, networkId: string, innerTx: boolean): Uint8Array;
5
6
  /**
6
7
  * In-memory account class
@@ -22,4 +23,13 @@ export default class AccountMemory extends AccountBase {
22
23
  }): Promise<Encoded.Transaction>;
23
24
  signMessage(message: string, options?: any): Promise<Uint8Array>;
24
25
  signTypedData(data: Encoded.ContractBytearray, aci: AciValue, { name, version, networkId, contractAddress, ...options }?: Parameters<AccountBase['signTypedData']>[2]): Promise<Encoded.Signature>;
26
+ signDelegationToContract(contractAddress: Encoded.ContractAddress, { networkId }?: {
27
+ networkId?: string;
28
+ }): Promise<Encoded.Signature>;
29
+ signNameDelegationToContract(contractAddress: Encoded.ContractAddress, name: AensName, { networkId }?: {
30
+ networkId?: string;
31
+ }): Promise<Encoded.Signature>;
32
+ signOracleQueryDelegationToContract(contractAddress: Encoded.ContractAddress, oracleQueryId: Encoded.OracleQueryId, { networkId }?: {
33
+ networkId?: string;
34
+ }): Promise<Encoded.Signature>;
25
35
  }
@@ -10,6 +10,7 @@ import { concatBuffers } from "../utils/other.mjs";
10
10
  import { hashTypedData } from "../utils/typed-data.mjs";
11
11
  import { buildTx } from "../tx/builder/index.mjs";
12
12
  import { Tag } from "../tx/builder/constants.mjs";
13
+ import { produceNameId } from "../tx/builder/helpers.mjs";
13
14
  const secretKeys = new WeakMap();
14
15
  export function getBufferToSign(transaction, networkId, innerTx) {
15
16
  const prefixes = [networkId];
@@ -84,5 +85,38 @@ export default class AccountMemory extends AccountBase {
84
85
  const signature = await this.sign(dHash, options);
85
86
  return encode(signature, Encoding.Signature);
86
87
  }
88
+ async signDelegationToContract(contractAddress) {
89
+ let {
90
+ networkId
91
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
92
+ if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
93
+ const payload = concatBuffers([_Buffer.from(networkId), decode(this.address), decode(contractAddress)]);
94
+ const signature = await this.sign(payload);
95
+ return encode(signature, Encoding.Signature);
96
+ }
97
+ async signNameDelegationToContract(contractAddress, name) {
98
+ let {
99
+ networkId
100
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
101
+ if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
102
+ const payload = concatBuffers([_Buffer.from(networkId), decode(this.address), decode(produceNameId(name)), decode(contractAddress)]);
103
+ const signature = await this.sign(payload);
104
+ return encode(signature, Encoding.Signature);
105
+ }
106
+ async signOracleQueryDelegationToContract(contractAddress, oracleQueryId) {
107
+ let {
108
+ networkId
109
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
110
+ const oracleQueryIdDecoded = decode(oracleQueryId);
111
+ const addressDecoded = decode(this.address);
112
+ // TODO: remove after fixing https://github.com/aeternity/aesophia/issues/475
113
+ if (oracleQueryIdDecoded.compare(addressDecoded) === 0) {
114
+ throw new ArgumentError('oracleQueryId', 'not equal to account address', oracleQueryId);
115
+ }
116
+ if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
117
+ const payload = concatBuffers([_Buffer.from(networkId), oracleQueryIdDecoded, decode(contractAddress)]);
118
+ const signature = await this.sign(payload);
119
+ return encode(signature, Encoding.Signature);
120
+ }
87
121
  }
88
122
  //# sourceMappingURL=Memory.mjs.map