@anywalletkit/wallet-near 0.3.0 → 0.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.cts CHANGED
@@ -401,6 +401,13 @@ declare function actionKey(a: NearAction): NearActionKey;
401
401
  declare function isPlainObject(v: unknown): v is Record<string, unknown>;
402
402
  /** Function-call args as bytes: raw bytes pass through; plain objects / strings become UTF-8 JSON / UTF-8. Anything else throws. */
403
403
  declare function argsBytes(args: Uint8Array | Record<string, unknown> | string): Uint8Array;
404
+ /**
405
+ * The borsh tag of an access-key permission (0 FunctionCall, 1 FullAccess), read from a permission of
406
+ * exactly one known variant: `{ fullAccess: {} }` or `{ functionCall: { receiverId, methodNames, allowance? } }`.
407
+ * Anything else throws, so an empty, misspelled, unknown or doubled variant is never encoded as
408
+ * FullAccess. The encoder, `assertWellFormed` and the description all read this one tag (scan 2026-10-30 F9).
409
+ */
410
+ declare function accessKeyPermissionTag(permission: unknown): 0 | 1;
404
411
  declare function writeAction(w: BorshWriter, a: NearAction): void;
405
412
  declare function readAction(r: BorshReader): NearAction;
406
413
  /** Borsh bytes of an unsigned transaction. */
@@ -624,7 +631,8 @@ declare function parseSignature(signature: string): Uint8Array;
624
631
  /**
625
632
  * An object transaction has exactly the shape the encoder writes, before it is built or signed (also
626
633
  * `signBuilt`): every action one known key; a function call's `methodName` a string of the method
627
- * grammar, `args` bytes, a string or a plain object, `gas` / `deposit` bigints; every account id and
634
+ * grammar, `args` bytes, a string or a plain object, `gas` / `deposit` bigints; an AddKey permission
635
+ * exactly one known variant (scan 2026-10-30 F9); every account id and
628
636
  * method name well formed. What the policies read is then what gets encoded (scan 2026-10-27 F6, F28).
629
637
  */
630
638
  declare function assertWellFormed(tx: Pick<NearBuiltTransaction, 'receiverId' | 'actions'>): void;
@@ -719,4 +727,4 @@ declare class WalletManagerNear extends WalletManager<WalletAccountNear, NearCon
719
727
  getFeeRates(): Promise<FeeRates>;
720
728
  }
721
729
 
