@stellar-expert/contract-wasm-interface-parser 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,14 +22,16 @@ Example output:
22
22
  {
23
23
  "enums": {
24
24
  "SubscriptionStatus": {
25
- "Active": {
26
- "value": 0
27
- },
28
- "Cancelled": {
29
- "value": 2
30
- },
31
- "Suspended": {
32
- "value": 1
25
+ "cases": {
26
+ "Active": {
27
+ "value": 0
28
+ },
29
+ "Cancelled": {
30
+ "value": 2
31
+ },
32
+ "Suspended": {
33
+ "value": 1
34
+ }
33
35
  }
34
36
  }
35
37
  },
@@ -178,82 +180,92 @@ Example output:
178
180
  },
179
181
  "structs": {
180
182
  "ConfigData": {
181
- "admin": {
182
- "type": "address"
183
- },
184
- "fee": {
185
- "type": "u64"
186
- },
187
- "token": {
188
- "type": "address"
183
+ "fields": {
184
+ "admin": {
185
+ "type": "address"
186
+ },
187
+ "fee": {
188
+ "type": "u64"
189
+ },
190
+ "token": {
191
+ "type": "address"
192
+ }
189
193
  }
190
194
  },
191
195
  "CreateSubscription": {
192
- "asset1": {
193
- "type": "TickerAsset"
194
- },
195
- "asset2": {
196
- "type": "TickerAsset"
197
- },
198
- "heartbeat": {
199
- "type": "u32"
200
- },
201
- "owner": {
202
- "type": "address"
203
- },
204
- "threshold": {
205
- "type": "u32"
206
- },
207
- "webhook": {
208
- "type": "bytes"
196
+ "fields": {
197
+ "asset1": {
198
+ "type": "TickerAsset"
199
+ },
200
+ "asset2": {
201
+ "type": "TickerAsset"
202
+ },
203
+ "heartbeat": {
204
+ "type": "u32"
205
+ },
206
+ "owner": {
207
+ "type": "address"
208
+ },
209
+ "threshold": {
210
+ "type": "u32"
211
+ },
212
+ "webhook": {
213
+ "type": "bytes"
214
+ }
209
215
  }
210
216
  },
211
217
  "Subscription": {
212
- "asset1": {
213
- "type": "TickerAsset"
214
- },
215
- "asset2": {
216
- "type": "TickerAsset"
217
- },
218
- "balance": {
219
- "type": "u64"
220
- },
221
- "heartbeat": {
222
- "type": "u32"
223
- },
224
- "last_charge": {
225
- "type": "u64"
226
- },
227
- "owner": {
228
- "type": "address"
229
- },
230
- "status": {
231
- "type": "SubscriptionStatus"
232
- },
233
- "threshold": {
234
- "type": "u32"
235
- },
236
- "webhook": {
237
- "type": "bytes"
218
+ "fields": {
219
+ "asset1": {
220
+ "type": "TickerAsset"
221
+ },
222
+ "asset2": {
223
+ "type": "TickerAsset"
224
+ },
225
+ "balance": {
226
+ "type": "u64"
227
+ },
228
+ "heartbeat": {
229
+ "type": "u32"
230
+ },
231
+ "last_charge": {
232
+ "type": "u64"
233
+ },
234
+ "owner": {
235
+ "type": "address"
236
+ },
237
+ "status": {
238
+ "type": "SubscriptionStatus"
239
+ },
240
+ "threshold": {
241
+ "type": "u32"
242
+ },
243
+ "webhook": {
244
+ "type": "bytes"
245
+ }
238
246
  }
239
247
  },
240
248
  "TickerAsset": {
241
- "asset": {
242
- "type": "Asset"
243
- },
244
- "source": {
245
- "type": "string"
249
+ "fields": {
250
+ "asset": {
251
+ "type": "Asset"
252
+ },
253
+ "source": {
254
+ "type": "string"
255
+ }
246
256
  }
247
257
  }
248
258
  },
249
259
  "unions": {
250
260
  "Asset": {
251
- "Other": [
252
- "symbol"
253
- ],
254
- "Stellar": [
255
- "address"
256
- ]
261
+ "cases": {
262
+ "Other": [
263
+ "symbol"
264
+ ],
265
+ "Stellar": [
266
+ "address"
267
+ ]
268
+ }
257
269
  }
258
270
  },
259
271
  "interfaceVersion": "85899345920",
@@ -0,0 +1,2 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@stellar/stellar-base")):"function"==typeof define&&define.amd?define(["@stellar/stellar-base"],t):"object"==typeof exports?exports.sorobanwasmparser=t(require("@stellar/stellar-base")):e.sorobanwasmparser=t(e["@stellar/stellar-base"])}(this,(e=>(()=>{"use strict";var t={755:t=>{t.exports=e}},r={};function s(e){var a=r[e];if(void 0!==a)return a.exports;var n=r[e]={exports:{}};return t[e](n,n.exports,s),n.exports}s.d=(e,t)=>{for(var r in t)s.o(t,r)&&!s.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var a={};s.d(a,{default:()=>h});var n=s(755);function i(e,t){const r=new o(e),s=[];for(;!r.eof;)s.push(t.read(r));return s}class o{constructor(e){if(!Buffer.isBuffer(e)){if(!(e instanceof Array))throw new Error("Source not specified");e=Buffer.from(e)}this._buffer=e,this._length=e.length,this._index=0}_buffer;_length;_index;get eof(){return this._index===this._length}advance(e){const t=this._index;if(this._index+=e,this._length<this._index)throw new Error("attempt to read outside the boundary of the buffer");const r=4-(e%4||4);if(r>0){for(let e=0;e<r;e++)if(0!==this._buffer[this._index+e])throw new Error("Invalid padding");this._index+=r}return t}rewind(){this._index=0}read(e){const t=this.advance(e);return this._buffer.subarray(t,t+e)}readInt32BE(){return this._buffer.readInt32BE(this.advance(4))}readUInt32BE(){return this._buffer.readUInt32BE(this.advance(4))}readBigInt64BE(){return this._buffer.readBigInt64BE(this.advance(8))}readBigUInt64BE(){return this._buffer.readBigUInt64BE(this.advance(8))}readFloatBE(){return this._buffer.readFloatBE(this.advance(4))}readDoubleBE(){return this._buffer.readDoubleBE(this.advance(8))}ensureInputConsumed(){if(this._index!==this._length)throw new Error("Invalid XDR contract typecast - source buffer not entirely consumed")}}class c{constructor(e){this.data=e}data;pointer=8;readCustomSections(){const e=[];for(;this.pointer<this.data.length;){const t=this.readUint8();let r=this.readVarUint32();if(0===t){const t=this.pointer,s=this.readString();r-=this.pointer-t,e.push({name:s,contents:this.data.subarray(this.pointer,this.pointer+r)})}this.pointer+=r}return e}readUint8(){return this.data.readUint8(this.pointer++)}readVarUint32(){let e=0,t=0;for(;;){let r=this.readUint8();if(e|=(127&r)<<t,t+=7,!(128&r))break}return e>>>0}readString(){const e=this.readVarUint32(),t=this.data.subarray(this.pointer,this.pointer+e);return this.pointer+=e,t.toString("utf-8")}}function u(e){const t={};for(const{_value:r}of e){const e=r.key().toString(),s=r.val().toString();switch(e){case"rsver":t.rustVersion=s;break;case"rssdkver":t.sdkVersion=s}}return t}class p{constructor(){this.res={}}res;addSpec(e,t,r){let s=this.res[e];void 0===s&&(s=this.res[e]={}),r.call(this,t,s)}parse(e){for(const t of e){const e=t.value(),{_attributes:r}=e;switch(t._arm){case"functionV0":this.addSpec("functions",r,this.parseFunction);break;case"udtStructV0":this.addSpec("structs",r,this.parseStruct);break;case"udtUnionV0":this.addSpec("unions",r,this.parseUnion);break;case"udtEnumV0":this.addSpec("enums",r,this.parseEnum);break;case"udtErrorEnumV0":this.addSpec("errors",r,this.parseError);break;default:console.log("Unknown spec type: "+t._arm)}}return this.res}parseFunction(e,t){const r={};e.inputs.forEach((e=>this.parseParameter(e,r))),t[e.name.toString()]=this.withDocs({inputs:r,outputs:e.outputs.map((e=>this.parseParameterType(e)))},e)}parseStruct(e,t){const r={};e.fields.forEach((e=>this.parseParameter(e,r))),t[this.parseStructName(e)]=this.withDocs({fields:r},e)}parseUnion(e,t){const r={};e.cases.forEach((e=>{const t=e.value();r[t.name().toString()]=t.type?t.type().map((e=>this.parseParameterType(e))):[]})),t[this.parseStructName(e)]=this.withDocs({cases:r},e)}parseEnum(e,t){const r={};e.cases.forEach((e=>{const t=e.value();if(t.name)r[t.name().toString()]=t.value();else{const s=e._attributes;r[s.name.toString()]=this.withDocs({value:t},s)}})),t[this.parseStructName(e)]=this.withDocs({cases:r},e)}parseError(e,t){e.cases.forEach((e=>{const r=e._attributes;t[r.name.toString()]=this.withDocs({value:r.value},r)}))}parseParameterType(e){const t=e.switch().name;switch(t){case"scSpecTypeOption":return`option<${this.parseParameterType(e.value().valueType())}>`;case"scSpecTypeBytesN":return`bytesn<${e.value().n()}>`;case"scSpecTypeVec":return`vec<${this.parseParameterType(e.value().elementType())}>`;case"scSpecTypeMap":return`map<${this.parseParameterType(e.value().keyType())},${this.parseParameterType(e.value().valueType())}>`;case"scSpecTypeResult":return`result<${this.parseParameterType(e.value().okType())},${this.parseParameterType(e.value().errorType())}>`;case"scSpecTypeTuple":return`tuple<${e.value().valueTypes().map((e=>this.parseParameterType(e))).join()}>`;case"scSpecTypeUdt":return e.value().name().toString();default:return t.replace("scSpecType","").toLowerCase()}}parseStructName(e){let t=e.name.toString();return e.lib.length&&(t+=":"+e.lib.toString()),t}parseParameter(e,t){const r=e._attributes;t[r.name.toString()]=this.withDocs({type:this.parseParameterType(r.type)},r)}withDocs(e,t){return t.doc?.length&&(e.doc=t.doc.toString()),e}}const h={parseContractMetadata:function(e){const t=new c(e).readCustomSections(),r={};for(const e of t)switch(e.name){case"contractenvmetav0":r.interfaceVersion=n.xdr.ScEnvMetaEntry.fromXDR(e.contents).value().toString();break;case"contractmetav0":Object.assign(r,u(i(e.contents,n.xdr.ScMetaEntry)));break;case"contractspecv0":Object.assign(r,(s=i(e.contents,n.xdr.ScSpecEntry),(new p).parse(s)))}var s;return r}};return a.default})()));
2
+ //# sourceMappingURL=wasmparser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasmparser.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAAQ,0BACR,mBAAXC,QAAyBA,OAAOC,IAC9CD,OAAO,CAAC,yBAA0BJ,GACR,iBAAZC,QACdA,QAA2B,kBAAID,EAAQG,QAAQ,0BAE/CJ,EAAwB,kBAAIC,EAAQD,EAAK,yBAC1C,CATD,CASGO,MAAOC,G,kCCTVL,EAAOD,QAAUM,C,GCCbC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaV,QAGrB,IAAIC,EAASM,EAAyBE,GAAY,CAGjDT,QAAS,CAAC,GAOX,OAHAY,EAAoBH,GAAUR,EAAQA,EAAOD,Q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B,QAAAA,CAAS2B,EAAY7C,GAIjB,OAHIA,EAAK8C,KAAKtF,SACVqF,EAAWC,IAAM9C,EAAK8C,IAAIxD,YAEvBuD,CACX,EC9HJ,MAEA,EAFc,CAACE,sBApBR,SAA+BC,GAClC,MACMrE,EADoB,IAAIJ,EAAkByE,GACbtE,qBAC7Be,EAAM,CAAC,EACb,IAAK,MAAMwD,KAAWtE,EAClB,OAAQsE,EAAQjE,MACZ,IAAK,oBACDS,EAAIyD,iBAAmBC,EAAAA,IAAIC,eAAeC,QAAQJ,EAAQ/D,UAAUkB,QAAQd,WAC5E,MACJ,IAAK,iBACDzD,OAAOyH,OAAO7D,EAAKF,EAAkBjD,EAAuB2G,EAAQ/D,SAAUiE,EAAAA,IAAII,eAClF,MACJ,IAAK,iBACD1H,OAAOyH,OAAO7D,GDNJ9C,ECMmBL,EAAuB2G,EAAQ/D,SAAUiE,EAAAA,IAAIK,cDL/E,IAAI1D,GAAaK,MAAMxD,KAD3B,IAAmBA,ECUtB,OAAO8C,CACX,G","sources":["webpack://sorobanwasmparser/webpack/universalModuleDefinition","webpack://sorobanwasmparser/external umd \"@stellar/stellar-base\"","webpack://sorobanwasmparser/webpack/bootstrap","webpack://sorobanwasmparser/webpack/runtime/define property getters","webpack://sorobanwasmparser/webpack/runtime/hasOwnProperty shorthand","webpack://sorobanwasmparser/./src/xdr-reader.js","webpack://sorobanwasmparser/./src/wasm-section-reader.js","webpack://sorobanwasmparser/./src/xdr-spec-parser.js","webpack://sorobanwasmparser/./src/index.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"@stellar/stellar-base\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"@stellar/stellar-base\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"sorobanwasmparser\"] = factory(require(\"@stellar/stellar-base\"));\n\telse\n\t\troot[\"sorobanwasmparser\"] = factory(root[\"@stellar/stellar-base\"]);\n})(this, (__WEBPACK_EXTERNAL_MODULE__755__) => {\nreturn ","module.exports = __WEBPACK_EXTERNAL_MODULE__755__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","/**\r\n *\r\n * @param {Buffer} buffer\r\n * @param {{read: function}} xdrContract\r\n * @return {{}[]}\r\n */\r\nexport function parseSectionEntriesXdr(buffer, xdrContract) {\r\n const reader = new XdrReader(buffer)\r\n const entries = []\r\n while (!reader.eof) {\r\n entries.push(xdrContract.read(reader))\r\n }\r\n return entries\r\n}\r\n\r\nclass XdrReader {\r\n /**\r\n * @constructor\r\n * @param {Buffer} source - Buffer containing serialized data\r\n */\r\n constructor(source) {\r\n if (!Buffer.isBuffer(source)) {\r\n if (source instanceof Array) {\r\n source = Buffer.from(source)\r\n } else\r\n throw new Error('Source not specified')\r\n }\r\n\r\n this._buffer = source\r\n this._length = source.length\r\n this._index = 0\r\n }\r\n\r\n /**\r\n * @type {Buffer}\r\n * @private\r\n * @readonly\r\n */\r\n _buffer\r\n /**\r\n * @type {Number}\r\n * @private\r\n * @readonly\r\n */\r\n _length\r\n /**\r\n * @type {Number}\r\n * @private\r\n * @readonly\r\n */\r\n _index\r\n\r\n /**\r\n * Check if the reader reached the end of the input buffer\r\n * @return {Boolean}\r\n */\r\n get eof() {\r\n return this._index === this._length\r\n }\r\n\r\n /**\r\n * Advance reader position, check padding and overflow\r\n * @param {Number} size - Bytes to read\r\n * @return {Number} Position to read from\r\n * @private\r\n */\r\n advance(size) {\r\n const from = this._index\r\n // advance cursor position\r\n this._index += size\r\n // check buffer boundaries\r\n if (this._length < this._index)\r\n throw new Error(\r\n 'attempt to read outside the boundary of the buffer'\r\n )\r\n // check that padding is correct for Opaque and String\r\n const padding = 4 - (size % 4 || 4)\r\n if (padding > 0) {\r\n for (let i = 0; i < padding; i++)\r\n if (this._buffer[this._index + i] !== 0)\r\n // all bytes in the padding should be zeros\r\n throw new Error('Invalid padding')\r\n this._index += padding\r\n }\r\n return from\r\n }\r\n\r\n /**\r\n * Reset reader position\r\n */\r\n rewind() {\r\n this._index = 0\r\n }\r\n\r\n /**\r\n * Read byte array from the buffer\r\n * @param {Number} size - Bytes to read\r\n * @return {Buffer} - Sliced portion of the underlying buffer\r\n */\r\n read(size) {\r\n const from = this.advance(size)\r\n return this._buffer.subarray(from, from + size)\r\n }\r\n\r\n /**\r\n * Read i32 from buffer\r\n * @return {Number}\r\n */\r\n readInt32BE() {\r\n return this._buffer.readInt32BE(this.advance(4))\r\n }\r\n\r\n /**\r\n * Read u32 from buffer\r\n * @return {Number}\r\n */\r\n readUInt32BE() {\r\n return this._buffer.readUInt32BE(this.advance(4))\r\n }\r\n\r\n /**\r\n * Read i64 from buffer\r\n * @return {BigInt}\r\n */\r\n readBigInt64BE() {\r\n return this._buffer.readBigInt64BE(this.advance(8))\r\n }\r\n\r\n /**\r\n * Read u64 from buffer\r\n * @return {BigInt}\r\n */\r\n readBigUInt64BE() {\r\n return this._buffer.readBigUInt64BE(this.advance(8))\r\n }\r\n\r\n /**\r\n * Read float from buffer\r\n * @return {Number}\r\n */\r\n readFloatBE() {\r\n return this._buffer.readFloatBE(this.advance(4))\r\n }\r\n\r\n /**\r\n * Read double from buffer\r\n * @return {Number}\r\n */\r\n readDoubleBE() {\r\n return this._buffer.readDoubleBE(this.advance(8))\r\n }\r\n\r\n /**\r\n * Ensure that input buffer has been consumed in full, otherwise it's a type mismatch\r\n */\r\n ensureInputConsumed() {\r\n if (this._index !== this._length)\r\n throw new Error(`Invalid XDR contract typecast - source buffer not entirely consumed`)\r\n }\r\n}","/**\r\n * Minimalistic WASM metadata reader\r\n */\r\nexport class WasmSectionReader {\r\n constructor(data) {\r\n this.data = data\r\n }\r\n\r\n /**\r\n * @type {Buffer}\r\n * @private\r\n */\r\n data\r\n /**\r\n * Current reader position\r\n * @type {number}\r\n * @private\r\n */\r\n pointer = 8\r\n\r\n /**\r\n * Read custom metadata sections from raw WASM\r\n * @return {{name: string, contents: Buffer}[]}\r\n */\r\n readCustomSections() {\r\n const sections = []\r\n while (this.pointer < this.data.length) {\r\n const sectionType = this.readUint8()\r\n let length = this.readVarUint32()\r\n if (sectionType === 0) { //accumulate only custom sections\r\n const sectionStart = this.pointer\r\n const name = this.readString()\r\n length -= this.pointer - sectionStart\r\n sections.push({\r\n name,\r\n contents: this.data.subarray(this.pointer, this.pointer + length)\r\n })\r\n }\r\n this.pointer += length\r\n }\r\n return sections\r\n }\r\n\r\n /**\r\n * @return {number}\r\n * @private\r\n */\r\n readUint8() {\r\n return this.data.readUint8(this.pointer++)\r\n }\r\n\r\n /**\r\n * @return {number}\r\n * @private\r\n */\r\n readVarUint32() {\r\n let result = 0\r\n let shift = 0\r\n while (true) {\r\n let byte = this.readUint8()\r\n result |= (byte & 0x7f) << shift\r\n shift += 7\r\n if ((byte & 0x80) === 0)\r\n break\r\n }\r\n return result >>> 0\r\n }\r\n\r\n /**\r\n * @return {string}\r\n * @private\r\n */\r\n readString() {\r\n const length = this.readVarUint32()\r\n const contents = this.data.subarray(this.pointer, this.pointer + length)\r\n this.pointer += length\r\n return contents.toString('utf-8')\r\n }\r\n}","export function parseContractMeta(meta) {\r\n const res = {}\r\n for (const {_value} of meta) {\r\n const key = _value.key().toString()\r\n const val = _value.val().toString()\r\n switch (key) {\r\n case 'rsver':\r\n res.rustVersion = val\r\n break\r\n case 'rssdkver':\r\n res.sdkVersion = val\r\n break\r\n }\r\n }\r\n return res\r\n}\r\n\r\nexport function parseSpec(entries) {\r\n return new SpecParser().parse(entries)\r\n}\r\n\r\n\r\nclass SpecParser {\r\n constructor() {\r\n this.res = {}\r\n }\r\n\r\n /**\r\n * @type {{}}\r\n */\r\n res\r\n\r\n addSpec(key, attr, parser) {\r\n //this.parseFunction(attr), attr.doc\r\n let spec = this.res[key]\r\n if (spec === undefined) {\r\n spec = this.res[key] = {}\r\n }\r\n parser.call(this, attr, spec)\r\n }\r\n\r\n parse(entries) {\r\n for (const spec of entries) {\r\n const value = spec.value()\r\n const {_attributes: attr} = value\r\n switch (spec._arm) {\r\n case 'functionV0':\r\n this.addSpec('functions', attr, this.parseFunction)\r\n break\r\n case 'udtStructV0':\r\n this.addSpec('structs', attr, this.parseStruct)\r\n break\r\n case 'udtUnionV0':\r\n this.addSpec('unions', attr, this.parseUnion)\r\n break\r\n case 'udtEnumV0':\r\n this.addSpec('enums', attr, this.parseEnum)\r\n break\r\n case 'udtErrorEnumV0':\r\n this.addSpec('errors', attr, this.parseError)\r\n break\r\n default:\r\n console.log('Unknown spec type: ' + spec._arm)\r\n break\r\n }\r\n }\r\n return this.res\r\n }\r\n\r\n parseFunction(attr, into) {\r\n const inputs = {}\r\n attr.inputs.forEach(i => this.parseParameter(i, inputs))\r\n into[attr.name.toString()] = this.withDocs({\r\n inputs,\r\n outputs: attr.outputs.map(o => this.parseParameterType(o))\r\n }, attr)\r\n }\r\n\r\n parseStruct(attr, into) {\r\n const fields = {}\r\n attr.fields.forEach(f => this.parseParameter(f, fields))\r\n into[this.parseStructName(attr)] = this.withDocs({fields}, attr)\r\n }\r\n\r\n parseUnion(attr, into) {\r\n const cases = {}\r\n attr.cases.forEach(c => {\r\n const value = c.value()\r\n cases[value.name().toString()] = value.type ?\r\n value.type().map(t => this.parseParameterType(t)) :\r\n []\r\n })\r\n into[this.parseStructName(attr)] = this.withDocs({cases}, attr)\r\n }\r\n\r\n parseEnum(attr, into) {\r\n const cases = {}\r\n attr.cases.forEach(c => {\r\n const value = c.value()\r\n if (value.name) {\r\n cases[value.name().toString()] = value.value()\r\n } else {\r\n const attr = c._attributes\r\n cases[attr.name.toString()] = this.withDocs({value}, attr)\r\n }\r\n })\r\n into[this.parseStructName(attr)] = this.withDocs({cases}, attr)\r\n }\r\n\r\n parseError(attr, into) {\r\n attr.cases.forEach(c => {\r\n const attr = c._attributes\r\n into[attr.name.toString()] = this.withDocs({value: attr.value}, attr)\r\n })\r\n }\r\n\r\n parseParameterType(type) {\r\n const typeName = type.switch().name\r\n switch (typeName) {\r\n case 'scSpecTypeOption':\r\n return `option<${this.parseParameterType(type.value().valueType())}>`\r\n case 'scSpecTypeBytesN':\r\n return `bytesn<${type.value().n()}>`\r\n case 'scSpecTypeVec':\r\n return `vec<${this.parseParameterType(type.value().elementType())}>`\r\n case 'scSpecTypeMap':\r\n return `map<${this.parseParameterType(type.value().keyType())},${this.parseParameterType(type.value().valueType())}>`\r\n case 'scSpecTypeResult':\r\n return `result<${this.parseParameterType(type.value().okType())},${this.parseParameterType(type.value().errorType())}>`\r\n case 'scSpecTypeTuple':\r\n return `tuple<${type.value().valueTypes().map(v => this.parseParameterType(v)).join()}>`\r\n case 'scSpecTypeUdt':\r\n return type.value().name().toString()\r\n default:\r\n return typeName.replace('scSpecType', '').toLowerCase()\r\n }\r\n }\r\n\r\n parseStructName(value) {\r\n let structName = value.name.toString()\r\n if (value.lib.length) {\r\n structName += ':' + value.lib.toString()\r\n }\r\n return structName\r\n }\r\n\r\n parseParameter(param, into) {\r\n const attr = param._attributes\r\n into[attr.name.toString()] = this.withDocs({type: this.parseParameterType(attr.type)}, attr)\r\n }\r\n\r\n withDocs(descriptor, attr) {\r\n if (attr.doc?.length) {\r\n descriptor.doc = attr.doc.toString()\r\n }\r\n return descriptor\r\n }\r\n}\r\n\r\n","import {xdr} from '@stellar/stellar-base'\r\nimport {parseSectionEntriesXdr} from './xdr-reader'\r\nimport {WasmSectionReader} from './wasm-section-reader'\r\nimport {parseContractMeta, parseSpec} from './xdr-spec-parser'\r\n\r\n/**\r\n * Parse contract metadata from WASM sections\r\n * @param {Buffer} rawWasm\r\n * @return {ParsedWasmMeta}\r\n */\r\nexport function parseContractMetadata(rawWasm) {\r\n const wasmSectionReader = new WasmSectionReader(rawWasm)\r\n const sections = wasmSectionReader.readCustomSections()\r\n const res = {}\r\n for (const section of sections) {\r\n switch (section.name) {\r\n case 'contractenvmetav0':\r\n res.interfaceVersion = xdr.ScEnvMetaEntry.fromXDR(section.contents).value().toString()\r\n break\r\n case 'contractmetav0':\r\n Object.assign(res, parseContractMeta(parseSectionEntriesXdr(section.contents, xdr.ScMetaEntry)))\r\n break\r\n case 'contractspecv0':\r\n Object.assign(res, parseSpec(parseSectionEntriesXdr(section.contents, xdr.ScSpecEntry)))\r\n break\r\n }\r\n }\r\n return res\r\n}\r\n\r\nconst index = {parseContractMetadata}\r\n\r\nexport default index\r\n\r\n/**\r\n * @typedef {{}} ParsedWasmMeta\r\n * @property {{}} functions\r\n * @property {{}} [errors]\r\n * @property {{}} [enums]\r\n * @property {{}} [structs]\r\n * @property {{}} [unions]\r\n * @property {string} rustVersion\r\n * @property {string} sdkVersion\r\n * @property {string} interfaceVersion\r\n */"],"names":["root","factory","exports","module","require","define","amd","this","__WEBPACK_EXTERNAL_MODULE__755__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","parseSectionEntriesXdr","buffer","xdrContract","reader","XdrReader","entries","eof","push","read","constructor","source","Buffer","isBuffer","Array","Error","from","_buffer","_length","length","_index","advance","size","padding","i","rewind","subarray","readInt32BE","readUInt32BE","readBigInt64BE","readBigUInt64BE","readFloatBE","readDoubleBE","ensureInputConsumed","WasmSectionReader","data","pointer","readCustomSections","sections","sectionType","readUint8","readVarUint32","sectionStart","name","readString","contents","result","shift","byte","toString","parseContractMeta","meta","res","_value","val","rustVersion","sdkVersion","SpecParser","addSpec","attr","parser","spec","parse","value","_attributes","_arm","parseFunction","parseStruct","parseUnion","parseEnum","parseError","console","log","into","inputs","forEach","parseParameter","withDocs","outputs","map","parseParameterType","fields","f","parseStructName","cases","c","type","t","typeName","switch","valueType","n","elementType","keyType","okType","errorType","valueTypes","v","join","replace","toLowerCase","structName","lib","param","descriptor","doc","parseContractMetadata","rawWasm","section","interfaceVersion","xdr","ScEnvMetaEntry","fromXDR","assign","ScMetaEntry","ScSpecEntry"],"sourceRoot":""}
package/package.json CHANGED
@@ -1,18 +1,25 @@
1
1
  {
2
2
  "name": "@stellar-expert/contract-wasm-interface-parser",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "Contract interface metadata parser for binary WASM",
5
- "main": "index.js",
6
- "module": "./index.js",
5
+ "author": "orbitlens <orbit@stellar.expert>",
6
+ "license": "MIT",
7
+ "main": "lib/wasmparser.js",
8
+ "module": "src/index.js",
9
+ "sideEffects": false,
10
+ "exports": {
11
+ "import": "./src/index.js",
12
+ "require": "./lib/wasmparser.js"
13
+ },
7
14
  "repository": {
8
15
  "type": "git",
9
16
  "url": "git+https://github.com/stellar-expert/contract-wasm-interface-parser.git"
10
17
  },
11
18
  "scripts": {
12
- "test": "jest"
19
+ "build": "webpack --mode=production --config webpack.config.cjs",
20
+ "test": "jest",
21
+ "prepublish": "npm run build"
13
22
  },
14
- "author": "orbitlens <orbit@stellar.expert>",
15
- "license": "MIT",
16
23
  "peerDependencies": {
17
24
  "@stellar/stellar-base": ">=12"
18
25
  },
@@ -1,7 +1,7 @@
1
1
  import {xdr} from '@stellar/stellar-base'
2
- import {parseSectionEntriesXdr} from './src/xdr-reader'
3
- import {WasmSectionReader} from './src/wasm-section-reader'
4
- import {parseContractMeta, parseSpec} from './src/xdr-spec-parser'
2
+ import {parseSectionEntriesXdr} from './xdr-reader'
3
+ import {WasmSectionReader} from './wasm-section-reader'
4
+ import {parseContractMeta, parseSpec} from './xdr-spec-parser'
5
5
 
6
6
  /**
7
7
  * Parse contract metadata from WASM sections
@@ -28,6 +28,10 @@ export function parseContractMetadata(rawWasm) {
28
28
  return res
29
29
  }
30
30
 
31
+ const index = {parseContractMetadata}
32
+
33
+ export default index
34
+
31
35
  /**
32
36
  * @typedef {{}} ParsedWasmMeta
33
37
  * @property {{}} functions
@@ -73,13 +73,13 @@ class SpecParser {
73
73
  into[attr.name.toString()] = this.withDocs({
74
74
  inputs,
75
75
  outputs: attr.outputs.map(o => this.parseParameterType(o))
76
- }, attr.doc)
76
+ }, attr)
77
77
  }
78
78
 
79
79
  parseStruct(attr, into) {
80
80
  const fields = {}
81
81
  attr.fields.forEach(f => this.parseParameter(f, fields))
82
- into[this.parseStructName(attr)] = this.withDocs(fields, attr.doc)
82
+ into[this.parseStructName(attr)] = this.withDocs({fields}, attr)
83
83
  }
84
84
 
85
85
  parseUnion(attr, into) {
@@ -90,7 +90,7 @@ class SpecParser {
90
90
  value.type().map(t => this.parseParameterType(t)) :
91
91
  []
92
92
  })
93
- into[this.parseStructName(attr)] = this.withDocs(cases, attr.doc)
93
+ into[this.parseStructName(attr)] = this.withDocs({cases}, attr)
94
94
  }
95
95
 
96
96
  parseEnum(attr, into) {
@@ -100,14 +100,18 @@ class SpecParser {
100
100
  if (value.name) {
101
101
  cases[value.name().toString()] = value.value()
102
102
  } else {
103
- cases[c._attributes.name.toString()] = this.withDocs({value}, c.doc())
103
+ const attr = c._attributes
104
+ cases[attr.name.toString()] = this.withDocs({value}, attr)
104
105
  }
105
106
  })
106
- into[this.parseStructName(attr)] = this.withDocs(cases, attr.doc)
107
+ into[this.parseStructName(attr)] = this.withDocs({cases}, attr)
107
108
  }
108
109
 
109
110
  parseError(attr, into) {
110
- attr.cases.forEach(c => into[c.name().toString()] = this.withDocs({value: c.value()}, c.doc()))
111
+ attr.cases.forEach(c => {
112
+ const attr = c._attributes
113
+ into[attr.name.toString()] = this.withDocs({value: attr.value}, attr)
114
+ })
111
115
  }
112
116
 
113
117
  parseParameterType(type) {
@@ -124,7 +128,7 @@ class SpecParser {
124
128
  case 'scSpecTypeResult':
125
129
  return `result<${this.parseParameterType(type.value().okType())},${this.parseParameterType(type.value().errorType())}>`
126
130
  case 'scSpecTypeTuple':
127
- return `tuple<${type.value().valueTypes().map(this.parseParameterType).join()}>`
131
+ return `tuple<${type.value().valueTypes().map(v => this.parseParameterType(v)).join()}>`
128
132
  case 'scSpecTypeUdt':
129
133
  return type.value().name().toString()
130
134
  default:
@@ -141,13 +145,13 @@ class SpecParser {
141
145
  }
142
146
 
143
147
  parseParameter(param, into) {
144
- const {_attributes: attr} = param
145
- into[attr.name.toString()] = this.withDocs({type: this.parseParameterType(attr.type)}, attr.doc)
148
+ const attr = param._attributes
149
+ into[attr.name.toString()] = this.withDocs({type: this.parseParameterType(attr.type)}, attr)
146
150
  }
147
151
 
148
- withDocs(descriptor, doc) {
149
- if (doc?.length) {
150
- descriptor.doc = doc.toString()
152
+ withDocs(descriptor, attr) {
153
+ if (attr.doc?.length) {
154
+ descriptor.doc = attr.doc.toString()
151
155
  }
152
156
  return descriptor
153
157
  }
package/babel.config.js DELETED
@@ -1,20 +0,0 @@
1
- module.exports = {
2
- presets: [
3
- [
4
- '@babel/preset-env',
5
- {
6
- corejs: '3.34',
7
- useBuiltIns: 'entry',
8
- //modules: false,
9
- targets: {
10
- browsers: [
11
- '> 1%',
12
- 'not dead',
13
- 'not op_mini all'
14
- ],
15
- node: '18'
16
- }
17
- }
18
- ]
19
- ]
20
- }