Skip to content

Commit 78a6f46

Browse files
authored
feat: typescript sdk enhancements (#3236)
2 parents 568ad67 + 8282fbb commit 78a6f46

24 files changed

+393
-220
lines changed

typescript-sdk/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<h1 align="center" style="font-size: 2.75rem; font-weight: 900; color: white;">Union Labs TypeScript SDK</h1>
22

3+
![JSR](https://jsr.io/badges/@union/client) ![NPM Version](https://img.shields.io/npm/v/@unionlabs/client)
4+
35
Union Labs TypeScript SDK providing utilities for cross-chain transfers and more.
46

57
```sh

typescript-sdk/bun.lockb

1.4 KB
Binary file not shown.

typescript-sdk/package.json

+17-16
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,41 @@
2020
"build": "tsup --config='tsup.config.ts'",
2121
"typecheck": "tsc --project tsconfig.json --noEmit",
2222
"test": "vitest --run",
23-
"test:typecheck": "vitest --typecheck.only",
24-
"check-package": "bunx publint@latest --strict && bunx @arethetypeswrong/cli --pack --ignore-rules 'cjs-resolves-to-esm'",
25-
"clean": "rm -rf dist node_modules",
26-
"knip": "knip --config='knip.json'",
27-
"postinstall": "patch-package",
2823
"prepublish": "bun run build",
29-
"typedoc": "bun x typedoc@latest --out .docs ./src/mod.ts"
24+
"postinstall": "patch-package",
25+
"knip": "knip --config='knip.json'",
26+
"clean": "rm -rf dist node_modules",
27+
"test:typecheck": "vitest --typecheck.only",
28+
"typedoc": "deno run --allow-all npm:typedoc@latest --out .docs ./src/mod.ts",
29+
"check-package": "deno run --allow-all npm:publint --strict && deno run --allow-all npm:@arethetypeswrong/cli@latest --pack --ignore-rules 'cjs-resolves-to-esm'"
3030
},
3131
"dependencies": {
32-
"@scure/base": "^1.1.9",
33-
"neverthrow": "^8.1.1",
34-
"ofetch": "^1.4.1",
35-
"patch-package": "^8.0.0",
36-
"@aptos-labs/ts-sdk": "^1.31.0",
32+
"@aptos-labs/ts-sdk": "^1.33.0",
3733
"@cosmjs/amino": "^0.32.4",
3834
"@cosmjs/cosmwasm-stargate": "0.32.4",
3935
"@cosmjs/proto-signing": "^0.32.4",
4036
"@cosmjs/stargate": "0.32.4",
4137
"@cosmjs/tendermint-rpc": "^0.32.4",
42-
"viem": "^2.21.43"
38+
"@scure/base": "^1.1.9",
39+
"neverthrow": "^8.1.1",
40+
"ofetch": "^1.4.1",
41+
"ox": "^0.2.2",
42+
"patch-package": "^8.0.0",
43+
"viem": "^2.21.48"
4344
},
4445
"devDependencies": {
4546
"@total-typescript/ts-reset": "^0.6.1",
4647
"@types/bun": "^1.1.13",
47-
"@types/node": "^22.9.0",
48+
"@types/node": "^22.9.1",
4849
"consola": "^3.2.3",
4950
"cosmjs-types": "^0.9.0",
5051
"jsr": "^0.13.2",
51-
"knip": "^5.36.3",
52+
"knip": "^5.37.1",
5253
"tsup": "^8.3.5",
5354
"tsx": "^4.19.2",
5455
"typescript": "^5.6.3",
55-
"vite-tsconfig-paths": "^5.1.0",
56-
"vitest": "^2.1.4"
56+
"vite-tsconfig-paths": "^5.1.3",
57+
"vitest": "^2.1.5"
5758
},
5859
"repository": {
5960
"type": "git",

typescript-sdk/playground/aptos-to-aptos.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bun
2-
import "#patch.ts"
2+
import "scripts/patch"
33
import { parseArgs } from "node:util"
44
import { consola } from "scripts/logger"
55
import { raise } from "#utilities/index.ts"

typescript-sdk/playground/aptos-to-union.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bun
2-
import "#patch.ts"
2+
import "scripts/patch"
33
import { parseArgs } from "node:util"
44
import { consola } from "scripts/logger"
55
import { raise } from "#utilities/index.ts"

typescript-sdk/playground/arbitrum-to-union.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bun
2-
import "#patch.ts"
2+
import "scripts/patch"
33
import { parseArgs } from "node:util"
44
import { fallback, http } from "viem"
55
import { consola } from "scripts/logger"

typescript-sdk/playground/stride-to-union.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bun
2-
import "#patch.ts"
2+
import "scripts/patch"
33
import { http } from "viem"
44
import { parseArgs } from "node:util"
55
import { consola } from "scripts/logger"

typescript-sdk/playground/union-to-sepolia.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bun
2-
import "#patch.ts"
2+
import "scripts/patch.ts"
33
import { http } from "viem"
44
import { sepolia } from "viem/chains"
55
import { parseArgs } from "node:util"

typescript-sdk/playground/union-to-union.ts

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const cosmosAccount = await DirectSecp256k1Wallet.fromKey(
2626
"union"
2727
)
2828

29+
const [account] = await cosmosAccount.getAccounts()
30+
if (!account) raise("no account found")
31+
2932
try {
3033
const client = createUnionClient({
3134
account: cosmosAccount,
File renamed without changes.

typescript-sdk/src/aptos/client.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ import {
33
aptosTransferSimulate,
44
aptosSameChainTransfer,
55
transferAssetFromAptos,
6-
type AptosTransferParams,
76
waitForTransactionReceipt,
87
type AptosPublicAccountInfo
98
} from "./transfer.ts"
109
import { err, type Result } from "neverthrow"
1110
import { bech32AddressToHex } from "../convert.ts"
12-
import { cosmosChainId } from "../client/cosmos.ts"
11+
import { cosmosChainId } from "../cosmos/client.ts"
1312
import type { TransferAssetsParameters } from "../types.ts"
1413
import { Aptos, Network, AptosConfig } from "@aptos-labs/ts-sdk"
1514
import { createPfmMemo, getHubbleChainDetails } from "../pfm.ts"
1615
import { createClient, fallback, type HttpTransport } from "viem"
1716
import type { AptosBrowserWallet, AuthAccess } from "./wallet.ts"
1817

19-
export type { AptosAccount, AptosBrowserWallet, AptosTransferParams, AptosPublicAccountInfo }
18+
export type { AptosAccount, AptosBrowserWallet }
2019

2120
export const aptosChainId = ["2"] as const
2221
export type AptosChainId = `${(typeof aptosChainId)[number]}`

typescript-sdk/src/aptos/transfer.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import {
1111
type PendingTransactionResponse,
1212
type InputGenerateTransactionPayloadData
1313
} from "@aptos-labs/ts-sdk"
14+
import type { Prettify } from "../types.ts"
1415
import { err, ok, type Result, ResultAsync } from "neverthrow"
1516
import { isValidBech32Address } from "../utilities/address.ts"
1617
import type { AptosBrowserWallet, AuthAccess } from "./wallet.ts"
1718
import { bech32AddressToHex, bech32ToBytes, hexToBytes } from "../convert.ts"
1819

19-
export type { AptosAccount, AptosTransferParams, AptosPublicAccountInfo }
20+
export type { AptosAccount, AptosPublicAccountInfo }
2021

2122
type AptosPublicAccountInfo = { address: string; publicKey: string }
2223

@@ -32,10 +33,12 @@ type AptosTransferBaseParams = {
3233
signer?: AptosAccount | AptosBrowserWallet
3334
}
3435

35-
type AptosTransferParams = AptosTransferBaseParams & {
36-
sourceChannel: string
37-
relayContractAddress: string
38-
}
36+
type AptosTransferParams = Prettify<
37+
AptosTransferBaseParams & {
38+
sourceChannel: string
39+
relayContractAddress: string
40+
}
41+
>
3942

4043
export const waitForTransactionReceipt: (args: { aptos: Aptos; hash: string }) => ResultAsync<
4144
string,
@@ -67,7 +70,7 @@ export const buildSimpleTransaction: (args: {
6770
error => new Error(`Build simple transaction failed`, { cause: error })
6871
)
6972

70-
export const submitSimpleTransaction: (args: {
73+
const submitSimpleTransaction: (args: {
7174
aptos: Aptos
7275
transaction: AnyRawTransaction
7376
accountAuthenticator: AccountAuthenticator
@@ -80,7 +83,7 @@ export const submitSimpleTransaction: (args: {
8083
error => new Error(`Submit simple transaction failed`, { cause: error })
8184
)
8285

83-
export const simulateSimpleTransaction: (args: {
86+
const simulateSimpleTransaction: (args: {
8487
aptos: Aptos
8588
signerPublicKey: PublicKey
8689
transaction: AnyRawTransaction

typescript-sdk/src/convert.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isHex } from "viem"
21
import { raise } from "./utilities/index.ts"
32
import { bech32, hex, bytes } from "@scure/base"
43
import type { Bech32Address, HexAddress } from "./types.ts"
@@ -13,9 +12,8 @@ import { isValidBech32Address } from "./utilities/address.ts"
1312
*/
1413
export function bech32AddressToHex({ address }: { address: string }): HexAddress {
1514
if (!isValidBech32Address(address)) raise(`Invalid bech32 address: ${address}`)
16-
const { words } = bech32.decode(address)
17-
const byteArray = bech32.fromWords(words)
18-
return `0x${bytesToHex(byteArray)}`
15+
const { bytes } = bech32.decodeToBytes(address)
16+
return `0x${bytesToHex(bytes)}`
1917
}
2018

2119
/**
@@ -32,7 +30,6 @@ export function hexAddressToBech32({
3230
address,
3331
bech32Prefix
3432
}: { address: HexAddress; bech32Prefix: string }): Bech32Address {
35-
if (!isHex(address)) raise("Invalid hex address")
3633
const words = bech32.toWords(hexToBytes(address))
3734
return bech32.encode(bech32Prefix, words, false)
3835
}
@@ -84,7 +81,9 @@ export function bech32ToBytes(bech32Address: string): Uint8Array {
8481
* bytesToHex(new Uint8Array([1, 2, 3]))
8582
* ```
8683
*/
87-
export const bytesToHex = (bytes: Uint8Array): string => hex.encode(bytes)
84+
export function bytesToHex(bytes: Uint8Array): string {
85+
return hex.encode(bytes)
86+
}
8887

8988
/**
9089
* convert a hex string to a byte array

typescript-sdk/src/client/cosmos.ts typescript-sdk/src/cosmos/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
cosmosSameChainTransfer,
66
cosmwasmTransferSimulate,
77
cosmosSameChainTransferSimulate
8-
} from "../transfer/cosmos.ts"
8+
} from "./transfer.ts"
99
import { err, type Result } from "neverthrow"
1010
import { timestamp } from "../utilities/index.ts"
1111
import { bech32AddressToHex } from "../convert.ts"

0 commit comments

Comments
 (0)