722
- export { ACTION_TAG, BorshReader, BorshWriter, BroadcastUnknownError, CAIP2, DANGEROUS_ACTIONS, type DescribeContext, FT_TRANSFER_GAS, IMPLICIT_ACCOUNT_MIN_DEPOSIT, MAX_GAS, MessageIsTransactionError, NEAR_BASE_PATH, NEP413_PREFIX, type NearAccessKey, type NearAccountView, type NearAction, type NearAddKeyAction, type NearBuiltTransaction, type NearConfig, type NearCreateAccountAction, type NearDelegateAction, type NearDeleteAccountAction, type NearDeleteKeyAction, type NearDeployContractAction, type NearDeployGlobalContractAction, type NearFeeEstimate, type NearFetch, type NearFunctionCallAction, type NearProvider, type NearPublicKey, type NearQuote, type NearReceipt, NearRpc, NearRpcError, type NearSignature, type NearSignedDelegateAction, type NearSignedTransaction, type NearSimulation, type NearStakeAction, type NearTransaction, type NearTransferAction, type NearTransferOptions, type NearTransferResult, type NearTxDescription, type NearTxKind, type NearTxWarning, type NearTxWarningCode, type NearUseGlobalContractAction, type Nep413Payload, type Nep413Signed, ONE_YOCTO, type RawAccessKeyView, type RawAccountView, type RawFinalOutcome, STORAGE_DEPOSIT_GAS, STORAGE_PRICE_PER_BYTE, SimulationError, TGAS, type UnsafeTransactionCode, UnsafeTransactionError, WalletAccountNear, WalletAccountReadOnlyNear, WalletManagerNear, YOCTO, actionKey, argsBytes, assertWellFormed, base58ToBytes, bytesToBase58, createClient, decodeAnyTransaction, decodeSignedTransaction, decodeTransaction, WalletManagerNear as default, describeTransaction, ed25519Key, encodeSignedTransaction, encodeTransaction, failureOf, fromBase64, implicitAccountId, isDangerous, isImplicitAccountId, isPlainObject, isValidAccountId, nep413Bytes, nep413Hash, outcomeFailed, parsePublicKey, parseSignature, publicKeyOfImplicit, publicKeyToString, readAction, readPublicKey, readSignature, receiptOf, toBase64, writeAction, writePublicKey, writeSignature };
730
+ export { ACTION_TAG, BorshReader, BorshWriter, BroadcastUnknownError, CAIP2, DANGEROUS_ACTIONS, type DescribeContext, FT_TRANSFER_GAS, IMPLICIT_ACCOUNT_MIN_DEPOSIT, MAX_GAS, MessageIsTransactionError, NEAR_BASE_PATH, NEP413_PREFIX, type NearAccessKey, type NearAccountView, type NearAction, type NearAddKeyAction, type NearBuiltTransaction, type NearConfig, type NearCreateAccountAction, type NearDelegateAction, type NearDeleteAccountAction, type NearDeleteKeyAction, type NearDeployContractAction, type NearDeployGlobalContractAction, type NearFeeEstimate, type NearFetch, type NearFunctionCallAction, type NearProvider, type NearPublicKey, type NearQuote, type NearReceipt, NearRpc, NearRpcError, type NearSignature, type NearSignedDelegateAction, type NearSignedTransaction, type NearSimulation, type NearStakeAction, type NearTransaction, type NearTransferAction, type NearTransferOptions, type NearTransferResult, type NearTxDescription, type NearTxKind, type NearTxWarning, type NearTxWarningCode, type NearUseGlobalContractAction, type Nep413Payload, type Nep413Signed, ONE_YOCTO, type RawAccessKeyView, type RawAccountView, type RawFinalOutcome, STORAGE_DEPOSIT_GAS, STORAGE_PRICE_PER_BYTE, SimulationError, TGAS, type UnsafeTransactionCode, UnsafeTransactionError, WalletAccountNear, WalletAccountReadOnlyNear, WalletManagerNear, YOCTO, accessKeyPermissionTag, actionKey, argsBytes, assertWellFormed, base58ToBytes, bytesToBase58, createClient, decodeAnyTransaction, decodeSignedTransaction, decodeTransaction, WalletManagerNear as default, describeTransaction, ed25519Key, encodeSignedTransaction, encodeTransaction, failureOf, fromBase64, implicitAccountId, isDangerous, isImplicitAccountId, isPlainObject, isValidAccountId, nep413Bytes, nep413Hash, outcomeFailed, parsePublicKey, parseSignature, publicKeyOfImplicit, publicKeyToString, readAction, readPublicKey, readSignature, receiptOf, toBase64, writeAction, writePublicKey, writeSignature };
package/dist/index.d.ts CHANGED
@@ -401,6 +401,13 @@ declare function actionKey(a: NearAction): NearActionKey;
401
401
  declare function isPlainObject(v: unknown): v is Record<string, unknown>;
402
402
  /** Function-call args as bytes: raw bytes pass through; plain objects / strings become UTF-8 JSON / UTF-8. Anything else throws. */
403
403
  declare function argsBytes(args: Uint8Array | Record<string, unknown> | string): Uint8Array;
