@block52/poker-vm-sdk 1.2.17 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +18 -1
- package/dist/index.esm.js +79 -26
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +77 -24
- package/dist/index.js.map +1 -1
- package/dist/signingClient.d.ts +18 -1
- package/dist/signingClient.d.ts.map +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -46598,7 +46598,7 @@ declare class SigningCosmosClient extends CosmosClient {
|
|
|
46598
46598
|
* Requires the player account to EXIST on-chain (funded). Same gasless
|
|
46599
46599
|
* fee + msg shape as {@link performActionSync}.
|
|
46600
46600
|
*/
|
|
46601
|
-
signPerformAction(gameId: string, action: string, amount?: bigint, data?: string,
|
|
46601
|
+
signPerformAction(gameId: string, action: string, amount?: bigint, data?: string, _signerData?: SignerData): Promise<{
|
|
46602
46602
|
base64: string;
|
|
46603
46603
|
sequence: number;
|
|
46604
46604
|
accountNumber: number;
|
|
@@ -46616,6 +46616,23 @@ declare class SigningCosmosClient extends CosmosClient {
|
|
|
46616
46616
|
* helpers below share with signPerformAction's gateway-settlement pattern.
|
|
46617
46617
|
*/
|
|
46618
46618
|
private signMsgOnly;
|
|
46619
|
+
/**
|
|
46620
|
+
* Sign a single cosmos message as an UNORDERED transaction (SDK 0.53): the
|
|
46621
|
+
* TxBody carries `unordered: true` + a `timeout_timestamp` and NO account
|
|
46622
|
+
* sequence (sequence MUST be 0). The chain admits it regardless of order and
|
|
46623
|
+
* dedups replay on (signer, timeout) — so settlement txs no longer carry a
|
|
46624
|
+
* client-guessed sequence and can never cascade (poker-vm#247, replaces the
|
|
46625
|
+
* sequence-tracking that caused #2413).
|
|
46626
|
+
*
|
|
46627
|
+
* Hand-built because CosmJS 0.32's TxBody proto predates the unordered
|
|
46628
|
+
* fields; we use the SDK's own cosmos.tx proto (which has them) for the body
|
|
46629
|
+
* and CosmJS only for AuthInfo + the direct signature.
|
|
46630
|
+
*
|
|
46631
|
+
* @param ttlSeconds - how far ahead the timeout_timestamp is set. Must be
|
|
46632
|
+
* within the chain's max unordered TTL (SDK default 10m). Also bounds how
|
|
46633
|
+
* long a replay of this exact tx is rejected.
|
|
46634
|
+
*/
|
|
46635
|
+
private signUnordered;
|
|
46619
46636
|
/**
|
|
46620
46637
|
* Sign-only MsgJoinGame: builds and signs the player's buy-in tx WITHOUT
|
|
46621
46638
|
* broadcasting, returning the base64 TxRaw for the gateway to relay
|
package/dist/index.esm.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Registry, DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
|
|
1
|
+
import { Registry, DirectSecp256k1HdWallet, encodePubkey, makeAuthInfoBytes, makeSignDoc } from '@cosmjs/proto-signing';
|
|
2
2
|
import { SigningStargateClient, GasPrice } from '@cosmjs/stargate';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import { stringToPath } from '@cosmjs/crypto';
|
|
5
5
|
import { createHash } from 'crypto';
|
|
6
|
-
import { toBase64 } from '@cosmjs/encoding';
|
|
6
|
+
import { toBase64, fromBase64 } from '@cosmjs/encoding';
|
|
7
|
+
import { encodeSecp256k1Pubkey } from '@cosmjs/amino';
|
|
7
8
|
|
|
8
9
|
/// <reference path="./types.d.ts" />
|
|
9
10
|
const defaultFee$q = {
|
|
@@ -60938,6 +60939,10 @@ var txExports = requireTx();
|
|
|
60938
60939
|
* Default gas limit for all transactions
|
|
60939
60940
|
*/
|
|
60940
60941
|
const DEFAULT_GAS_LIMIT = 1000000;
|
|
60942
|
+
// Registry with the poker message types, used to pack a Msg into an Any when
|
|
60943
|
+
// hand-building an unordered TxBody (signUnordered). Module-level so it's built
|
|
60944
|
+
// once and shared with the stargate client's registry semantics.
|
|
60945
|
+
const pokerRegistry = new Registry(msgTypes$u);
|
|
60941
60946
|
/**
|
|
60942
60947
|
* Create a gasless fee object with specified gas limit
|
|
60943
60948
|
* Chain is configured with min-gas-prices = "0stake" so no fee tokens required
|
|
@@ -61428,36 +61433,31 @@ class SigningCosmosClient extends CosmosClient {
|
|
|
61428
61433
|
* Requires the player account to EXIST on-chain (funded). Same gasless
|
|
61429
61434
|
* fee + msg shape as {@link performActionSync}.
|
|
61430
61435
|
*/
|
|
61431
|
-
async signPerformAction(gameId, action, amount = 0n, data,
|
|
61432
|
-
|
|
61433
|
-
|
|
61434
|
-
|
|
61436
|
+
async signPerformAction(gameId, action, amount = 0n, data, _signerData) {
|
|
61437
|
+
// Unordered signing needs only the wallet + REST getAccount — no RPC
|
|
61438
|
+
// stargate client, so this works without a reachable RPC endpoint.
|
|
61439
|
+
if (!this.wallet) {
|
|
61440
|
+
throw new Error("No wallet provided for signing");
|
|
61435
61441
|
}
|
|
61436
61442
|
const [account] = await this.wallet.getAccounts();
|
|
61437
61443
|
const player = account.address;
|
|
61438
|
-
const msgPerformAction = {
|
|
61439
|
-
player,
|
|
61440
|
-
gameId,
|
|
61441
|
-
action,
|
|
61442
|
-
amount: Long.fromString(amount.toString(), true),
|
|
61443
|
-
data: data || ""
|
|
61444
|
-
};
|
|
61445
61444
|
const msg = {
|
|
61446
61445
|
typeUrl: "/pokerchain.poker.v1.MsgPerformAction",
|
|
61447
|
-
value:
|
|
61446
|
+
value: {
|
|
61447
|
+
player,
|
|
61448
|
+
gameId,
|
|
61449
|
+
action,
|
|
61450
|
+
amount: Long.fromString(amount.toString(), true),
|
|
61451
|
+
data: data || ""
|
|
61452
|
+
}
|
|
61448
61453
|
};
|
|
61449
|
-
|
|
61450
|
-
|
|
61451
|
-
|
|
61452
|
-
|
|
61453
|
-
|
|
61454
|
-
|
|
61455
|
-
|
|
61456
|
-
};
|
|
61457
|
-
}
|
|
61458
|
-
const txRaw = await this.signingClient.sign(player, [msg], gaslessFee(), `Poker action (relay): ${action}`, explicit);
|
|
61459
|
-
const base64 = toBase64(txExports.TxRaw.encode(txRaw).finish());
|
|
61460
|
-
return { base64, sequence: explicit.sequence, accountNumber: explicit.accountNumber };
|
|
61454
|
+
// Settlement txs are UNORDERED (#247): no account sequence, so optimistic
|
|
61455
|
+
// play can never desync the chain sequence (the #2413 cascade). The
|
|
61456
|
+
// `signerData`/sequence arg is retained for signature compatibility but
|
|
61457
|
+
// ignored — unordered txs carry sequence 0.
|
|
61458
|
+
const { base64, accountNumber } = await this.signUnordered(msg);
|
|
61459
|
+
// sequence is meaningless for unordered txs; return 0 for shape compat.
|
|
61460
|
+
return { base64, sequence: 0, accountNumber };
|
|
61461
61461
|
}
|
|
61462
61462
|
/**
|
|
61463
61463
|
* Resolves the signer data (account number + sequence + chain id) for a
|
|
@@ -61493,6 +61493,59 @@ class SigningCosmosClient extends CosmosClient {
|
|
|
61493
61493
|
const base64 = toBase64(txExports.TxRaw.encode(txRaw).finish());
|
|
61494
61494
|
return { base64, sequence: explicit.sequence, accountNumber: explicit.accountNumber };
|
|
61495
61495
|
}
|
|
61496
|
+
/**
|
|
61497
|
+
* Sign a single cosmos message as an UNORDERED transaction (SDK 0.53): the
|
|
61498
|
+
* TxBody carries `unordered: true` + a `timeout_timestamp` and NO account
|
|
61499
|
+
* sequence (sequence MUST be 0). The chain admits it regardless of order and
|
|
61500
|
+
* dedups replay on (signer, timeout) — so settlement txs no longer carry a
|
|
61501
|
+
* client-guessed sequence and can never cascade (poker-vm#247, replaces the
|
|
61502
|
+
* sequence-tracking that caused #2413).
|
|
61503
|
+
*
|
|
61504
|
+
* Hand-built because CosmJS 0.32's TxBody proto predates the unordered
|
|
61505
|
+
* fields; we use the SDK's own cosmos.tx proto (which has them) for the body
|
|
61506
|
+
* and CosmJS only for AuthInfo + the direct signature.
|
|
61507
|
+
*
|
|
61508
|
+
* @param ttlSeconds - how far ahead the timeout_timestamp is set. Must be
|
|
61509
|
+
* within the chain's max unordered TTL (SDK default 10m). Also bounds how
|
|
61510
|
+
* long a replay of this exact tx is rejected.
|
|
61511
|
+
*/
|
|
61512
|
+
async signUnordered(msg, ttlSeconds = 120) {
|
|
61513
|
+
// No RPC signing client needed: unordered signing is a direct signature
|
|
61514
|
+
// over locally-built bytes. Only the wallet (for signDirect) and a REST
|
|
61515
|
+
// getAccount (for account_number) are required.
|
|
61516
|
+
if (!this.wallet) {
|
|
61517
|
+
throw new Error("No wallet provided for signing");
|
|
61518
|
+
}
|
|
61519
|
+
const [account] = await this.wallet.getAccounts();
|
|
61520
|
+
const player = account.address;
|
|
61521
|
+
// account_number + chainId are still needed for the sign doc; the
|
|
61522
|
+
// SEQUENCE is not — unordered txs must sign with sequence 0.
|
|
61523
|
+
const accountInfo = await this.getAccount(player);
|
|
61524
|
+
const accountNumber = Number(accountInfo.account.account_number);
|
|
61525
|
+
const chainId = this.config.chainId;
|
|
61526
|
+
// Body with unordered=true + timeout_timestamp, messages packed as Any
|
|
61527
|
+
// via the poker registry. timeoutHeight stays 0 (we gate on timestamp).
|
|
61528
|
+
const bodyBytes = TxBody.encode(TxBody.fromPartial({
|
|
61529
|
+
messages: [pokerRegistry.encodeAsAny(msg)],
|
|
61530
|
+
memo: "",
|
|
61531
|
+
timeoutHeight: Long.UZERO,
|
|
61532
|
+
unordered: true,
|
|
61533
|
+
timeoutTimestamp: new Date(Date.now() + ttlSeconds * 1000)
|
|
61534
|
+
})).finish();
|
|
61535
|
+
// AuthInfo with sequence 0 (required for unordered). CosmJS builds this
|
|
61536
|
+
// — the pubkey/fee encoding is unchanged from an ordered tx.
|
|
61537
|
+
const pubkey = encodePubkey(encodeSecp256k1Pubkey(account.pubkey));
|
|
61538
|
+
const gas = gaslessFee();
|
|
61539
|
+
const authInfoBytes = makeAuthInfoBytes([{ pubkey, sequence: 0 }], gas.amount, Number(gas.gas), undefined, undefined);
|
|
61540
|
+
const signDoc = makeSignDoc(bodyBytes, authInfoBytes, chainId, accountNumber);
|
|
61541
|
+
const { signature, signed } = await this.wallet.signDirect(player, signDoc);
|
|
61542
|
+
const base64 = toBase64(TxRaw.encode(TxRaw.fromPartial({
|
|
61543
|
+
bodyBytes: signed.bodyBytes,
|
|
61544
|
+
authInfoBytes: signed.authInfoBytes,
|
|
61545
|
+
signatures: [fromBase64(signature.signature)]
|
|
61546
|
+
})).finish());
|
|
61547
|
+
return { base64, accountNumber };
|
|
61548
|
+
}
|
|
61496
61549
|
/**
|
|
61497
61550
|
* Sign-only MsgJoinGame: builds and signs the player's buy-in tx WITHOUT
|
|
61498
61551
|
* broadcasting, returning the base64 TxRaw for the gateway to relay
|