@stellar-expert/contract-wasm-interface-parser 3.1.0 → 4.0.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 +13 -13
- package/lib/wasmparser.js +2 -0
- package/lib/wasmparser.js.map +1 -0
- package/package.json +14 -7
- package/{index.js → src/index.js} +12 -4
- package/src/xdr-spec-parser.js +64 -17
- package/babel.config.js +0 -20
package/README.md
CHANGED
|
@@ -68,7 +68,7 @@ Example output:
|
|
|
68
68
|
"admin": {
|
|
69
69
|
"inputs": {},
|
|
70
70
|
"outputs": [
|
|
71
|
-
"
|
|
71
|
+
"Option<Address>"
|
|
72
72
|
]
|
|
73
73
|
},
|
|
74
74
|
"cancel": {
|
|
@@ -82,7 +82,7 @@ Example output:
|
|
|
82
82
|
"charge": {
|
|
83
83
|
"inputs": {
|
|
84
84
|
"subscription_ids": {
|
|
85
|
-
"type": "
|
|
85
|
+
"type": "Vec<u64>"
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
"outputs": []
|
|
@@ -105,7 +105,7 @@ Example output:
|
|
|
105
105
|
}
|
|
106
106
|
},
|
|
107
107
|
"outputs": [
|
|
108
|
-
"
|
|
108
|
+
"(u64, Subscription)"
|
|
109
109
|
]
|
|
110
110
|
},
|
|
111
111
|
"deposit": {
|
|
@@ -114,7 +114,7 @@ Example output:
|
|
|
114
114
|
"type": "u64"
|
|
115
115
|
},
|
|
116
116
|
"from": {
|
|
117
|
-
"type": "
|
|
117
|
+
"type": "Address"
|
|
118
118
|
},
|
|
119
119
|
"subscription_id": {
|
|
120
120
|
"type": "u64"
|
|
@@ -158,7 +158,7 @@ Example output:
|
|
|
158
158
|
"type": "u64"
|
|
159
159
|
},
|
|
160
160
|
"trigger_hash": {
|
|
161
|
-
"type": "
|
|
161
|
+
"type": "BytesN<32>"
|
|
162
162
|
}
|
|
163
163
|
},
|
|
164
164
|
"outputs": []
|
|
@@ -166,7 +166,7 @@ Example output:
|
|
|
166
166
|
"update_contract": {
|
|
167
167
|
"inputs": {
|
|
168
168
|
"wasm_hash": {
|
|
169
|
-
"type": "
|
|
169
|
+
"type": "BytesN<32>"
|
|
170
170
|
}
|
|
171
171
|
},
|
|
172
172
|
"outputs": []
|
|
@@ -182,13 +182,13 @@ Example output:
|
|
|
182
182
|
"ConfigData": {
|
|
183
183
|
"fields": {
|
|
184
184
|
"admin": {
|
|
185
|
-
"type": "
|
|
185
|
+
"type": "Address"
|
|
186
186
|
},
|
|
187
187
|
"fee": {
|
|
188
188
|
"type": "u64"
|
|
189
189
|
},
|
|
190
190
|
"token": {
|
|
191
|
-
"type": "
|
|
191
|
+
"type": "Address"
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
},
|
|
@@ -204,13 +204,13 @@ Example output:
|
|
|
204
204
|
"type": "u32"
|
|
205
205
|
},
|
|
206
206
|
"owner": {
|
|
207
|
-
"type": "
|
|
207
|
+
"type": "Address"
|
|
208
208
|
},
|
|
209
209
|
"threshold": {
|
|
210
210
|
"type": "u32"
|
|
211
211
|
},
|
|
212
212
|
"webhook": {
|
|
213
|
-
"type": "
|
|
213
|
+
"type": "Bytes"
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
},
|
|
@@ -232,7 +232,7 @@ Example output:
|
|
|
232
232
|
"type": "u64"
|
|
233
233
|
},
|
|
234
234
|
"owner": {
|
|
235
|
-
"type": "
|
|
235
|
+
"type": "Address"
|
|
236
236
|
},
|
|
237
237
|
"status": {
|
|
238
238
|
"type": "SubscriptionStatus"
|
|
@@ -241,7 +241,7 @@ Example output:
|
|
|
241
241
|
"type": "u32"
|
|
242
242
|
},
|
|
243
243
|
"webhook": {
|
|
244
|
-
"type": "
|
|
244
|
+
"type": "Bytes"
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
},
|
|
@@ -268,7 +268,7 @@ Example output:
|
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
},
|
|
271
|
-
"interfaceVersion": "
|
|
271
|
+
"interfaceVersion": "20.0",
|
|
272
272
|
"rustVersion": "1.74.0",
|
|
273
273
|
"sdkVersion": "20.5.0#9e2c3022b4355b224a7a814e13ba51761eeb14bb"
|
|
274
274
|
}
|
|
@@ -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:()=>d});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;break;default:t[e]=s}}return t}function p(e){return(new h).parse(e)}class h{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;case"eventV0":this.addSpec("events",r,this.parseEvent);break;default:console.log("Unknown spec type: "+t._arm)}}return this.res}parseFunction(e,t){t[e.name.toString()]=this.withDocs({inputs:e.inputs.map(e=>this.parseFuncArgument(e)),outputs:e.outputs.map(e=>this.parseParameterType(e))},e)}parseStruct(e,t){const r={};for(const t of e.fields)this.parseParameter(t,r);t[this.parseStructName(e)]=this.withDocs({fields:r},e)}parseUnion(e,t){const r={};for(const t of e.cases){const e=t.value();r[e.name().toString()]=e.type?e.type().map(e=>this.parseParameterType(e)):[]}t[this.parseStructName(e)]=this.withDocs({cases:r},e)}parseEnum(e,t){const r={};for(const t of e.cases){const e=t.value();if(e.name)r[e.name().toString()]=e.value();else{const s=t._attributes;r[s.name.toString()]=this.withDocs({value:e},s)}}t[this.parseStructName(e)]=this.withDocs({cases:r},e)}parseError(e,t){for(const r of e.cases){const e=r._attributes;t[e.name.toString()]=this.withDocs({value:e.value},e)}}parseEvent(e,t){let r;switch(e.dataFormat.value){case 1:r="Vec";break;case 2:r="Map";break;default:r=e.dataFormat.name}const s={prefixTopics:e.prefixTopics.map(e=>e.toString()),params:e.params.map(e=>{const t=e._attributes,r={name:t.name.toString(),type:this.parseParameterType(t.type),location:0===t.location.value?"data":"topics"};return this.withDocs(r,t)}),dataFormat:r};t[this.parseStructName(e)]=this.withDocs(s,e)}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`(${e.value().valueTypes().map(e=>this.parseParameterType(e)).join(", ")})`;case"scSpecTypeUdt":return e.value().name().toString();default:let r=t.replace("scSpecType","");return(/^[IU](8|16|32|64|128)$/.test(r)||"Bool"===r)&&(r=r.toLowerCase()),r}}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)}parseFuncArgument(e){const t=e._attributes;return this.withDocs({name:t.name.toString(),type:this.parseParameterType(t.type)},t)}withDocs(e,t){return t.doc?.length&&(e.doc=t.doc.toString()),e}}const d={parseContractMetadata:function(e){const t=new c(e).readCustomSections(),r={};for(const e of t)switch(e.name){case"contractenvmetav0":const t=n.xdr.ScEnvMetaEntry.fromXDR(e.contents).value()._attributes;r.interfaceVersion=`${t.protocol}.${t.preRelease}`;break;case"contractmetav0":Object.assign(r,u(i(e.contents,n.xdr.ScMetaEntry)));break;case"contractspecv0":Object.assign(r,p(i(e.contents,n.xdr.ScSpecEntry)));break;default:r[e.name]=e.contents.toString()}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,KAAOC,G,iCCTVL,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,QAASQ,GAG/CP,EAAOD,OACf,CCrBAQ,EAAoBK,EAAI,CAACb,EAASc,KACjC,IAAI,IAAIC,KAAOD,EACXN,EAAoBQ,EAAEF,EAAYC,KAASP,EAAoBQ,EAAEhB,EAASe,IAC5EE,OAAOC,eAAelB,EAASe,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EP,EAAoBQ,EAAI,CAACK,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,G,6CCM3E,SAASI,EAAuBC,EAAQC,GAC3C,MAAMC,EA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AuBuH,EAAQ3E,SAAU4E,EAAAA,IAAIQ,eAC1E,MACJ,QACI7E,EAAIoE,EAAQ7E,MAAQ6E,EAAQ3E,SAASI,WAIjD,OAAOG,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 default:\r\n res[key] = 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 case 'eventV0':\r\n this.addSpec('events', attr, this.parseEvent)\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 into[attr.name.toString()] = this.withDocs({\r\n inputs: attr.inputs.map(a => this.parseFuncArgument(a)),\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 for (const f of attr.fields) {\r\n this.parseParameter(f, fields)\r\n }\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 for (const c of attr.cases) {\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 for (const c of attr.cases) {\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 for (const c of attr.cases) {\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 parseEvent(attr, into) {\r\n let dataFormat\r\n switch (attr.dataFormat.value) {\r\n case 1:\r\n dataFormat = 'Vec'\r\n break\r\n case 2:\r\n dataFormat = 'Map'\r\n break\r\n default:\r\n dataFormat = attr.dataFormat.name\r\n break\r\n }\r\n const evt = {\r\n prefixTopics: attr.prefixTopics.map(t => t.toString()),\r\n params: attr.params.map(p => {\r\n const pa = p._attributes\r\n const param = {\r\n name: pa.name.toString(),\r\n type: this.parseParameterType(pa.type),\r\n location: pa.location.value === 0 ? 'data' : 'topics'\r\n }\r\n return this.withDocs(param, pa)\r\n }),\r\n dataFormat\r\n }\r\n into[this.parseStructName(attr)] = this.withDocs(evt, attr)\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 `(${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 let res = typeName.replace('scSpecType', '')\r\n if (/^[IU](8|16|32|64|128)$/.test(res) || res === 'Bool') { //remap standard int types\r\n res = res.toLowerCase()\r\n }\r\n return res\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 parseFuncArgument(arg) {\r\n const attr = arg._attributes\r\n return this.withDocs({\r\n name: attr.name.toString(),\r\n type: this.parseParameterType(attr.type)\r\n }, 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 const v = xdr.ScEnvMetaEntry.fromXDR(section.contents).value()._attributes\r\n res.interfaceVersion = `${v.protocol}.${v.preRelease}`\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 default:\r\n res[section.name] = section.contents.toString()\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","parseSpec","SpecParser","parse","addSpec","attr","parser","spec","value","_attributes","_arm","parseFunction","parseStruct","parseUnion","parseEnum","parseError","parseEvent","console","log","into","withDocs","inputs","map","a","parseFuncArgument","outputs","parseParameterType","fields","f","parseParameter","parseStructName","cases","c","type","t","dataFormat","evt","prefixTopics","params","p","pa","param","location","typeName","switch","valueType","n","elementType","keyType","okType","errorType","valueTypes","v","join","replace","test","toLowerCase","structName","lib","arg","descriptor","doc","parseContractMetadata","rawWasm","section","xdr","ScEnvMetaEntry","fromXDR","interfaceVersion","protocol","preRelease","assign","ScMetaEntry","ScSpecEntry"],"ignoreList":[],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stellar-expert/contract-wasm-interface-parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Contract interface metadata parser for binary WASM",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"@stellar/stellar-base": ">=
|
|
24
|
+
"@stellar/stellar-base": ">=14"
|
|
18
25
|
},
|
|
19
26
|
"devDependencies": {
|
|
20
27
|
"@babel/core": "^7.24.8",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {xdr} from '@stellar/stellar-base'
|
|
2
|
-
import {parseSectionEntriesXdr} from './
|
|
3
|
-
import {WasmSectionReader} from './
|
|
4
|
-
import {parseContractMeta, parseSpec} from './
|
|
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
|
|
@@ -15,7 +15,8 @@ export function parseContractMetadata(rawWasm) {
|
|
|
15
15
|
for (const section of sections) {
|
|
16
16
|
switch (section.name) {
|
|
17
17
|
case 'contractenvmetav0':
|
|
18
|
-
|
|
18
|
+
const v = xdr.ScEnvMetaEntry.fromXDR(section.contents).value()._attributes
|
|
19
|
+
res.interfaceVersion = `${v.protocol}.${v.preRelease}`
|
|
19
20
|
break
|
|
20
21
|
case 'contractmetav0':
|
|
21
22
|
Object.assign(res, parseContractMeta(parseSectionEntriesXdr(section.contents, xdr.ScMetaEntry)))
|
|
@@ -23,11 +24,18 @@ export function parseContractMetadata(rawWasm) {
|
|
|
23
24
|
case 'contractspecv0':
|
|
24
25
|
Object.assign(res, parseSpec(parseSectionEntriesXdr(section.contents, xdr.ScSpecEntry)))
|
|
25
26
|
break
|
|
27
|
+
default:
|
|
28
|
+
res[section.name] = section.contents.toString()
|
|
29
|
+
break
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
return res
|
|
29
33
|
}
|
|
30
34
|
|
|
35
|
+
const index = {parseContractMetadata}
|
|
36
|
+
|
|
37
|
+
export default index
|
|
38
|
+
|
|
31
39
|
/**
|
|
32
40
|
* @typedef {{}} ParsedWasmMeta
|
|
33
41
|
* @property {{}} functions
|
package/src/xdr-spec-parser.js
CHANGED
|
@@ -10,6 +10,9 @@ export function parseContractMeta(meta) {
|
|
|
10
10
|
case 'rssdkver':
|
|
11
11
|
res.sdkVersion = val
|
|
12
12
|
break
|
|
13
|
+
default:
|
|
14
|
+
res[key] = val
|
|
15
|
+
break
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
return res
|
|
@@ -59,6 +62,9 @@ class SpecParser {
|
|
|
59
62
|
case 'udtErrorEnumV0':
|
|
60
63
|
this.addSpec('errors', attr, this.parseError)
|
|
61
64
|
break
|
|
65
|
+
case 'eventV0':
|
|
66
|
+
this.addSpec('events', attr, this.parseEvent)
|
|
67
|
+
break
|
|
62
68
|
default:
|
|
63
69
|
console.log('Unknown spec type: ' + spec._arm)
|
|
64
70
|
break
|
|
@@ -68,34 +74,34 @@ class SpecParser {
|
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
parseFunction(attr, into) {
|
|
71
|
-
const inputs = {}
|
|
72
|
-
attr.inputs.forEach(i => this.parseParameter(i, inputs))
|
|
73
77
|
into[attr.name.toString()] = this.withDocs({
|
|
74
|
-
inputs,
|
|
78
|
+
inputs: attr.inputs.map(a => this.parseFuncArgument(a)),
|
|
75
79
|
outputs: attr.outputs.map(o => this.parseParameterType(o))
|
|
76
80
|
}, attr)
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
parseStruct(attr, into) {
|
|
80
84
|
const fields = {}
|
|
81
|
-
|
|
85
|
+
for (const f of attr.fields) {
|
|
86
|
+
this.parseParameter(f, fields)
|
|
87
|
+
}
|
|
82
88
|
into[this.parseStructName(attr)] = this.withDocs({fields}, attr)
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
parseUnion(attr, into) {
|
|
86
92
|
const cases = {}
|
|
87
|
-
attr.cases
|
|
93
|
+
for (const c of attr.cases) {
|
|
88
94
|
const value = c.value()
|
|
89
95
|
cases[value.name().toString()] = value.type ?
|
|
90
96
|
value.type().map(t => this.parseParameterType(t)) :
|
|
91
97
|
[]
|
|
92
|
-
}
|
|
98
|
+
}
|
|
93
99
|
into[this.parseStructName(attr)] = this.withDocs({cases}, attr)
|
|
94
100
|
}
|
|
95
101
|
|
|
96
102
|
parseEnum(attr, into) {
|
|
97
103
|
const cases = {}
|
|
98
|
-
attr.cases
|
|
104
|
+
for (const c of attr.cases) {
|
|
99
105
|
const value = c.value()
|
|
100
106
|
if (value.name) {
|
|
101
107
|
cases[value.name().toString()] = value.value()
|
|
@@ -103,36 +109,69 @@ class SpecParser {
|
|
|
103
109
|
const attr = c._attributes
|
|
104
110
|
cases[attr.name.toString()] = this.withDocs({value}, attr)
|
|
105
111
|
}
|
|
106
|
-
}
|
|
112
|
+
}
|
|
107
113
|
into[this.parseStructName(attr)] = this.withDocs({cases}, attr)
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
parseError(attr, into) {
|
|
111
|
-
attr.cases
|
|
117
|
+
for (const c of attr.cases) {
|
|
112
118
|
const attr = c._attributes
|
|
113
119
|
into[attr.name.toString()] = this.withDocs({value: attr.value}, attr)
|
|
114
|
-
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
parseEvent(attr, into) {
|
|
124
|
+
let dataFormat
|
|
125
|
+
switch (attr.dataFormat.value) {
|
|
126
|
+
case 1:
|
|
127
|
+
dataFormat = 'Vec'
|
|
128
|
+
break
|
|
129
|
+
case 2:
|
|
130
|
+
dataFormat = 'Map'
|
|
131
|
+
break
|
|
132
|
+
default:
|
|
133
|
+
dataFormat = attr.dataFormat.name
|
|
134
|
+
break
|
|
135
|
+
}
|
|
136
|
+
const evt = {
|
|
137
|
+
prefixTopics: attr.prefixTopics.map(t => t.toString()),
|
|
138
|
+
params: attr.params.map(p => {
|
|
139
|
+
const pa = p._attributes
|
|
140
|
+
const param = {
|
|
141
|
+
name: pa.name.toString(),
|
|
142
|
+
type: this.parseParameterType(pa.type),
|
|
143
|
+
location: pa.location.value === 0 ? 'data' : 'topics'
|
|
144
|
+
}
|
|
145
|
+
return this.withDocs(param, pa)
|
|
146
|
+
}),
|
|
147
|
+
dataFormat
|
|
148
|
+
}
|
|
149
|
+
into[this.parseStructName(attr)] = this.withDocs(evt, attr)
|
|
115
150
|
}
|
|
116
151
|
|
|
117
152
|
parseParameterType(type) {
|
|
118
153
|
const typeName = type.switch().name
|
|
119
154
|
switch (typeName) {
|
|
120
155
|
case 'scSpecTypeOption':
|
|
121
|
-
return `
|
|
156
|
+
return `Option<${this.parseParameterType(type.value().valueType())}>`
|
|
122
157
|
case 'scSpecTypeBytesN':
|
|
123
|
-
return `
|
|
158
|
+
return `BytesN<${type.value().n()}>`
|
|
124
159
|
case 'scSpecTypeVec':
|
|
125
|
-
return `
|
|
160
|
+
return `Vec<${this.parseParameterType(type.value().elementType())}>`
|
|
126
161
|
case 'scSpecTypeMap':
|
|
127
|
-
return `
|
|
162
|
+
return `Map<${this.parseParameterType(type.value().keyType())}, ${this.parseParameterType(type.value().valueType())}>`
|
|
128
163
|
case 'scSpecTypeResult':
|
|
129
|
-
return `
|
|
164
|
+
return `Result<${this.parseParameterType(type.value().okType())}, ${this.parseParameterType(type.value().errorType())}>`
|
|
130
165
|
case 'scSpecTypeTuple':
|
|
131
|
-
return `
|
|
166
|
+
return `(${type.value().valueTypes().map(v => this.parseParameterType(v)).join(', ')})`
|
|
132
167
|
case 'scSpecTypeUdt':
|
|
133
168
|
return type.value().name().toString()
|
|
134
169
|
default:
|
|
135
|
-
|
|
170
|
+
let res = typeName.replace('scSpecType', '')
|
|
171
|
+
if (/^[IU](8|16|32|64|128)$/.test(res) || res === 'Bool') { //remap standard int types
|
|
172
|
+
res = res.toLowerCase()
|
|
173
|
+
}
|
|
174
|
+
return res
|
|
136
175
|
}
|
|
137
176
|
}
|
|
138
177
|
|
|
@@ -149,6 +188,14 @@ class SpecParser {
|
|
|
149
188
|
into[attr.name.toString()] = this.withDocs({type: this.parseParameterType(attr.type)}, attr)
|
|
150
189
|
}
|
|
151
190
|
|
|
191
|
+
parseFuncArgument(arg) {
|
|
192
|
+
const attr = arg._attributes
|
|
193
|
+
return this.withDocs({
|
|
194
|
+
name: attr.name.toString(),
|
|
195
|
+
type: this.parseParameterType(attr.type)
|
|
196
|
+
}, attr)
|
|
197
|
+
}
|
|
198
|
+
|
|
152
199
|
withDocs(descriptor, attr) {
|
|
153
200
|
if (attr.doc?.length) {
|
|
154
201
|
descriptor.doc = attr.doc.toString()
|
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
|
-
}
|