404
+ /**
405
+ * The borsh tag of an access-key permission (0 FunctionCall, 1 FullAccess), read from a permission of
406
+ * exactly one known variant: `{ fullAccess: {} }` or `{ functionCall: { receiverId, methodNames, allowance? } }`.
407
+ * Anything else throws, so an empty, misspelled, unknown or doubled variant is never encoded as
408
+ * FullAccess. The encoder, `assertWellFormed` and the description all read this one tag (scan 2026-10-30 F9).
409
+ */
410
+ declare function accessKeyPermissionTag(permission: unknown): 0 | 1;
404
411
  declare function writeAction(w: BorshWriter, a: NearAction): void;
405
412
  declare function readAction(r: BorshReader): NearAction;
406
413
  /** Borsh bytes of an unsigned transaction. */
@@ -624,7 +631,8 @@ declare function parseSignature(signature: string): Uint8Array;
624
631
  /**
625
632
  * An object transaction has exactly the shape the encoder writes, before it is built or signed (also
626
633
  * `signBuilt`): every action one known key; a function call's `methodName` a string of the method
627
- * grammar, `args` bytes, a string or a plain object, `gas` / `deposit` bigints; every account id and
634
+ * grammar, `args` bytes, a string or a plain object, `gas` / `deposit` bigints; an AddKey permission
635
+ * exactly one known variant (scan 2026-10-30 F9); every account id and
628
636
  * method name well formed. What the policies read is then what gets encoded (scan 2026-10-27 F6, F28).
629
637
  */
630
638
  declare function assertWellFormed(tx: Pick<NearBuiltTransaction, 'receiverId' | 'actions'>): void;
@@ -719,4 +727,4 @@ declare class WalletManagerNear extends WalletManager<WalletAccountNear, NearCon
719
727
  getFeeRates(): Promise<FeeRates>;
720
728
  }
721
729
 
