@aastar/sdk 0.20.6 → 0.20.8

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.
@@ -1,12 +1,23 @@
1
1
  import { __export } from './chunk-PZ5AY32C.js';
2
2
  import axios2 from 'axios';
3
3
  import { startRegistration, startAuthentication } from '@simplewebauthn/browser';
4
- import { ethers } from 'ethers';
4
+ import { parseAbiParameters, encodeAbiParameters, keccak256 as keccak256$1, encodePacked, hexToBytes as hexToBytes$1, bytesToHex as bytesToHex$1, numberToHex, stringToBytes } from 'viem';
5
5
  import * as crypto from 'crypto';
6
6
 
7
+ var DEFAULT_PASSKEY_ROUTES = {
8
+ registerBegin: "/auth/passkey/register/begin",
9
+ registerComplete: "/auth/passkey/register/complete",
10
+ loginBegin: "/auth/passkey/login/begin",
11
+ loginComplete: "/auth/passkey/login/complete",
12
+ deviceBegin: "/auth/device/passkey/begin",
13
+ deviceComplete: "/auth/device/passkey/complete",
14
+ transactionVerifyBegin: "/auth/transaction/verify/begin"
15
+ };
7
16
  var PasskeyManager = class {
8
17
  api;
9
- constructor(baseURL, tokenProvider) {
18
+ routes;
19
+ constructor(baseURL, tokenProvider, routes) {
20
+ this.routes = { ...DEFAULT_PASSKEY_ROUTES, ...routes };
10
21
  this.api = axios2.create({
11
22
  baseURL,
12
23
  headers: {
@@ -28,11 +39,11 @@ var PasskeyManager = class {
28
39
  */
29
40
  async register(params) {
30
41
  const beginResponse = await this.api.post(
31
- "/auth/passkey/register/begin",
42
+ this.routes.registerBegin,
32
43
  params
33
44
  );
34
45
  const credential = await startRegistration(beginResponse.data);
35
- const completeResponse = await this.api.post("/auth/passkey/register/complete", {
46
+ const completeResponse = await this.api.post(this.routes.registerComplete, {
36
47
  email: params.email,
37
48
  username: params.username,
38
49
  password: params.password,
@@ -45,11 +56,11 @@ var PasskeyManager = class {
45
56
  */
46
57
  async authenticate(params) {
47
58
  const beginResponse = await this.api.post(
48
- "/auth/passkey/login/begin",
59
+ this.routes.loginBegin,
49
60
  params
50
61
  );
51
62
  const credential = await startAuthentication(beginResponse.data);
52
- const completeResponse = await this.api.post("/auth/passkey/login/complete", { credential });
63
+ const completeResponse = await this.api.post(this.routes.loginComplete, { credential });
53
64
  return completeResponse.data;
54
65
  }
55
66
  /**
@@ -58,7 +69,7 @@ var PasskeyManager = class {
58
69
  */
59
70
  async verifyTransaction(params) {
60
71
  const beginResponse = await this.api.post(
61
- "/auth/transaction/verify/begin",
72
+ this.routes.transactionVerifyBegin,
62
73
  { transaction: params }
63
74
  );
64
75
  const { userOpHash, ...authOptions } = beginResponse.data;
@@ -74,11 +85,11 @@ var PasskeyManager = class {
74
85
  */
75
86
  async addDevice(params) {
76
87
  const beginResponse = await this.api.post(
77
- "/auth/device/passkey/begin",
88
+ this.routes.deviceBegin,
78
89
  params
79
90
  );
80
91
  const credential = await startRegistration(beginResponse.data);
81
- const completeResponse = await this.api.post("/auth/device/passkey/complete", {
92
+ const completeResponse = await this.api.post(this.routes.deviceComplete, {
82
93
  email: params.email,
83
94
  password: params.password,
84
95
  credential
@@ -4020,6 +4031,91 @@ function mapToG2(scalars) {
4020
4031
  return isogenyMapG2(x, y);
4021
4032
  }
4022
4033
 
4034
+ // ../airaccount/src/migration/viem/bls-packing.ts
4035
+ var BLS_DST = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_";
4036
+ function packSignature(data) {
4037
+ if (!data.nodeIds || !data.aaSignature || !data.messagePointSignature) {
4038
+ throw new Error("Missing required signature components");
4039
+ }
4040
+ const nodeIdsLength = encodePacked(["uint256"], [BigInt(data.nodeIds.length)]);
4041
+ const nodeIdsBytes = encodePacked(
4042
+ Array(data.nodeIds.length).fill("bytes32"),
4043
+ data.nodeIds
4044
+ );
4045
+ return encodePacked(
4046
+ ["bytes", "bytes", "bytes", "bytes", "bytes", "bytes"],
4047
+ [
4048
+ nodeIdsLength,
4049
+ nodeIdsBytes,
4050
+ data.signature,
4051
+ data.messagePoint,
4052
+ data.aaSignature,
4053
+ data.messagePointSignature
4054
+ ]
4055
+ );
4056
+ }
4057
+ function packCumulativeT2Signature(data) {
4058
+ const nodeIdsLength = encodePacked(["uint256"], [BigInt(data.nodeIds.length)]);
4059
+ const nodeIdsBytes = encodePacked(
4060
+ Array(data.nodeIds.length).fill("bytes32"),
4061
+ data.nodeIds
4062
+ );
4063
+ return encodePacked(
4064
+ ["bytes1", "bytes", "bytes", "bytes", "bytes", "bytes", "bytes"],
4065
+ [
4066
+ "0x04",
4067
+ data.p256Signature,
4068
+ nodeIdsLength,
4069
+ nodeIdsBytes,
4070
+ data.blsSignature,
4071
+ data.messagePoint,
4072
+ data.messagePointSignature
4073
+ ]
4074
+ );
4075
+ }
4076
+ function packCumulativeT3Signature(data) {
4077
+ const nodeIdsLength = encodePacked(["uint256"], [BigInt(data.nodeIds.length)]);
4078
+ const nodeIdsBytes = encodePacked(
4079
+ Array(data.nodeIds.length).fill("bytes32"),
4080
+ data.nodeIds
4081
+ );
4082
+ return encodePacked(
4083
+ ["bytes1", "bytes", "bytes", "bytes", "bytes", "bytes", "bytes", "bytes"],
4084
+ [
4085
+ "0x05",
4086
+ data.p256Signature,
4087
+ nodeIdsLength,
4088
+ nodeIdsBytes,
4089
+ data.blsSignature,
4090
+ data.messagePoint,
4091
+ data.messagePointSignature,
4092
+ data.guardianSignature
4093
+ ]
4094
+ );
4095
+ }
4096
+ function encodeG2Point(point) {
4097
+ const result = new Uint8Array(256);
4098
+ const affine = point.toAffine();
4099
+ const x0Bytes = hexToBytes$1(numberToHex(affine.x.c0, { size: 48 }));
4100
+ const x1Bytes = hexToBytes$1(numberToHex(affine.x.c1, { size: 48 }));
4101
+ const y0Bytes = hexToBytes$1(numberToHex(affine.y.c0, { size: 48 }));
4102
+ const y1Bytes = hexToBytes$1(numberToHex(affine.y.c1, { size: 48 }));
4103
+ result.set(x0Bytes, 16);
4104
+ result.set(x1Bytes, 80);
4105
+ result.set(y0Bytes, 144);
4106
+ result.set(y1Bytes, 208);
4107
+ return result;
4108
+ }
4109
+ async function hashToCurve(messageBytes) {
4110
+ return bls12_381.G2.hashToCurve(messageBytes, { DST: BLS_DST });
4111
+ }
4112
+ async function generateMessagePoint(message) {
4113
+ const messageBytes = typeof message === "string" ? hexToBytes$1(message) : message;
4114
+ const messagePointBLS = await hashToCurve(messageBytes);
4115
+ const messageG2EIP = encodeG2Point(messagePointBLS);
4116
+ return bytesToHex$1(messageG2EIP);
4117
+ }
4118
+
4023
4119
  // ../airaccount/src/core/bls/bls.manager.ts
4024
4120
  var BLSManager = class {
4025
4121
  config;
@@ -4060,59 +4156,13 @@ var BLSManager = class {
4060
4156
  * Format: [nodeIdsLength][nodeIds...][blsSignature][messagePoint][aaSignature][messagePointSignature]
4061
4157
  */
4062
4158
  packSignature(data) {
4063
- if (!data.nodeIds || !data.aaSignature || !data.messagePointSignature) {
4064
- throw new Error("Missing required signature components");
4065
- }
4066
- const nodeIdsLength = ethers.solidityPacked(["uint256"], [data.nodeIds.length]);
4067
- const nodeIdsBytes = ethers.solidityPacked(
4068
- Array(data.nodeIds.length).fill("bytes32"),
4069
- data.nodeIds
4070
- );
4071
- return ethers.solidityPacked(
4072
- ["bytes", "bytes", "bytes", "bytes", "bytes", "bytes"],
4073
- [
4074
- nodeIdsLength,
4075
- nodeIdsBytes,
4076
- data.signature,
4077
- data.messagePoint,
4078
- data.aaSignature,
4079
- data.messagePointSignature
4080
- ]
4081
- );
4159
+ return packSignature(data);
4082
4160
  }
4083
4161
  /**
4084
4162
  * Calculate the MessagePoint G2 point for a given message (UserOpHash)
4085
4163
  */
4086
4164
  async generateMessagePoint(message) {
4087
- const messageBytes = typeof message === "string" ? ethers.getBytes(message) : message;
4088
- const DST = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_";
4089
- const messagePointBLS = await bls12_381.G2.hashToCurve(messageBytes, { DST });
4090
- const messageG2EIP = this.encodeG2Point(messagePointBLS);
4091
- return "0x" + Buffer.from(messageG2EIP).toString("hex");
4092
- }
4093
- /**
4094
- * Encode G2 Point to bytes for EIP-2537 format
4095
- */
4096
- encodeG2Point(point) {
4097
- const result = new Uint8Array(256);
4098
- const affine = point.toAffine();
4099
- const x0Bytes = this.hexToBytes(affine.x.c0.toString(16).padStart(96, "0"));
4100
- const x1Bytes = this.hexToBytes(affine.x.c1.toString(16).padStart(96, "0"));
4101
- const y0Bytes = this.hexToBytes(affine.y.c0.toString(16).padStart(96, "0"));
4102
- const y1Bytes = this.hexToBytes(affine.y.c1.toString(16).padStart(96, "0"));
4103
- result.set(x0Bytes, 16);
4104
- result.set(x1Bytes, 80);
4105
- result.set(y0Bytes, 144);
4106
- result.set(y1Bytes, 208);
4107
- return result;
4108
- }
4109
- hexToBytes(hex) {
4110
- if (hex.startsWith("0x")) hex = hex.slice(2);
4111
- const bytes = new Uint8Array(hex.length / 2);
4112
- for (let i = 0; i < hex.length; i += 2) {
4113
- bytes[i / 2] = parseInt(hex.substr(i, 2), 16);
4114
- }
4115
- return bytes;
4165
+ return generateMessagePoint(message);
4116
4166
  }
4117
4167
  /**
4118
4168
  * Pack cumulative Tier 2 signature (algId 0x04): P256 + BLS.
@@ -4124,23 +4174,7 @@ var BLSManager = class {
4124
4174
  * [messagePointECDSA (65)]
4125
4175
  */
4126
4176
  packCumulativeT2Signature(data) {
4127
- const nodeIdsLength = ethers.solidityPacked(["uint256"], [data.nodeIds.length]);
4128
- const nodeIdsBytes = ethers.solidityPacked(
4129
- Array(data.nodeIds.length).fill("bytes32"),
4130
- data.nodeIds
4131
- );
4132
- return ethers.solidityPacked(
4133
- ["bytes1", "bytes", "bytes", "bytes", "bytes", "bytes", "bytes"],
4134
- [
4135
- "0x04",
4136
- data.p256Signature,
4137
- nodeIdsLength,
4138
- nodeIdsBytes,
4139
- data.blsSignature,
4140
- data.messagePoint,
4141
- data.messagePointSignature
4142
- ]
4143
- );
4177
+ return packCumulativeT2Signature(data);
4144
4178
  }
4145
4179
  /**
4146
4180
  * Pack cumulative Tier 3 signature (algId 0x05): P256 + BLS + Guardian.
@@ -4152,24 +4186,7 @@ var BLSManager = class {
4152
4186
  * [messagePointECDSA (65)] [guardianECDSA (65)]
4153
4187
  */
4154
4188
  packCumulativeT3Signature(data) {
4155
- const nodeIdsLength = ethers.solidityPacked(["uint256"], [data.nodeIds.length]);
4156
- const nodeIdsBytes = ethers.solidityPacked(
4157
- Array(data.nodeIds.length).fill("bytes32"),
4158
- data.nodeIds
4159
- );
4160
- return ethers.solidityPacked(
4161
- ["bytes1", "bytes", "bytes", "bytes", "bytes", "bytes", "bytes", "bytes"],
4162
- [
4163
- "0x05",
4164
- data.p256Signature,
4165
- nodeIdsLength,
4166
- nodeIdsBytes,
4167
- data.blsSignature,
4168
- data.messagePoint,
4169
- data.messagePointSignature,
4170
- data.guardianSignature
4171
- ]
4172
- );
4189
+ return packCumulativeT3Signature(data);
4173
4190
  }
4174
4191
  /**
4175
4192
  * Request signature from a single node
@@ -4198,15 +4215,20 @@ var BLSManager = class {
4198
4215
  };
4199
4216
 
4200
4217
  // ../airaccount/src/client.ts
4201
- var YAAAClient = class {
4218
+ var AirAccountClient = class {
4202
4219
  constructor(config) {
4203
4220
  this.config = config;
4204
- this.passkey = new PasskeyManager(config.apiURL, config.tokenProvider);
4221
+ this.passkey = new PasskeyManager(
4222
+ config.apiURL,
4223
+ config.tokenProvider,
4224
+ config.passkeyRoutes
4225
+ );
4205
4226
  this.bls = new BLSManager(config.bls);
4206
4227
  }
4207
4228
  passkey;
4208
4229
  bls;
4209
4230
  };
4231
+ var YAAAClient = AirAccountClient;
4210
4232
  var CryptoUtil = class _CryptoUtil {
4211
4233
  static ALGORITHM = "aes-256-gcm";
4212
4234
  static KEY_LENGTH = 32;
@@ -4311,6 +4333,24 @@ var ERC4337Utils = class _ERC4337Utils {
4311
4333
  };
4312
4334
  }
4313
4335
  };
4336
+ function encodeAbiParams(types, values) {
4337
+ const params = parseAbiParameters(types.join(", "));
4338
+ return encodeAbiParameters(params, values);
4339
+ }
4340
+ function solidityPacked(types, values) {
4341
+ return encodePacked(types, values);
4342
+ }
4343
+ function id(value) {
4344
+ return keccak256$1(stringToBytes(value));
4345
+ }
4346
+ function keccak256(data) {
4347
+ return keccak256$1(data);
4348
+ }
4349
+ function selectorFromId(signature) {
4350
+ return id(signature).slice(0, 10);
4351
+ }
4352
+
4353
+ // ../airaccount/src/core/erc4337/userop.builder.ts
4314
4354
  var UserOpBuilder = class _UserOpBuilder {
4315
4355
  // Basic defaults
4316
4356
  static DEFAULT_VERIFICATION_GAS_LIMIT = 100000n;
@@ -4347,23 +4387,23 @@ var UserOpBuilder = class _UserOpBuilder {
4347
4387
  * Hash the UserOperation for signing (ERC-4337 v0.7)
4348
4388
  */
4349
4389
  getUserOpHash(userOp, entryPoint, chainId) {
4350
- const encoded = ethers.AbiCoder.defaultAbiCoder().encode(
4390
+ const encoded = encodeAbiParams(
4351
4391
  ["address", "uint256", "bytes32", "bytes32", "bytes32", "uint256", "bytes32", "bytes32"],
4352
4392
  [
4353
4393
  userOp.sender,
4354
4394
  userOp.nonce,
4355
- ethers.keccak256(userOp.initCode),
4356
- ethers.keccak256(userOp.callData),
4395
+ keccak256(userOp.initCode),
4396
+ keccak256(userOp.callData),
4357
4397
  userOp.accountGasLimits,
4358
4398
  userOp.preVerificationGas,
4359
4399
  userOp.gasFees,
4360
- ethers.keccak256(userOp.paymasterAndData)
4400
+ keccak256(userOp.paymasterAndData)
4361
4401
  ]
4362
4402
  );
4363
- return ethers.keccak256(
4364
- ethers.AbiCoder.defaultAbiCoder().encode(
4403
+ return keccak256(
4404
+ encodeAbiParams(
4365
4405
  ["bytes32", "address", "uint256"],
4366
- [ethers.keccak256(encoded), entryPoint, chainId]
4406
+ [keccak256(encoded), entryPoint, BigInt(chainId)]
4367
4407
  )
4368
4408
  );
4369
4409
  }
@@ -4403,8 +4443,10 @@ __export(src_exports, {
4403
4443
  ALG_CUMULATIVE_T3: () => ALG_CUMULATIVE_T3,
4404
4444
  ALG_ECDSA: () => ALG_ECDSA,
4405
4445
  ALG_P256: () => ALG_P256,
4446
+ AirAccountClient: () => AirAccountClient,
4406
4447
  BLSManager: () => BLSManager,
4407
4448
  CryptoUtil: () => CryptoUtil,
4449
+ DEFAULT_PASSKEY_ROUTES: () => DEFAULT_PASSKEY_ROUTES,
4408
4450
  ERC4337Utils: () => ERC4337Utils,
4409
4451
  PasskeyManager: () => PasskeyManager,
4410
4452
  UserOpBuilder: () => UserOpBuilder,
@@ -4427,6 +4469,6 @@ __export(src_exports, {
4427
4469
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
4428
4470
  */
4429
4471
 
4430
- export { ALG_BLS, ALG_CUMULATIVE_T2, ALG_CUMULATIVE_T3, ALG_ECDSA, ALG_P256, BLSManager, CryptoUtil, ERC4337Utils, PasskeyManager, UserOpBuilder, YAAAClient, algIdForTier, ecdsa, resolveTier, sha256, src_exports, weierstrass };
4431
- //# sourceMappingURL=chunk-FUU7RIIA.js.map
4432
- //# sourceMappingURL=chunk-FUU7RIIA.js.map
4472
+ export { ALG_BLS, ALG_CUMULATIVE_T2, ALG_CUMULATIVE_T3, ALG_ECDSA, ALG_P256, AirAccountClient, BLSManager, CryptoUtil, DEFAULT_PASSKEY_ROUTES, ERC4337Utils, PasskeyManager, UserOpBuilder, YAAAClient, algIdForTier, ecdsa, encodeAbiParams, keccak256, resolveTier, selectorFromId, sha256, solidityPacked, src_exports, weierstrass };
4473
+ //# sourceMappingURL=chunk-X3AMH53O.js.map
4474
+ //# sourceMappingURL=chunk-X3AMH53O.js.map