Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions packages/js-evo-sdk/src/addresses/facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,204 @@ export class AddressesFacade {
const w = await this.sdk.getWasmSdkConnected();
return w.getAddressesInfosWithProofInfo(addresses);
}

/**
* Transfers credits between Platform addresses.
*
* @param options - Transfer options including inputs, outputs, and signer
* @returns Promise resolving to transfer result with updated address information
*
* @example
* ```typescript
* const recipientAddr = PlatformAddress.fromBech32m("tdashevo1...");
* const privateKey = PrivateKey.fromWIF("cPrivateKeyWif...");
*
* const signer = new PlatformAddressSigner();
* const senderAddr = signer.addKey(privateKey); // Derives P2PKH address from key
*
* const input = new PlatformAddressInput(senderAddr, 0n, 100000n);
* const output = new PlatformAddressOutput(recipientAddr, 90000n);
*
* const result = await sdk.addresses.transfer({
* inputs: [input],
* outputs: [output],
* signer
* });
* ```
*/
async transfer(options: wasm.AddressFundsTransferOptions): Promise<Map<wasm.PlatformAddress, wasm.PlatformAddressInfo>> {
const w = await this.sdk.getWasmSdkConnected();
return w.addressFundsTransfer(options);
}
Comment on lines +83 to +86

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Search for addressFundsTransfer definition in wasm-sdk
rg -nP --type=ts --type=d.ts 'addressFundsTransfer' --max-count=20

Repository: dashpay/platform

Length of output: 88


🏁 Script executed:

# Find test files for the transfer method
fd -t f 'facade.*test\|.*\.spec\.ts' packages/js-evo-sdk

Repository: dashpay/platform

Length of output: 42


🏁 Script executed:

# Search for AddressFundsTransfer related types
rg -nP --type=ts --type=d.ts 'AddressFundsTransfer(Result|Options)' --max-count=20

Repository: dashpay/platform

Length of output: 88


🏁 Script executed:

# Search for addressFundsTransfer more broadly
rg -n 'addressFundsTransfer' packages/

Repository: dashpay/platform

Length of output: 762


🏁 Script executed:

# Find test files more broadly
find packages/js-evo-sdk -type f -name '*.test.ts' -o -name '*.spec.ts'

Repository: dashpay/platform

Length of output: 42


🏁 Script executed:

# Look for facade-related test files
find packages/js-evo-sdk -type f -name '*facade*'

Repository: dashpay/platform

Length of output: 521


🏁 Script executed:

# Search for AddressFundsTransfer types in wasm-sdk
rg -n 'AddressFundsTransfer' packages/wasm-sdk/

Repository: dashpay/platform

Length of output: 845


🏁 Script executed:

# Read the test file to see actual return values
cat packages/js-evo-sdk/tests/unit/facades/addresses.spec.mjs

Repository: dashpay/platform

Length of output: 10867


🏁 Script executed:

# Read the Rust source for addressFundsTransfer
cat packages/wasm-sdk/src/state_transitions/addresses.rs

Repository: dashpay/platform

Length of output: 38593


Return type does not match test expectations.

The declared return type Promise<Map<wasm.PlatformAddress, wasm.PlatformAddressInfo>> contradicts what the test file expects. Tests stub addressFundsTransfer to return a discriminated union object (lines 22-25, 105-108) with a type field containing either 'VerifiedAddressInfos' (with addressInfos array) or 'Success' (with message string), not a Map. Update the return type in facade.ts to match the actual WASM SDK return shape, or verify that the WASM binding's return type definition is correct.

🤖 Prompt for AI Agents
In packages/js-evo-sdk/src/addresses/facade.ts around lines 84-87, the declared
return type Promise<Map<wasm.PlatformAddress, wasm.PlatformAddressInfo>> does
not match what tests (and the WASM stub) actually return — a discriminated-union
with type 'VerifiedAddressInfos' (containing addressInfos array) or 'Success'
(containing message). Change the transfer method's return type to the actual
WASM return shape (e.g., Promise<wasm.AddressFundsTransferResult> or an explicit
union like Promise<{type: 'VerifiedAddressInfos'; addressInfos: ...} | {type:
'Success'; message: string}>), keep the implementation calling
w.addressFundsTransfer(options) unchanged, and/or update the WASM binding type
if that definition is incorrect so the facade signature reflects the real return
value.


/**
* Top up an identity from Platform addresses.
*
* @param options - Top up options including identity ID, inputs, and signer
* @returns Promise resolving to result with updated address infos and new identity balance
*
* @example
* ```typescript
* const identityId = Identifier.from("...");
* const privateKey = PrivateKey.fromWIF("cPrivateKeyWif...");
*
* const signer = new PlatformAddressSigner();
* const sourceAddr = signer.addKey(privateKey); // Derives P2PKH address from key
*
* const input = new PlatformAddressInput(sourceAddr, 0n, 50000n);
*
* const result = await sdk.addresses.topUpIdentity({
* identityId,
* inputs: [input],
* signer
* });
*
* console.log('New identity balance:', result.newBalance);
* ```
*/
async topUpIdentity(options: wasm.IdentityTopUpFromAddressesOptions): Promise<wasm.IdentityTopUpFromAddressesResult> {
const w = await this.sdk.getWasmSdkConnected();
return w.identityTopUpFromAddresses(options);
}