722
- export { ACTION_TAG, BorshReader, BorshWriter, BroadcastUnknownError, CAIP2, DANGEROUS_ACTIONS, type DescribeContext, FT_TRANSFER_GAS, IMPLICIT_ACCOUNT_MIN_DEPOSIT, MAX_GAS, MessageIsTransactionError, NEAR_BASE_PATH, NEP413_PREFIX, type NearAccessKey, type NearAccountView, type NearAction, type NearAddKeyAction, type NearBuiltTransaction, type NearConfig, type NearCreateAccountAction, type NearDelegateAction, type NearDeleteAccountAction, type NearDeleteKeyAction, type NearDeployContractAction, type NearDeployGlobalContractAction, type NearFeeEstimate, type NearFetch, type NearFunctionCallAction, type NearProvider, type NearPublicKey, type NearQuote, type NearReceipt, NearRpc, NearRpcError, type NearSignature, type NearSignedDelegateAction, type NearSignedTransaction, type NearSimulation, type NearStakeAction, type NearTransaction, type NearTransferAction, type NearTransferOptions, type NearTransferResult, type NearTxDescription, type NearTxKind, type NearTxWarning, type NearTxWarningCode, type NearUseGlobalContractAction, type Nep413Payload, type Nep413Signed, ONE_YOCTO, type RawAccessKeyView, type RawAccountView, type RawFinalOutcome, STORAGE_DEPOSIT_GAS, STORAGE_PRICE_PER_BYTE, SimulationError, TGAS, type UnsafeTransactionCode, UnsafeTransactionError, WalletAccountNear, WalletAccountReadOnlyNear, WalletManagerNear, YOCTO, actionKey, argsBytes, assertWellFormed, base58ToBytes, bytesToBase58, createClient, decodeAnyTransaction, decodeSignedTransaction, decodeTransaction, WalletManagerNear as default, describeTransaction, ed25519Key, encodeSignedTransaction, encodeTransaction, failureOf, fromBase64, implicitAccountId, isDangerous, isImplicitAccountId, isPlainObject, isValidAccountId, nep413Bytes, nep413Hash, outcomeFailed, parsePublicKey, parseSignature, publicKeyOfImplicit, publicKeyToString, readAction, readPublicKey, readSignature, receiptOf, toBase64, writeAction, writePublicKey, writeSignature };
730
+ export { ACTION_TAG, BorshReader, BorshWriter, BroadcastUnknownError, CAIP2, DANGEROUS_ACTIONS, type DescribeContext, FT_TRANSFER_GAS, IMPLICIT_ACCOUNT_MIN_DEPOSIT, MAX_GAS, MessageIsTransactionError, NEAR_BASE_PATH, NEP413_PREFIX, type NearAccessKey, type NearAccountView, type NearAction, type NearAddKeyAction, type NearBuiltTransaction, type NearConfig, type NearCreateAccountAction, type NearDelegateAction, type NearDeleteAccountAction, type NearDeleteKeyAction, type NearDeployContractAction, type NearDeployGlobalContractAction, type NearFeeEstimate, type NearFetch, type NearFunctionCallAction, type NearProvider, type NearPublicKey, type NearQuote, type NearReceipt, NearRpc, NearRpcError, type NearSignature, type NearSignedDelegateAction, type NearSignedTransaction, type NearSimulation, type NearStakeAction, type NearTransaction, type NearTransferAction, type NearTransferOptions, type NearTransferResult, type NearTxDescription, type NearTxKind, type NearTxWarning, type NearTxWarningCode, type NearUseGlobalContractAction, type Nep413Payload, type Nep413Signed, ONE_YOCTO, type RawAccessKeyView, type RawAccountView, type RawFinalOutcome, STORAGE_DEPOSIT_GAS, STORAGE_PRICE_PER_BYTE, SimulationError, TGAS, type UnsafeTransactionCode, UnsafeTransactionError, WalletAccountNear, WalletAccountReadOnlyNear, WalletManagerNear, YOCTO, accessKeyPermissionTag, actionKey, argsBytes, assertWellFormed, base58ToBytes, bytesToBase58, createClient, decodeAnyTransaction, decodeSignedTransaction, decodeTransaction, WalletManagerNear as default, describeTransaction, ed25519Key, encodeSignedTransaction, encodeTransaction, failureOf, fromBase64, implicitAccountId, isDangerous, isImplicitAccountId, isPlainObject, isValidAccountId, nep413Bytes, nep413Hash, outcomeFailed, parsePublicKey, parseSignature, publicKeyOfImplicit, publicKeyToString, readAction, readPublicKey, readSignature, receiptOf, toBase64, writeAction, writePublicKey, writeSignature };
package/dist/index.js CHANGED
@@ -239,17 +239,34 @@ function argsBytes(args) {
239
239
  if (!isPlainObject(args)) throw new TypeError("function-call args must be bytes, a string or a plain object");
240
240
  return utf8.encode(JSON.stringify(args));
241
241
  }
