@block52/poker-vm-sdk 1.1.11 → 1.1.12

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 CHANGED
@@ -46461,6 +46461,37 @@ declare class SigningCosmosClient extends CosmosClient {
46461
46461
  * Get the current wallet
46462
46462
  */
46463
46463
  getWallet(): DirectSecp256k1HdWallet | undefined;
46464
+ /**
46465
+ * Register an NFT as the player's avatar
46466
+ *
46467
+ * This broadcasts a MsgRegisterNftAvatar transaction containing:
46468
+ * - The ETH address that owns the NFT
46469
+ * - The NFT contract address and token ID
46470
+ * - An ETH signature proving the ETH address owner authorizes this cosmos address
46471
+ * to use the NFT as their avatar
46472
+ *
46473
+ * The validator verifies the ETH signature via ecrecover and, if valid,
46474
+ * stores the mapping on-chain: cosmosAddress → (contractAddress, tokenId)
46475
+ *
46476
+ * @param ethAddress - The ETH address that owns the NFT
46477
+ * @param contractAddress - The NFT contract address on Ethereum/Base
46478
+ * @param tokenId - The NFT token ID
46479
+ * @param ethSignature - EIP-191 signature proving ETH address ownership
46480
+ * @returns Transaction hash
46481
+ */
46482
+ registerNftAvatar(ethAddress: string, contractAddress: string, tokenId: string, ethSignature: string): Promise<string>;
46483
+ /**
46484
+ * Query a registered NFT avatar for a cosmos address
46485
+ *
46486
+ * @param cosmosAddress - The cosmos address to look up
46487
+ * @returns The NFT avatar data if registered, or null if not found
46488
+ */
46489
+ queryNftAvatar(cosmosAddress: string): Promise<{
46490
+ cosmosAddress: string;
46491
+ ethAddress: string;
46492
+ contractAddress: string;
46493
+ tokenId: string;
46494
+ } | null>;
46464
46495
  }
