decane-connect-kit 2.24.0 → 2.24.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.cjs CHANGED
@@ -3232,6 +3232,8 @@ function loginWithKingsChatPopup(opts) {
3232
3232
 
3233
3233
  // src/social/signers/evm.ts
3234
3234
  var import_ethers2 = require("ethers");
3235
+ init_errors();
3236
+ var DECODE = (bytes) => new TextDecoder().decode(bytes);
3235
3237
  async function signEvmTransaction(tee, chain, tx, jwt) {
3236
3238
  const resolved = await (0, import_ethers2.resolveProperties)(tx);
3237
3239
  const unsigned = import_ethers2.Transaction.from(resolved).unsignedSerialized;
@@ -3240,7 +3242,44 @@ async function signEvmTransaction(tee, chain, tx, jwt) {
3240
3242
  return tee.sign({ chain, kind: "transaction", payload, txHash }, jwt);
3241
3243
  }
3242
3244
  async function signEvmMessage(tee, chain, message, jwt) {
3243
- return tee.sign({ chain, kind: "message", payload: message }, jwt);
3245
+ return tee.sign({ chain, kind: "message", payload: messageAsString(message) }, jwt);
3246
+ }
3247
+ function messageAsString(message) {
3248
+ if (typeof message === "string") return message;
3249
+ if (!isValidUtf8(message)) {
3250
+ throw new CallSequenceError(
3251
+ "signMessage: the message bytes are not valid UTF-8. The signer hashes text; pass a string, or UTF-8 bytes."
3252
+ );
3253
+ }
3254
+ return DECODE(message);
3255
+ }
3256
+ function isValidUtf8(b) {
3257
+ let i = 0;
3258
+ while (i < b.length) {
3259
+ const c = b[i];
3260
+ let n = 0;
3261
+ if (c < 128) n = 0;
3262
+ else if (c >= 194 && c <= 223) n = 1;
3263
+ else if (c >= 224 && c <= 239) n = 2;
3264
+ else if (c >= 240 && c <= 244) n = 3;
3265
+ else return false;
3266
+ for (let k = 1; k <= n; k++) {
3267
+ const t = b[i + k];
3268
+ if (t === void 0 || (t & 192) !== 128) return false;
3269
+ }
3270
+ if (n === 2) {
3271
+ const c1 = b[i + 1];
3272
+ if (c === 224 && c1 < 160) return false;
3273
+ if (c === 237 && c1 >= 160) return false;
3274
+ }
3275
+ if (n === 3) {
3276
+ const c1 = b[i + 1];
3277
+ if (c === 240 && c1 < 144) return false;
3278
+ if (c === 244 && c1 >= 144) return false;
3279
+ }
3280
+ i += n + 1;
3281
+ }
3282
+ return true;
3244
3283
  }
3245
3284
  async function signEvmAuthorization(tee, chainId, address, nonce, jwt) {
3246
3285
  const serialized = await tee.sign(
@@ -4884,8 +4923,7 @@ async function createDecaneConnect(config) {
4884
4923
  return bufferToB64u(sig);
4885
4924
  }
4886
4925
  if (req.chain.startsWith("tron:")) {
4887
- const msg = typeof req.message === "string" ? req.message : new TextDecoder().decode(req.message);
4888
- return tee.sign({ chain: req.chain, kind: "message", payload: msg }, auth?.jwt);
4926
+ return tee.sign({ chain: req.chain, kind: "message", payload: messageAsString(req.message) }, auth?.jwt);
4889
4927
  }
4890
4928
  throw new CallSequenceError(`Unsupported chain: ${req.chain}`);
4891
4929
  },