-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes: #10614 refs: #10249 #10250 ## Description Pack a bech32 "base address" (like "agoric1...") plus HTTP query string "hook parameter" bytes into a bech32 "address hook". These address hooks are bech32-encoded (i.e., all of their data is encoded and part of the bech32 checksum), but they may be up to 1024 characters in length (instead of the default 90-character length limit). ### Example ```js import { encodeAddressHook, decodeAddressHook, } from '@agoric/cosmic-proto/address-hooks.js'; const baseAddress = 'agoric1qqp0e5ys'; const query = { key: 'value', foo: ['bar', 'baz'] }; const addressHook = encodeAddressHook(baseAddress, query); // 'agoric10rchqqplvehk70tzv9ezven0du7kyct6ye4k27faweskcat9qqqstnf2eq' addressHook.startsWith('agoric10rch'); // true const decoded = decodeAddressHook(addressHook); // { // baseAddress: 'agoric1qqp0e5ys', // query: [Object: null prototype] { foo: [ 'bar', 'baz' ], key: 'value' } // } ``` ### Encoding Specifically, an address hook looks like "agoric10rch...", and its binary payload consists of: | offset | 0 | 3 | 3+len(baseAddress) | len(payload)-2 | | ------ | ----- | ----------- | ------------------ | ---------------- | | data | magic | baseAddress | hookData | len(baseAddress) | `magic` is a 3-byte prefix that identifies a hooked address and its version nibble, whose value is 4 bits (between 0 and 0xf (15)). Currently, the only supported version is 0. ```js 0x78, 0xf1, (0x70 | ADDRESS_HOOK_VERSION), ``` This magic prefix encodes as `0rch`, regardless of the version or HRP (e.g. `'agoric10rch<rest of payload as bech32><bech32 checksum>'`). ### Security Considerations Improves robustness of address hook extraction with magic bytes and version nibble, as well as length validation. ### Scaling Considerations n/a ### Documentation Considerations Needs to be documented as part of Orch Core Address Hooks. ### Testing Considerations Should be tested as part of a regular contract. Already verified that encoding/decoding unit tests can pass in a JS compartment without any special powers. ### Upgrade Considerations Layered to facilitate the construction of arbitrary hookData, not just URL query strings. Should be extensible if needed.
- Loading branch information
Showing
13 changed files
with
748 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.