46465
46496
  /**
46466
46497
  * Create a signing client from a mnemonic
package/dist/index.esm.js CHANGED
@@ -4167,6 +4167,119 @@ const MsgDeleteGame = {
4167
4167
  return message;
4168
4168
  },
4169
4169
  };
4170
+ function createBaseMsgRegisterNftAvatar() {
4171
+ return { creator: "", ethAddress: "", contractAddress: "", tokenId: "", ethSignature: "" };
4172
+ }
4173
+ const MsgRegisterNftAvatar = {
4174
+ encode(message, writer = new BinaryWriter()) {
4175
+ if (message.creator !== "") {
4176
+ writer.uint32(10).string(message.creator);
4177
+ }
4178
+ if (message.ethAddress !== "") {
4179
+ writer.uint32(18).string(message.ethAddress);
4180
+ }
4181
+ if (message.contractAddress !== "") {
4182
+ writer.uint32(26).string(message.contractAddress);
4183
+ }
4184
+ if (message.tokenId !== "") {
4185
+ writer.uint32(34).string(message.tokenId);
4186
+ }
4187
+ if (message.ethSignature !== "") {
4188
+ writer.uint32(42).string(message.ethSignature);
4189
+ }
4190
+ return writer;
4191
+ },
4192
+ decode(input, length) {
4193
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
4194
+ const end = length === undefined ? reader.len : reader.pos + length;
4195
+ const message = createBaseMsgRegisterNftAvatar();
4196
+ while (reader.pos < end) {
4197
+ const tag = reader.uint32();
4198
+ switch (tag >>> 3) {
4199
+ case 1: {
4200
+ if (tag !== 10) {
4201
+ break;
4202
+ }
4203
+ message.creator = reader.string();
4204
+ continue;
4205
+ }
4206
+ case 2: {
4207
+ if (tag !== 18) {
4208
+ break;
4209
+ }
4210
+ message.ethAddress = reader.string();
4211
+ continue;
4212
+ }
4213
+ case 3: {
4214
+ if (tag !== 26) {
4215
+ break;
4216
+ }
4217
+ message.contractAddress = reader.string();
4218
+ continue;
4219
+ }
4220
+ case 4: {
4221
+ if (tag !== 34) {
4222
+ break;
4223
+ }
4224
+ message.tokenId = reader.string();
4225
+ continue;
4226
+ }
4227
+ case 5: {
4228
+ if (tag !== 42) {
4229
+ break;
4230
+ }
4231
+ message.ethSignature = reader.string();
4232
+ continue;
4233
+ }
4234
+ }
4235
+ if ((tag & 7) === 4 || tag === 0) {
4236
+ break;
4237
+ }
4238
+ reader.skip(tag & 7);
4239
+ }
4240
+ return message;
4241
+ },
4242
+ fromJSON(object) {
4243
+ return {
4244
+ creator: isSet$2b(object.creator) ? globalThis.String(object.creator) : "",
4245
+ ethAddress: isSet$2b(object.ethAddress) ? globalThis.String(object.ethAddress) : "",
4246
+ contractAddress: isSet$2b(object.contractAddress) ? globalThis.String(object.contractAddress) : "",
4247
+ tokenId: isSet$2b(object.tokenId) ? globalThis.String(object.tokenId) : "",
4248
+ ethSignature: isSet$2b(object.ethSignature) ? globalThis.String(object.ethSignature) : "",
4249
+ };
4250
+ },
4251
+ toJSON(message) {
4252
+ const obj = {};
4253
+ if (message.creator !== "") {
4254
+ obj.creator = message.creator;
4255
+ }
4256
+ if (message.ethAddress !== "") {
4257
+ obj.ethAddress = message.ethAddress;
4258
+ }
4259
+ if (message.contractAddress !== "") {
4260
+ obj.contractAddress = message.contractAddress;
4261
+ }
4262
+ if (message.tokenId !== "") {
4263
+ obj.tokenId = message.tokenId;
4264
+ }
4265
+ if (message.ethSignature !== "") {
4266
+ obj.ethSignature = message.ethSignature;
4267
+ }
4268
+ return obj;
4269
+ },
4270
+ create(base) {
4271
+ return MsgRegisterNftAvatar.fromPartial(base ?? {});
4272
+ },
4273
+ fromPartial(object) {
4274
+ const message = createBaseMsgRegisterNftAvatar();
4275
+ message.creator = object.creator ?? "";
4276
+ message.ethAddress = object.ethAddress ?? "";
4277
+ message.contractAddress = object.contractAddress ?? "";
4278
+ message.tokenId = object.tokenId ?? "";
4279
+ message.ethSignature = object.ethSignature ?? "";
4280
+ return message;
4281
+ },
4282
+ };
4170
4283
  function isSet$2b(value) {
4171
4284
  return value !== null && value !== undefined;
4172
4285
  }
@@ -4187,6 +4300,7 @@ const msgTypes$u = [
4187
4300
  ["/pokerchain.poker.v1.MsgUpdateEthBlockHeight", MsgUpdateEthBlockHeight],
4188
4301
  ["/pokerchain.poker.v1.MsgTopUp", MsgTopUp],
4189
4302
  ["/pokerchain.poker.v1.MsgDeleteGame", MsgDeleteGame],
4303
+ ["/pokerchain.poker.v1.MsgRegisterNftAvatar", MsgRegisterNftAvatar],
4190
4304
  ];
4191
4305
 
4192
4306
  /**
@@ -58148,6 +58262,93 @@ class SigningCosmosClient extends CosmosClient {
58148
58262
  getWallet() {
58149
58263
  return this.wallet;
58150
58264
  }
58265
+ /**
58266
+ * Register an NFT as the player's avatar
58267
+ *
58268
+ * This broadcasts a MsgRegisterNftAvatar transaction containing:
58269
+ * - The ETH address that owns the NFT
58270
+ * - The NFT contract address and token ID
58271
+ * - An ETH signature proving the ETH address owner authorizes this cosmos address
58272
+ * to use the NFT as their avatar
58273
+ *
58274
+ * The validator verifies the ETH signature via ecrecover and, if valid,
58275
+ * stores the mapping on-chain: cosmosAddress → (contractAddress, tokenId)
58276
+ *
58277
+ * @param ethAddress - The ETH address that owns the NFT
58278
+ * @param contractAddress - The NFT contract address on Ethereum/Base
58279
+ * @param tokenId - The NFT token ID
58280
+ * @param ethSignature - EIP-191 signature proving ETH address ownership
58281
+ * @returns Transaction hash
58282
+ */
58283
+ async registerNftAvatar(ethAddress, contractAddress, tokenId, ethSignature) {
58284
+ await this.initializeSigningClient();
58285
+ if (!this.signingClient || !this.wallet) {
58286
+ throw new Error("Signing client not initialized");
58287
+ }
58288
+ const [account] = await this.wallet.getAccounts();
58289
+ const creator = account.address;
58290
+ // Create the message object
58291
+ const msgRegisterNftAvatar = {
58292
+ creator,
58293
+ ethAddress,
58294
+ contractAddress,
58295
+ tokenId,
58296
+ ethSignature
58297
+ };
58298
+ // Create the transaction message
58299
+ const msg = {
58300
+ typeUrl: "/pokerchain.poker.v1.MsgRegisterNftAvatar",
58301
+ value: msgRegisterNftAvatar
58302
+ };
58303
+ const fee = gaslessFee();
58304
+ const memo = "Register NFT avatar via SDK";
58305
+ console.log("🖼️ Registering NFT avatar:", {
58306
+ creator,
58307
+ ethAddress,
58308
+ contractAddress,
58309
+ tokenId: tokenId.substring(0, 20) + (tokenId.length > 20 ? "..." : "")
58310
+ });
58311
+ try {
58312
+ const result = await this.signingClient.signAndBroadcast(creator, [msg], fee, memo);
58313
+ console.log("✅ NFT avatar registration successful:", result.transactionHash);
58314
+ return result.transactionHash;
58315
+ }
58316
+ catch (error) {
58317
+ console.error("❌ NFT avatar registration failed:", error);
58318
+ throw error;
58319
+ }
58320
+ }
58321
+ /**
58322
+ * Query a registered NFT avatar for a cosmos address
58323
+ *
58324
+ * @param cosmosAddress - The cosmos address to look up
58325
+ * @returns The NFT avatar data if registered, or null if not found
58326
+ */
58327
+ async queryNftAvatar(cosmosAddress) {
58328
+ try {
58329
+ const response = await fetch(`${this.config.restEndpoint}/pokerchain/poker/nft_avatar/${encodeURIComponent(cosmosAddress)}`);
58330
+ if (!response.ok) {
58331
+ if (response.status === 404) {
58332
+ return null;
58333
+ }
58334
+ throw new Error(`Failed to query NFT avatar: ${response.statusText}`);
58335
+ }
58336
+ const data = await response.json();
58337
+ if (!data.contract_address || !data.token_id) {
58338
+ return null;
58339
+ }
58340
+ return {
58341
+ cosmosAddress: data.cosmos_address || cosmosAddress,
58342
+ ethAddress: data.eth_address || "",
58343
+ contractAddress: data.contract_address,
58344
+ tokenId: data.token_id
58345
+ };
58346
+ }
58347
+ catch (error) {
58348
+ console.error("❌ queryNftAvatar() failed:", error);
58349
+ throw error;
58350
+ }
58351
+ }
58151
58352
  }
58152
58353
  /**
58153
58354
  * Create a signing client with a wallet