Repository navigation
feat(sdk): #17 typed @yieldstream/sdk TypeScript client and Merkle tooling - #20
Merged
Merged
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #17.
Sibling SDK repository PR: yieldstream-org/yieldstream-sdk#7
Implements the official typed client wrapping the YieldStream distributor contract for web frontends (
@stellar/stellar-sdk+ Freighter):createCampaign/buildCreateCampaignTx)generateTree&computeLeaf: Byte-identical JavaScript/TypeScript port of the contract's domain-separated Merkle leaf hashing including XDR ScVal encodingsgetProof(wallet, distributionId, tree))claimandclaimMany(Freighter and web app ready)created,claimed,cancel,swept,upgrade)Implementation Details
1. Merkle Engine (
packages/sdk/src/merkle.ts)LEAF_PREFIX = 0x00,NODE_PREFIX = 0x01).merkle.rsbyte-for-byte:20198\text{leaf} = \text{SHA-256}(0\text{x}00 \mathbin{\Vert} \text{XDR}(\text{distribution_id}) \mathbin{\Vert} \text{XDR}(\text{index}) \mathbin{\Vert} \text{XDR}(\text{recipient}) \mathbin{\Vert} \text{XDR}(\text{amount}))20198
20198\text{parent} = \text{SHA-256}(0\text{x}01 \mathbin{\Vert} \min(a, b) \mathbin{\Vert} \max(a, b))20198
generateTree(distributionId, recipients)returning root, leaves, and per-claim inclusion proofs.verifyProof(proof, root, leaf)for off-chain inclusion validation.2. Typed Protocol Client (
packages/sdk/src/client.ts)YieldStreamClientconfigured withcontractId,networkPassphrase, andrpcUrl.buildCreateCampaignTx/createCampaignbuildClaimTx/claimbuildClaimManyTx/claimMany(batched claim operations)buildCancelTxbuildSweepTxbuildUpgradeTxgetDistribution(id)isClaimed(id, index)getDistributionCount()getAdmin()getVersion()3. Cross-Language Conformance Test Suite (
packages/sdk/src/conformance.test.ts)test-vectors/merkle_v1.json.computeLeafgenerates 100% byte-identical hashes for every single leaf inmerkle_v1.jsonbuildTreereproduces roots and inclusion proofs matching the contract vectorsgenerateTreereproduces all vector outputsYieldStreamClientbuilds validinvokeHostFunctionoperations forcreateCampaignandclaim4. Documentation & Packaging (
packages/sdk/README.md)@stellar/stellar-sdkand Freighter.tsconfig.json), declaration maps, and dual MIT/Apache-2.0 license.Acceptance Criteria Verification
merkle_v1.json) — 9/9 tests passpackages/sdk/README.mddeclarationMap,sourceMap)cargo fmt --check,cargo clippy --all-targets -- -D warnings, andcargo testall pass