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.js CHANGED
@@ -3148,7 +3148,9 @@ function loginWithKingsChatPopup(opts) {
3148
3148
  }
3149
3149
 
3150
3150
  // src/social/signers/evm.ts
3151
+ init_errors();
3151
3152
  import { keccak256, Transaction, resolveProperties } from "ethers";
3153
+ var DECODE = (bytes) => new TextDecoder().decode(bytes);
3152
3154
  async function signEvmTransaction(tee, chain, tx, jwt) {
3153
3155
  const resolved = await resolveProperties(tx);
3154
3156
  const unsigned = Transaction.from(resolved).unsignedSerialized;
@@ -3157,7 +3159,44 @@ async function signEvmTransaction(tee, chain, tx, jwt) {
3157
3159
  return tee.sign({ chain, kind: "transaction", payload, txHash }, jwt);
3158
3160
  }
3159
3161
  async function signEvmMessage(tee, chain, message, jwt) {
3160
- return tee.sign({ chain, kind: "message", payload: message }, jwt);
3162
+ return tee.sign({ chain, kind: "message", payload: messageAsString(message) }, jwt);
3163
+ }
3164
+ function messageAsString(message) {
3165
+ if (typeof message === "string") return message;
3166
+ if (!isValidUtf8(message)) {
3167
+ throw new CallSequenceError(
3168
+ "signMessage: the message bytes are not valid UTF-8. The signer hashes text; pass a string, or UTF-8 bytes."
3169
+ );
3170
+ }
3171
+ return DECODE(message);
3172
+ }
3173
+ function isValidUtf8(b) {
3174
+ let i = 0;
3175
+ while (i < b.length) {
3176
+ const c = b[i];
3177
+ let n = 0;
3178
+ if (c < 128) n = 0;
3179
+ else if (c >= 194 && c <= 223) n = 1;
3180
+ else if (c >= 224 && c <= 239) n = 2;
3181
+ else if (c >= 240 && c <= 244) n = 3;
3182
+ else return false;
3183
+ for (let k = 1; k <= n; k++) {
3184
+ const t = b[i + k];
3185
+ if (t === void 0 || (t & 192) !== 128) return false;
3186
+ }
3187
+ if (n === 2) {
3188
+ const c1 = b[i + 1];
3189
+ if (c === 224 && c1 < 160) return false;
3190
+ if (c === 237 && c1 >= 160) return false;
3191
+ }
3192
+ if (n === 3) {
3193
+ const c1 = b[i + 1];
3194
+ if (c === 240 && c1 < 144) return false;
3195
+ if (c === 244 && c1 >= 144) return false;
3196
+ }
3197
+ i += n + 1;
3198
+ }
3199
+ return true;
3161
3200
  }
3162
3201
  async function signEvmAuthorization(tee, chainId, address, nonce, jwt) {
3163
3202
  const serialized = await tee.sign(
@@ -4801,8 +4840,7 @@ async function createDecaneConnect(config) {
4801
4840
  return bufferToB64u(sig);
4802
4841
  }
4803
4842
  if (req.chain.startsWith("tron:")) {
4804
- const msg = typeof req.message === "string" ? req.message : new TextDecoder().decode(req.message);
4805
- return tee.sign({ chain: req.chain, kind: "message", payload: msg }, auth?.jwt);
4843
+ return tee.sign({ chain: req.chain, kind: "message", payload: messageAsString(req.message) }, auth?.jwt);
4806
4844
  }
4807
4845
  throw new CallSequenceError(`Unsupported chain: ${req.chain}`);
4808
4846
  },