]> git.ardis.lu - solc-metadata/commitdiff
Add index.d.ts for TypeScript support
authorArdis Lu <ardisglu@gmail.com>
Wed, 15 Nov 2023 05:43:53 +0000 (21:43 -0800)
committerArdis Lu <ardisglu@gmail.com>
Wed, 15 Nov 2023 05:43:53 +0000 (21:43 -0800)
README.md
index.d.ts [new file with mode: 0644]

index 76501f63f80f8332ead2c9ddd16cfb713bee4477..dcf85919fa949c128186599d68dbfec6c0c62bd5 100644 (file)
--- a/README.md
+++ b/README.md
@@ -40,3 +40,11 @@ The table above was created by researching the [`solc` changelog](https://github
 Once the CID is calculated, you may finally use the CID to retrieve the full JSON metadata from IPFS (assuming someone has pinned the JSON file in IPFS).
 
 If the smart contract was compiled using an old version of `solc` (before `v0.6.0`), then the metadata may only contain `bzzr0` or `bzzr1` keys. In this case, the tool is unable to fetch the metadata because there are no easily accessible public Swarm gateways, and it's unlikely the metadata is still hosted anyway.
+
+## TypeScript
+
+`index.d.ts` is generated from the [JSDoc](https://jsdoc.app/) comments in `index.js` using `tsc`:
+
+```
+tsc --declaration --emitDeclarationOnly --allowJs ./index.js
+```
diff --git a/index.d.ts b/index.d.ts
new file mode 100644 (file)
index 0000000..6a84825
--- /dev/null
@@ -0,0 +1,35 @@
+/**
+ * Wrapper around the `fetch` API to simplify making an `eth_getCode` JSON-RPC call.
+ * @param {string} address Hex address of the smart contract to retrieve the bytecode for (including `0x` prefix).
+ * @param {string} rpc URL for a node that supports the standard Ethereum JSON-RPC method `eth_getCode`.
+ * @returns {Promise<string|undefined>} `Promise` that will resolve to the `string` bytecode for the address, or `undefined` if the address is malformed.
+ * @throws {TypeError} Will throw an error if the RPC responds with an HTTP error.
+ */
+export function fetchBytecode(address: string, rpc: string): Promise<string | undefined>;
+/**
+ * Parse arbitrary EVM bytecode to extract the bytecode metadata from it.
+ * @param {string} bytecode Raw EVM bytecode in hex (including `0x` prefix).
+ * @param {'solidity'|'vyper'} [lang=solidity] Smart contract language used to compile this bytecode.
+ * @returns {Array<number>} Byte array of the CBOR-encoded bytecode metadata.
+ * @throws {TypeError} Will throw an error if the bytecode is malformed.
+ */
+export function extractCBOR(bytecode: string, lang?: 'solidity' | 'vyper'): Array<number>;
+/**
+ * Decode `solc`-encoded CBOR metadata. This is **not a full CBOR decoder**, it can only handle metadata from `solc`.
+ * @param {Array<number>} cbor Byte array of CBOR-encoded data.
+ * @returns {Object} `Object` representing the decoded CBOR data.
+ */
+export function decodeCBOR(cbor: Array<number>): any;
+/**
+ * Get IPFS CIDs for the JSON metadata file from decoded bytecode metadata.
+ * @param {Object} metadata Decoded bytecode metadata.
+ * @returns {Object} The `solc` compiler version and IPFS CIDs (both CIDv0 and CIDv1) of the JSON metadata.
+ */
+export function calculateCID(metadata: any): any;
+/**
+ * Wrapper around the `fetch` API to simplify querying an IPFS node for a CID.
+ * @param {string} cid An IPFS CID.
+ * @param {string} ipfs URL for an IPFS node.
+ * @returns {Promise<Response>} `Promise` that resolves to a `Response` object.
+ */
+export function fetchCID(cid: string, ipfs: string): Promise<Response>;
This page took 0.037474 seconds and 4 git commands to generate.