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
52 changes: 50 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Tutorial code for https://docs.dash.org/platform",
"main": "connect.mjs",
"scripts": {
"fmt": "npx prettier@3.8.1 --write '**/*.{js,mjs}'",
"lint": "npx -p typescript@4 tsc",
"fmt": "prettier --write '**/*.{js,mjs}'",
"lint": "tsc",
"test": "node --test --test-timeout=120000 test/read-only.test.mjs",
"test:read-only": "node --test --test-timeout=120000 test/read-only.test.mjs",
"test:read-write": "node --test --test-timeout=300000 --test-concurrency=1 test/read-write.test.mjs",
Expand All @@ -31,6 +31,8 @@
"@types/node": "25.5.0",
"chai": "6.2.2",
"eslint": "8.45.0",
"mocha": "11.7.5"
"mocha": "11.7.5",
"prettier": "3.8.1",
"typescript": "4.9.5"
}
}
44 changes: 42 additions & 2 deletions setupDashClient-core.d.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import type {
DataContract,
EvoSDK,
Identity,
IdentityPublicKey,
IdentitySigner,
PlatformAddress,
PlatformAddressInfo,
PlatformAddressSigner,
} from "@dashevo/evo-sdk";

interface AddressEntry {
address: PlatformAddress;
bech32m: string;
privateKeyWif: string;
path: string;
}

interface ConnectedDocumentLike {
revision?: bigint | number | string;
toJSON?: () => Record<string, unknown>;
Expand All @@ -25,7 +36,7 @@ interface ConnectedDocumentTokenPaymentInfo {
| 2;
}

interface ConnectedDashClientLike {
export interface ConnectedDashClientLike {
contracts: {
fetch(contractId: string): Promise<{
toJSON?: () => Record<string, unknown>;
Expand Down Expand Up @@ -148,6 +159,12 @@ export declare class IdentityKeyManager {
network?: string;
identityIndex?: number;
}): Promise<IdentityKeyManager>;
static createForNewIdentity(opts: {
sdk: ConnectedDashClientLike;
mnemonic: string;
network?: string;
identityIndex?: number;
}): Promise<IdentityKeyManager>;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
readonly identityId: string | null | undefined;
getAuth(): Promise<{
identity: Identity;
Expand All @@ -161,6 +178,29 @@ export declare class IdentityKeyManager {
}>;
}

export declare class AddressKeyManager {
static create(opts: {
sdk: ConnectedDashClientLike;
mnemonic: string;
network?: string;
count?: number;
}): Promise<AddressKeyManager>;
readonly addresses: AddressEntry[];
readonly primaryAddress: AddressEntry;
getSigner(): PlatformAddressSigner;
getFullSigner(): PlatformAddressSigner;
getInfo(): Promise<PlatformAddressInfo | undefined>;
getInfoAt(index: number): Promise<PlatformAddressInfo | undefined>;
}

export declare const KEY_SPECS: readonly unknown[];

export declare function dip13KeyPath(
network: string,
identityIndex: number,
keyIndex: number,
): Promise<string>;

export declare function createClient(
network?: string,
): Promise<ConnectedDashClientLike>;
): Promise<ConnectedDashClientLike & EvoSDK>;
11 changes: 11 additions & 0 deletions view-wallet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ try {
const { bech32m, path } = addressKeyManager.primaryAddress;

let identityId = 'No identity found for this mnemonic';
let balance = null;
try {
const keyManager = await IdentityKeyManager.create({
sdk,
mnemonic,
network,
});
identityId = keyManager.identityId;
const identity = await sdk.identities.fetch(identityId);
balance = identity.balance;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
} catch (e) {
if (!e.message?.includes('No identity found for the given mnemonic'))
throw e;
Expand All @@ -43,6 +46,14 @@ try {
`https://bridge.thepasta.org/?address=${bech32m}`,
);
console.log('Identity ID: ', identityId);
if (balance !== null) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
// 1000 credits = 1 duff, 100_000_000 duffs = 1 Dash
const dash = Number(balance) / 1e11;
console.log(
'Identity balance:',
`${balance} credits (${dash.toFixed(8)} DASH)`,
);
}
} catch (e) {
console.error('Something went wrong:\n', e.message);
}