sarvalabs / js-moi-sdk

JavaScript library to interact with MOI Protocol via RPC API
https://js-moi-sdk.docs.moi.technology/
Apache License 2.0
24 stars 2 forks source link

feat: add `decodeManifest` method to `ManifestCoder` #91

Closed sarvalabs-harshrastogi closed 1 month ago

sarvalabs-harshrastogi commented 2 months ago

Add decodeManifest method to ManifestCoder

Description

This pull request adds a new method decodeManifest to the ManifestCoder class. This method allows decoding of POLO encoded manifests into their JSON equivalent, addressing the current lack of this feature in the library.

Changes

Implementation Details

The decodeManifest method takes a POLO encoded manifest (either as a hex string or Uint8Array) and its format as input, and returns a LogicManifest.Manifest object. It includes input validation and error handling for invalid manifests or unsupported formats.

Example

const manifest = `0x0e4f031e9e01012f064e504953410fdf010ebe08be10be1cee31ce3d9e505f0300068e01636f6e7374616e742f0666737472696e6730783036363936653733373536363636363936333639363536653734323036323631366336313665363336354f0310166e0173746174653f069e01657068656d6572616c3f0eae024f030696015370656e6461626c65753235364f03169601014c6f636b65647570753235364f0310166e0273746174653f06ae0170657273697374656e747f0eee01fe03ee053f0306464e616d65737472696e673f0316760153796d626f6c737472696e673f03167602537570706c79753235363f031666034f776e6572616464726573735f031e66de01032f03130201726f7574696e65cf010646e601ce028e099e099e115365656470657273697374656e746465706c6f795f0eee01fe033f0306466e616d65737472696e673f0316760173796d626f6c737472696e673f03167602737570706c79753235360f5f06a607a007800000040100360001810080000104010136000181008000020401023600018100800003730249020236000281007300830200003602018402000f5f031e46be01041f0301726f7574696e65df010686019602fe028e039e03de075265676973746572657068656d6572616c656e6c6973740f0f5f06e603e0037300830100002b02073601028401007300830101002b02073601028401000f5f031e56ce01052f030301726f7574696e65cf010666f601de02de04ee04ce0e4c6f636b7570657068656d6572616c696e766f6b651f0e3f030666616d6f756e74753235360f5f06860980097300830100003702010403004404020362040411050b03050411040010040407040166030203240203360102840100730083010100370201040300650302032402033601028401000f5f031e66de01062f03130201726f7574696e65cf010646e601ce02ce04de04be0a4d696e7470657273697374656e74696e766f6b651f0e3f030666616d6f756e74753235360f5f0686058005800002370100040200650101023600018100730083010000370201040300650202033601028401000f`;
const decoded = ManifestCoder.decodeManifest(manifest, ManifestFormat.JSON);

console.log(JSON.stringify(decoded, null, 4)); // >> { syntax: 1, engine: { kind: "PISA", flags: [] }, elements: [...] }

Changes include

Checklist

cloudflare-workers-and-pages[bot] commented 1 month ago

Deploying js-moi-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 418560c
Status: ✅  Deploy successful!
Preview URL: https://890df1e5.js-moi-sdk.pages.dev
Branch Preview URL: https://feat-90-decode-polo-hex-json.js-moi-sdk.pages.dev

View logs