242
+ var FUNCTION_CALL_PERMISSION_KEYS = /* @__PURE__ */ new Set(["allowance", "receiverId", "methodNames"]);
243
+ function accessKeyPermissionTag(permission) {
244
+ const keys = isPlainObject(permission) ? Object.keys(permission) : [];
245
+ if (keys.length !== 1) throw new TypeError(`an access-key permission must have exactly one variant, fullAccess or functionCall (has: ${keys.join(", ") || "none"})`);
246
+ const variant = permission[keys[0]];
247
+ if (keys[0] === "fullAccess") {
248
+ if (!isPlainObject(variant)) throw new TypeError("fullAccess must be a plain object");
249
+ return 1;
250
+ }
251
+ if (keys[0] === "functionCall") {
252
+ if (!isPlainObject(variant) || Object.keys(variant).some((k) => !FUNCTION_CALL_PERMISSION_KEYS.has(k))) throw new TypeError("functionCall must be a plain { receiverId, methodNames, allowance? } object");
253
+ if (typeof variant.receiverId !== "string") throw new TypeError("functionCall.receiverId must be a string");
254
+ if (!Array.isArray(variant.methodNames) || !variant.methodNames.every((m) => typeof m === "string")) throw new TypeError("functionCall.methodNames must be an array of strings");
255
+ if (variant.allowance !== void 0 && typeof variant.allowance !== "bigint") throw new TypeError("functionCall.allowance must be a bigint or absent");
256
+ return 0;
257
+ }
258
+ throw new TypeError(`unknown access-key permission ${JSON.stringify(keys[0])}`);
259
+ }
242
260
  function writeAccessKey(w, k) {
243
261
  w.u64(k.nonce);
244
- if ("functionCall" in k.permission) {
262
+ const tag = accessKeyPermissionTag(k.permission);
263
+ w.u8(tag);
264
+ if (tag === 0) {
245
265
  const p = k.permission.functionCall;
246
- w.u8(0);
247
266
  w.option(p.allowance, (a) => w.u128(a));
248
267
  w.string(p.receiverId);
249
268
  w.u32(p.methodNames.length);
250
269
  for (const m of p.methodNames) w.string(m);
251
- } else {
252
- w.u8(1);
253
270
  }
254
271
  }
255
272
  function readAccessKey(r) {
@@ -489,8 +506,15 @@ function describeTransaction(tx, ctx = {}) {
489
506
  if (DANGEROUS_ACTIONS.has(key)) {
490
507
  dangerous ??= KIND_OF_DANGEROUS[key];
491
508
  warnings.push({ code: "dangerous-action", message: `${key} changes the account, its keys or its code.` });
492
- if (key === "addKey" && "fullAccess" in a.addKey.accessKey.permission) {
493
- warnings.push({ code: "full-access-key", message: "Adds a FULL ACCESS key: whoever holds it owns the account." });
509
+ if (key === "addKey") {
510
+ let tag;
511
+ try {
512
+ tag = accessKeyPermissionTag(a.addKey?.accessKey?.permission);
513
+ } catch {
514
+ tag = void 0;
515
+ }
516
+ if (tag === 1) warnings.push({ code: "full-access-key", message: "Adds a FULL ACCESS key: whoever holds it owns the account." });
517
+ else if (tag === void 0) warnings.push({ code: "dangerous-action", message: "Malformed access-key permission: neither fullAccess nor functionCall. The wallet refuses to sign it." });
494
518
  }
495
519
  continue;
496
520
  }
@@ -888,6 +912,15 @@ function assertShape(actions, depth = 0) {
888
912
  if (!(f.args instanceof Uint8Array) && typeof f.args !== "string" && !isPlainObject(f.args)) throw new UnsafeTransactionError("malformed-action", "Function-call args must be bytes, a string or a plain object.");
889
913
  if (f.gas !== void 0 && typeof f.gas !== "bigint" || f.deposit !== void 0 && typeof f.deposit !== "bigint") throw new UnsafeTransactionError("malformed-action", "Function-call gas and deposit must be bigints.");
890
914
  }
915
+ if ("addKey" in a) {
916
+ const k = a.addKey;
917
+ if (!isPlainObject(k) || !isPlainObject(k.accessKey)) throw new UnsafeTransactionError("malformed-action", "addKey must carry an accessKey object.");
918
+ try {
919
+ accessKeyPermissionTag(k.accessKey.permission);
920
+ } catch (e) {
921
+ throw new UnsafeTransactionError("malformed-action", `AddKey: ${e.message}.`);
922
+ }
923
+ }
891
924
  if ("signedDelegate" in a && depth === 0) assertShape(a.signedDelegate.delegateAction.actions, depth + 1);
892
925
  }
893
926
  }
@@ -1159,6 +1192,7 @@ export {
1159
1192
  WalletAccountReadOnlyNear,
1160
1193
  WalletManagerNear,
1161
1194
  YOCTO,
1195
+ accessKeyPermissionTag,
1162
1196
  actionKey,
1163
1197
  argsBytes,
1164
1198
  assertWellFormed,