@0xsequence/guard 2.3.39 → 3.0.0-beta.10

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.
@@ -0,0 +1,14 @@
1
+ import { Address, Bytes } from 'ox';
2
+ import * as Client from './client/guard.gen.js';
3
+ import * as Types from './types.js';
4
+ export declare class Guard implements Types.Guard {
5
+ private readonly guard?;
6
+ readonly address: Address.Address;
7
+ constructor(hostname: string, address: Address.Address, fetch?: Client.Fetch);
8
+ signPayload(wallet: Address.Address, chainId: number, type: Client.PayloadType, digest: Bytes.Bytes, message: Bytes.Bytes, signatures?: Client.Signature[], token?: Client.AuthToken): Promise<{
9
+ r: bigint;
10
+ s: bigint;
11
+ yParity: number;
12
+ }>;
13
+ }
14
+ //# sourceMappingURL=sequence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,KAAK,EAAQ,MAAM,IAAI,CAAA;AACzD,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAC/C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,qBAAa,KAAM,YAAW,KAAK,CAAC,KAAK;IACvC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAc;IACrC,SAAgB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAA;gBAE5B,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK;IAOtE,WAAW,CACf,MAAM,EAAE,OAAO,CAAC,OAAO,EACvB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,CAAC,WAAW,EACxB,MAAM,EAAE,KAAK,CAAC,KAAK,EACnB,OAAO,EAAE,KAAK,CAAC,KAAK,EACpB,UAAU,CAAC,EAAE,MAAM,CAAC,SAAS,EAAE,EAC/B,KAAK,CAAC,EAAE,MAAM,CAAC,SAAS;;;;;CAiC3B"}
@@ -0,0 +1,44 @@
1
+ import { Hex, Signature } from 'ox';
2
+ import * as Client from './client/guard.gen.js';
3
+ import * as Types from './types.js';
4
+ export class Guard {
5
+ guard;
6
+ address;
7
+ constructor(hostname, address, fetch) {
8
+ if (hostname && address) {
9
+ this.guard = new Client.Guard(hostname, fetch ?? window.fetch);
10
+ }
11
+ this.address = address;
12
+ }
13
+ async signPayload(wallet, chainId, type, digest, message, signatures, token) {
14
+ if (!this.guard || !this.address) {
15
+ throw new Error('Guard not initialized');
16
+ }
17
+ try {
18
+ const res = await this.guard.signWith({
19
+ signer: this.address,
20
+ request: {
21
+ chainId: chainId,
22
+ msg: Hex.fromBytes(digest),
23
+ wallet,
24
+ payloadType: type,
25
+ payloadData: Hex.fromBytes(message),
26
+ signatures,
27
+ },
28
+ token,
29
+ });
30
+ Hex.assert(res.sig);
31
+ return Signature.fromHex(res.sig);
32
+ }
33
+ catch (error) {
34
+ if (error instanceof Client.RequiresTOTPError) {
35
+ throw new Types.AuthRequiredError('TOTP');
36
+ }
37
+ if (error instanceof Client.RequiresPINError) {
38
+ throw new Types.AuthRequiredError('PIN');
39
+ }
40
+ console.error(error);
41
+ throw new Error('Error signing with guard');
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,11 @@
1
+ import { Address, Bytes, Signature } from 'ox';
2
+ import * as Client from './client/guard.gen.js';
3
+ export interface Guard {
4
+ readonly address: Address.Address;
5
+ signPayload(wallet: Address.Address, chainId: number, type: Client.PayloadType, digest: Bytes.Bytes, message: Bytes.Bytes, signatures?: Client.Signature[], token?: Client.AuthToken): Promise<Signature.Signature>;
6
+ }
7
+ export declare class AuthRequiredError extends Error {
8
+ readonly id: 'TOTP' | 'PIN';
9
+ constructor(id: 'TOTP' | 'PIN');
10
+ }
11
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAC9C,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAE/C,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAA;IAEjC,WAAW,CACT,MAAM,EAAE,OAAO,CAAC,OAAO,EACvB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,CAAC,WAAW,EACxB,MAAM,EAAE,KAAK,CAAC,KAAK,EACnB,OAAO,EAAE,KAAK,CAAC,KAAK,EACpB,UAAU,CAAC,EAAE,MAAM,CAAC,SAAS,EAAE,EAC/B,KAAK,CAAC,EAAE,MAAM,CAAC,SAAS,GACvB,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;CAChC;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,SAAgB,EAAE,EAAE,MAAM,GAAG,KAAK,CAAA;gBAEtB,EAAE,EAAE,MAAM,GAAG,KAAK;CAM/B"}
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ export class AuthRequiredError extends Error {
2
+ id;
3
+ constructor(id) {
4
+ super('auth required');
5
+ this.id = id;
6
+ this.name = 'AuthRequiredError';
7
+ Object.setPrototypeOf(this, AuthRequiredError.prototype);
8
+ }
9
+ }
package/package.json CHANGED
@@ -1,31 +1,35 @@
1
1
  {
2
2
  "name": "@0xsequence/guard",
3
- "version": "2.3.39",
3
+ "version": "3.0.0-beta.10",
4
4
  "description": "guard sub-package for Sequence",
5
- "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/guard",
6
- "source": "src/index.ts",
7
- "main": "dist/0xsequence-guard.cjs.js",
8
- "module": "dist/0xsequence-guard.esm.js",
9
- "author": "Horizon Blockchain Games",
5
+ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/services/guard",
6
+ "author": "Sequence Platforms Inc.",
10
7
  "license": "Apache-2.0",
11
- "peerDependencies": {
12
- "ethers": ">=6"
8
+ "type": "module",
9
+ "publishConfig": {
10
+ "access": "public"
13
11
  },
14
- "dependencies": {
15
- "@0xsequence/core": "2.3.39",
16
- "@0xsequence/signhub": "2.3.39",
17
- "@0xsequence/account": "2.3.39",
18
- "@0xsequence/utils": "2.3.39"
12
+ "private": false,
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
19
18
  },
20
19
  "devDependencies": {
21
- "ethers": "6.13.4"
20
+ "@types/node": "^25.0.2",
21
+ "typescript": "^5.9.3",
22
+ "vitest": "^4.0.15",
23
+ "@repo/typescript-config": "^0.0.1-beta.1"
24
+ },
25
+ "dependencies": {
26
+ "ox": "^0.9.17"
22
27
  },
23
- "files": [
24
- "src",
25
- "dist"
26
- ],
27
28
  "scripts": {
28
- "test": "echo",
29
+ "build": "tsc",
30
+ "dev": "tsc --watch",
31
+ "test": "vitest run",
32
+ "test:coverage": "vitest run --coverage",
29
33
  "typecheck": "tsc --noEmit"
30
34
  }
31
35
  }