/**
* Withdraws Platform address credits to Dash Core.
*
* @param options - Withdrawal options including inputs, output script, pooling, and signer
* @returns Promise resolving to Map of PlatformAddress to PlatformAddressInfo
*
* @example
* ```typescript
* const privateKey = PrivateKey.fromWIF("cPrivateKeyWif...");
*
* // Create Core output script for L1 destination
* const coreScript = CoreScript.newP2PKH(coreAddressHash);
*
* const signer = new PlatformAddressSigner();
* const platformAddr = signer.addKey(privateKey); // Derives P2PKH address from key
*
* const input = new PlatformAddressInput(platformAddr, 0n, 100000n);
*
* const result = await sdk.addresses.withdraw({
* inputs: [input],
* coreFeePerByte: 1,
* pooling: PoolingWasm.Standard,
* outputScript: coreScript,
* signer
* });
* ```
*/
async withdraw(options: wasm.AddressFundsWithdrawOptions): Promise<Map<wasm.PlatformAddress, wasm.PlatformAddressInfo>> {
const w = await this.sdk.getWasmSdkConnected();
return w.addressFundsWithdraw(options);
}

/**
* Transfer credits from an identity to Platform addresses.
*
* @param options - Transfer options including identity ID, outputs, and signer
* @returns Result with updated address information and new identity balance
*
* @example
* ```typescript
* const identityId = Identifier.from("...");
* const recipientAddr = PlatformAddress.fromBech32m("tdashevo1...");
* const privateKey = PrivateKey.fromWIF("cPrivateKeyWif..."); // Identity transfer key
*
* const output = new PlatformAddressOutput(recipientAddr, 100000n);
*
* // Create identity signer and add the transfer key
* const signer = new IdentitySigner();
* signer.addKey(privateKey);
*
* const result = await sdk.addresses.transferFromIdentity({
* identityId,
* outputs: [output],
* signer
* });
*
* console.log(`New identity balance: ${result.newBalance}`);
* console.log(`Updated addresses:`, result.addressInfos);
* ```
*/
async transferFromIdentity(options: wasm.IdentityTransferToAddressesOptions): Promise<wasm.IdentityTransferToAddressesResult> {
const w = await this.sdk.getWasmSdkConnected();
return w.identityTransferToAddresses(options);
}

/**
* Fund Platform addresses from an asset lock.
*
* @param options - Funding options including asset lock proof, outputs, and signer
* @returns Promise resolving to Map of PlatformAddress to PlatformAddressInfo
*
* @example
* ```typescript
* const assetLockPrivateKey = PrivateKey.fromWIF("cPrivateKeyWif...");
* const addressPrivateKey = PrivateKey.fromWIF("cPrivateKeyWif...");
*
* // Create asset lock proof from L1 transaction
* const assetLockProof = AssetLockProof.createInstantAssetLockProof(
* instantLockBytes,
* transactionBytes,
* outputIndex
* );
*
* const signer = new PlatformAddressSigner();
* const platformAddr = signer.addKey(addressPrivateKey); // Derives P2PKH address from key
*
* const output = new PlatformAddressOutput(platformAddr, 100000n);
*
* const result = await sdk.addresses.fundFromAssetLock({
* assetLockProof,
* assetLockPrivateKey,
* outputs: [output],
* signer
* });
* ```
*/
async fundFromAssetLock(options: wasm.AddressFundingFromAssetLockOptions): Promise<Map<wasm.PlatformAddress, wasm.PlatformAddressInfo>> {
const w = await this.sdk.getWasmSdkConnected();
return w.addressFundingFromAssetLock(options);
}

/**
* Create an identity funded from Platform addresses.
*
* @param options - Creation options including identity, inputs, and signers
* @returns Promise resolving to result with created identity and updated address infos
*
* @example
* ```typescript
* const addressPrivateKey = PrivateKey.fromWIF("cAddressPrivateKeyWif...");
* const identityPrivateKey = PrivateKey.fromWIF("cIdentityKeyWif...");
*
* // Create identity structure with public keys
* const identity = new Identity(Identifier.random());
* identity.addPublicKey(identityPublicKey);
*
* // Create signers
* const addressSigner = new PlatformAddressSigner();
* const sourceAddr = addressSigner.addKey(addressPrivateKey); // Derives P2PKH address from key
*
* const input = new PlatformAddressInput(sourceAddr, 0n, 100000n);
*
* const identitySigner = new IdentitySigner();
* identitySigner.addKey(identityPrivateKey);
*
* const result = await sdk.addresses.createIdentity({
* identity,
* inputs: [input],
* identitySigner,
* addressSigner
* });
*
* console.log('Created identity:', result.identity.id());
* console.log('Updated addresses:', result.addressInfos);
* ```
*/
async createIdentity(options: wasm.IdentityCreateFromAddressesOptions): Promise<wasm.IdentityCreateFromAddressesResult> {
const w = await this.sdk.getWasmSdkConnected();
return w.identityCreateFromAddresses(options);
}
}
1 change: 0 additions & 1 deletion packages/js-evo-sdk/src/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ export async function ensureInitialized(): Promise<void> {
// Re-export all wasm SDK symbols for convenience
export * from '@dashevo/wasm-sdk/compressed';
export { default } from '@dashevo/wasm-sdk/compressed';
export type { DataContract } from '@dashevo/wasm-sdk/compressed';
5 changes: 4 additions & 1 deletion packages/js-evo-sdk/tests/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ extends:
- airbnb-base
- plugin:jsdoc/recommended
env:
es2020: true
es2022: true
node: true
mocha: true
parserOptions:
ecmaVersion: 2022
sourceType: module
rules:
eol-last:
- error
Expand Down
Loading
Loading