@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.js
CHANGED
|
@@ -6,6 +6,7 @@ var events = require('events');
|
|
|
6
6
|
var crypto = require('@cosmjs/crypto');
|
|
7
7
|
var crypto$1 = require('crypto');
|
|
8
8
|
var encoding = require('@cosmjs/encoding');
|
|
9
|
+
var amino = require('@cosmjs/amino');
|
|
9
10
|
|
|
10
11
|
/// <reference path="./types.d.ts" />
|
|
11
12
|
const defaultFee$q = {
|
|
@@ -60940,6 +60941,10 @@ var txExports = requireTx();
|
|
|
60940
60941
|
* Default gas limit for all transactions
|
|
60941
60942
|
*/
|
|
60942
60943
|
const DEFAULT_GAS_LIMIT = 1000000;
|
|
60944
|
+
// Registry with the poker message types, used to pack a Msg into an Any when
|
|
60945
|
+
// hand-building an unordered TxBody (signUnordered). Module-level so it's built
|
|
60946
|
+
// once and shared with the stargate client's registry semantics.
|
|
60947
|
+
const pokerRegistry = new protoSigning.Registry(msgTypes$u);
|
|
60943
60948
|
/**
|
|
60944
60949
|
* Create a gasless fee object with specified gas limit
|
|
60945
60950
|
* Chain is configured with min-gas-prices = "0stake" so no fee tokens required
|
|
@@ -61430,36 +61435,31 @@ class SigningCosmosClient extends CosmosClient {
|
|
|
61430
61435
|
* Requires the player account to EXIST on-chain (funded). Same gasless
|
|
61431
61436
|
* fee + msg shape as {@link performActionSync}.
|
|
61432
61437
|
*/
|
|
61433
|
-
async signPerformAction(gameId, action, amount = 0n, data,
|
|
61434
|
-
|
|
61435
|
-
|
|
61436
|
-
|
|
61438
|
+
async signPerformAction(gameId, action, amount = 0n, data, _signerData) {
|
|
61439
|
+
// Unordered signing needs only the wallet + REST getAccount — no RPC
|
|
61440
|
+
// stargate client, so this works without a reachable RPC endpoint.
|
|
61441
|
+
if (!this.wallet) {
|
|
61442
|
+
throw new Error("No wallet provided for signing");
|
|
61437
61443
|
}
|
|
61438
61444
|
const [account] = await this.wallet.getAccounts();
|
|
61439
61445
|
const player = account.address;
|
|
61440
|
-
const msgPerformAction = {
|
|
61441
|
-
player,
|
|
61442
|
-
gameId,
|
|
61443
|
-
action,
|
|
61444
|
-
amount: Long.fromString(amount.toString(), true),
|
|
61445
|
-
data: data || ""
|
|
61446
|
-
};
|
|
61447
61446
|
const msg = {
|
|
61448
61447
|
typeUrl: "/pokerchain.poker.v1.MsgPerformAction",
|
|
61449
|
-
value:
|
|
61448
|
+
value: {
|
|
61449
|
+
player,
|
|
61450
|
+
gameId,
|
|
61451
|
+
action,
|
|
61452
|
+
amount: Long.fromString(amount.toString(), true),
|
|
61453
|
+
data: data || ""
|
|
61454
|
+
}
|
|
61450
61455
|
};
|
|
61451
|
-
|
|
61452
|
-
|
|
61453
|
-
|
|
61454
|
-
|
|
61455
|
-
|
|
61456
|
-
|
|
61457
|
-
|
|
61458
|
-
};
|
|
61459
|
-
}
|
|
61460
|
-
const txRaw = await this.signingClient.sign(player, [msg], gaslessFee(), `Poker action (relay): ${action}`, explicit);
|
|
61461
|
-
const base64 = encoding.toBase64(txExports.TxRaw.encode(txRaw).finish());
|
|
61462
|
-
return { base64, sequence: explicit.sequence, accountNumber: explicit.accountNumber };
|
|
61456
|
+
// Settlement txs are UNORDERED (#247): no account sequence, so optimistic
|
|
61457
|
+
// play can never desync the chain sequence (the #2413 cascade). The
|
|
61458
|
+
// `signerData`/sequence arg is retained for signature compatibility but
|
|
61459
|
+
// ignored — unordered txs carry sequence 0.
|
|
61460
|
+
const { base64, accountNumber } = await this.signUnordered(msg);
|
|
61461
|
+
// sequence is meaningless for unordered txs; return 0 for shape compat.
|
|
61462
|
+
return { base64, sequence: 0, accountNumber };
|
|
61463
61463
|
}
|
|
61464
61464
|
/**
|
|
61465
61465
|
* Resolves the signer data (account number + sequence + chain id) for a
|
|
@@ -61495,6 +61495,59 @@ class SigningCosmosClient extends CosmosClient {
|
|
|
61495
61495
|
const base64 = encoding.toBase64(txExports.TxRaw.encode(txRaw).finish());
|
|
61496
61496
|
return { base64, sequence: explicit.sequence, accountNumber: explicit.accountNumber };
|
|
61497
61497
|
}
|
|
61498
|
+
/**
|
|
61499
|
+
* Sign a single cosmos message as an UNORDERED transaction (SDK 0.53): the
|
|
61500
|
+
* TxBody carries `unordered: true` + a `timeout_timestamp` and NO account
|
|
61501
|
+
* sequence (sequence MUST be 0). The chain admits it regardless of order and
|
|
61502
|
+
* dedups replay on (signer, timeout) — so settlement txs no longer carry a
|
|
61503
|
+
* client-guessed sequence and can never cascade (poker-vm#247, replaces the
|
|
61504
|
+
* sequence-tracking that caused #2413).
|
|
61505
|
+
*
|
|
61506
|
+
* Hand-built because CosmJS 0.32's TxBody proto predates the unordered
|
|
61507
|
+
* fields; we use the SDK's own cosmos.tx proto (which has them) for the body
|
|
61508
|
+
* and CosmJS only for AuthInfo + the direct signature.
|
|
61509
|
+
*
|
|
61510
|
+
* @param ttlSeconds - how far ahead the timeout_timestamp is set. Must be
|
|
61511
|
+
* within the chain's max unordered TTL (SDK default 10m). Also bounds how
|
|
61512
|
+
* long a replay of this exact tx is rejected.
|
|
61513
|
+
*/
|
|
61514
|
+
async signUnordered(msg, ttlSeconds = 120) {
|
|
61515
|
+
// No RPC signing client needed: unordered signing is a direct signature
|
|
61516
|
+
// over locally-built bytes. Only the wallet (for signDirect) and a REST
|
|
61517
|
+
// getAccount (for account_number) are required.
|
|
61518
|
+
if (!this.wallet) {
|
|
61519
|
+
throw new Error("No wallet provided for signing");
|
|
61520
|
+
}
|
|
61521
|
+
const [account] = await this.wallet.getAccounts();
|
|
61522
|
+
const player = account.address;
|
|
61523
|
+
// account_number + chainId are still needed for the sign doc; the
|
|
61524
|
+
// SEQUENCE is not — unordered txs must sign with sequence 0.
|
|
61525
|
+
const accountInfo = await this.getAccount(player);
|
|
61526
|
+
const accountNumber = Number(accountInfo.account.account_number);
|
|
61527
|
+
const chainId = this.config.chainId;
|
|
61528
|
+
// Body with unordered=true + timeout_timestamp, messages packed as Any
|
|
61529
|
+
// via the poker registry. timeoutHeight stays 0 (we gate on timestamp).
|
|
61530
|
+
const bodyBytes = TxBody.encode(TxBody.fromPartial({
|
|
61531
|
+
messages: [pokerRegistry.encodeAsAny(msg)],
|
|
61532
|
+
memo: "",
|
|
61533
|
+
timeoutHeight: Long.UZERO,
|
|
61534
|
+
unordered: true,
|
|
61535
|
+
timeoutTimestamp: new Date(Date.now() + ttlSeconds * 1000)
|
|
61536
|
+
})).finish();
|
|
61537
|
+
// AuthInfo with sequence 0 (required for unordered). CosmJS builds this
|
|
61538
|
+
// — the pubkey/fee encoding is unchanged from an ordered tx.
|
|
61539
|
+
const pubkey = protoSigning.encodePubkey(amino.encodeSecp256k1Pubkey(account.pubkey));
|
|
61540
|
+
const gas = gaslessFee();
|
|
61541
|
+
const authInfoBytes = protoSigning.makeAuthInfoBytes([{ pubkey, sequence: 0 }], gas.amount, Number(gas.gas), undefined, undefined);
|
|
61542
|
+
const signDoc = protoSigning.makeSignDoc(bodyBytes, authInfoBytes, chainId, accountNumber);
|
|
61543
|
+
const { signature, signed } = await this.wallet.signDirect(player, signDoc);
|
|
61544
|
+
const base64 = encoding.toBase64(TxRaw.encode(TxRaw.fromPartial({
|
|
61545
|
+
bodyBytes: signed.bodyBytes,
|
|
61546
|
+
authInfoBytes: signed.authInfoBytes,
|
|
61547
|
+
signatures: [encoding.fromBase64(signature.signature)]
|
|
61548
|
+
})).finish());
|
|
61549
|
+
return { base64, accountNumber };
|
|
61550
|
+
}
|
|
61498
61551
|
/**
|
|
61499
61552
|
* Sign-only MsgJoinGame: builds and signs the player's buy-in tx WITHOUT
|
|
61500
61553
|
* broadcasting, returning the base64 TxRaw for the gateway to relay
|