@cartridge/controller 0.1.0 → 0.1.2

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,150 +1,149 @@
1
- import { DeployContractPayload, DeployContractResponse as StarknetDeployContractResponse, Abi, Call, InvocationsDetails, typedData, InvokeFunctionResponse, Signature, Invocation } from "starknet";
2
- import { BigNumberish } from "starknet/dist/utils/number";
3
- import { EstimateFee } from "starknet/types/account";
4
- export declare type Approvals = {
5
- [origin: string]: {
6
- scopes: Scope[];
7
- maxFee: BigNumberish;
8
- };
9
- };
10
- export declare type Scope = {
11
- target: string;
12
- method?: string;
13
- };
14
- export interface ProbeRequest extends RawRequest {
15
- method: "probe";
16
- }
17
- export interface ProbeResponse extends RawResponse {
18
- method: "probe";
19
- result?: {
20
- address?: string;
21
- scopes?: Scope[];
22
- };
23
- }
24
- export interface ConnectRequest extends RawRequest {
25
- method: "connect";
26
- params: {
27
- id: string;
28
- scopes: Scope[];
29
- };
30
- }
31
- export interface ConnectResponse extends RawResponse {
32
- method: "connect";
33
- result?: {
34
- success: boolean;
35
- address?: string;
36
- scopes: Scope[];
37
- };
38
- }
39
- export interface DeployContractRequest extends RawRequest {
40
- method: "deploy-contract";
41
- params: {
42
- id: string;
43
- payload: DeployContractPayload;
44
- abi?: Abi;
45
- };
46
- }
47
- export interface DeployContractResponse extends RawResponse {
48
- method: "deploy-contract";
49
- result?: StarknetDeployContractResponse;
50
- }
51
- export interface EstimateFeeRequest extends RawRequest {
52
- method: "estimate-fee";
53
- params: {
54
- invocation: Invocation;
55
- };
56
- }
57
- export interface EstimateFeeResponse extends RawResponse {
58
- method: "estimate-fee";
59
- result?: EstimateFee;
60
- }
61
- export interface ExecuteRequest extends RawRequest {
62
- method: "execute";
63
- params: {
64
- id?: string;
65
- transactions: Call | Call[];
66
- abis?: Abi[];
67
- transactionsDetail?: InvocationsDetails;
68
- };
69
- }
70
- export interface ExecuteResponse extends RawResponse {
71
- method: "execute";
72
- result?: InvokeFunctionResponse;
73
- scopes?: Scope[];
74
- }
75
- export interface SignTransactionRequest extends RawRequest {
76
- method: "sign-transaction";
77
- params: {
78
- id: string;
79
- transactions: Call | Call[];
80
- abis?: Abi[];
81
- transactionsDetail?: InvocationsDetails;
82
- };
83
- }
84
- export interface SignTransactionResponse extends RawResponse {
85
- method: "sign-transaction";
86
- result?: Signature;
87
- }
88
- export interface SignMessageRequest extends RawRequest {
89
- method: "sign-message";
90
- params: {
91
- id: string;
92
- account?: string;
93
- typedData: typedData.TypedData;
94
- };
95
- }
96
- export interface SignMessageResponse extends RawResponse {
97
- method: "sign-message";
98
- result?: Signature;
99
- }
100
- export interface HashMessageRequest extends RawRequest {
101
- method: "hash-message";
102
- params: {
103
- typedData: typedData.TypedData;
104
- };
105
- }
106
- export interface HashMessageResponse extends RawResponse {
107
- method: "hash-message";
108
- result?: string;
109
- }
110
- export interface VerifyMessageRequest extends RawRequest {
111
- method: "verify-message";
112
- params: {
113
- typedData: typedData.TypedData;
114
- signature: Signature;
115
- };
116
- }
117
- export interface VerifyMessageResponse extends RawResponse {
118
- method: "verify-message";
119
- result?: boolean;
120
- }
121
- export interface VerifyMessageHashRequest extends RawRequest {
122
- method: "verify-message-hash";
123
- params: {
124
- hash: BigNumberish;
125
- signature: Signature;
126
- };
127
- }
128
- export interface VerifyMessageHashResponse extends RawResponse {
129
- method: "verify-message-hash";
130
- result?: boolean;
131
- }
132
- export interface GetNonceRequest extends RawRequest {
133
- method: "get-nonce";
134
- }
135
- export interface GetNonceResponse extends RawResponse {
136
- method: "get-nonce";
137
- result?: string;
138
- }
139
- export declare type RawRequest = {
140
- origin?: string;
141
- method: string;
142
- params?: object | any[];
143
- };
144
- export declare type Request = RawRequest | ProbeRequest | ConnectRequest | DeployContractRequest | EstimateFeeRequest | ExecuteRequest | SignMessageRequest | HashMessageRequest | VerifyMessageHashRequest | VerifyMessageRequest | GetNonceRequest;
145
- export declare type RawResponse = {
146
- result?: any;
147
- error?: unknown;
148
- };
149
- export declare type Response = RawResponse | ProbeResponse | DeployContractResponse | EstimateFeeResponse | ConnectResponse | SignMessageResponse | HashMessageResponse | VerifyMessageHashResponse | VerifyMessageResponse | GetNonceResponse;
150
- //# sourceMappingURL=types.d.ts.map
1
+ import { DeployContractPayload, DeployContractResponse as StarknetDeployContractResponse, Abi, Call, InvocationsDetails, typedData, InvokeFunctionResponse, Signature, Invocation } from "starknet";
2
+ import { BigNumberish } from "starknet/dist/utils/number";
3
+ import { EstimateFee } from "starknet/types/account";
4
+ export declare type Approvals = {
5
+ [origin: string]: {
6
+ scopes: Scope[];
7
+ maxFee: BigNumberish;
8
+ };
9
+ };
10
+ export declare type Scope = {
11
+ target: string;
12
+ method?: string;
13
+ };
14
+ export interface ProbeRequest extends RawRequest {
15
+ method: "probe";
16
+ }
17
+ export interface ProbeResponse extends RawResponse {
18
+ method: "probe";
19
+ result?: {
20
+ address?: string;
21
+ scopes?: Scope[];
22
+ };
23
+ }
24
+ export interface ConnectRequest extends RawRequest {
25
+ method: "connect";
26
+ params: {
27
+ id: string;
28
+ scopes: Scope[];
29
+ };
30
+ }
31
+ export interface ConnectResponse extends RawResponse {
32
+ method: "connect";
33
+ result?: {
34
+ success: boolean;
35
+ address?: string;
36
+ scopes: Scope[];
37
+ };
38
+ }
39
+ export interface DeployContractRequest extends RawRequest {
40
+ method: "deploy-contract";
41
+ params: {
42
+ id: string;
43
+ payload: DeployContractPayload;
44
+ abi?: Abi;
45
+ };
46
+ }
47
+ export interface DeployContractResponse extends RawResponse {
48
+ method: "deploy-contract";
49
+ result?: StarknetDeployContractResponse;
50
+ }
51
+ export interface EstimateFeeRequest extends RawRequest {
52
+ method: "estimate-fee";
53
+ params: {
54
+ invocation: Invocation;
55
+ };
56
+ }
57
+ export interface EstimateFeeResponse extends RawResponse {
58
+ method: "estimate-fee";
59
+ result?: EstimateFee;
60
+ }
61
+ export interface ExecuteRequest extends RawRequest {
62
+ method: "execute";
63
+ params: {
64
+ id?: string;
65
+ transactions: Call | Call[];
66
+ abis?: Abi[];
67
+ transactionsDetail?: InvocationsDetails;
68
+ };
69
+ }
70
+ export interface ExecuteResponse extends RawResponse {
71
+ method: "execute";
72
+ result?: InvokeFunctionResponse;
73
+ scopes?: Scope[];
74
+ }
75
+ export interface SignTransactionRequest extends RawRequest {
76
+ method: "sign-transaction";
77
+ params: {
78
+ id: string;
79
+ transactions: Call | Call[];
80
+ abis?: Abi[];
81
+ transactionsDetail?: InvocationsDetails;
82
+ };
83
+ }
84
+ export interface SignTransactionResponse extends RawResponse {
85
+ method: "sign-transaction";
86
+ result?: Signature;
87
+ }
88
+ export interface SignMessageRequest extends RawRequest {
89
+ method: "sign-message";
90
+ params: {
91
+ id: string;
92
+ account?: string;
93
+ typedData: typedData.TypedData;
94
+ };
95
+ }
96
+ export interface SignMessageResponse extends RawResponse {
97
+ method: "sign-message";
98
+ result?: Signature;
99
+ }
100
+ export interface HashMessageRequest extends RawRequest {
101
+ method: "hash-message";
102
+ params: {
103
+ typedData: typedData.TypedData;
104
+ };
105
+ }
106
+ export interface HashMessageResponse extends RawResponse {
107
+ method: "hash-message";
108
+ result?: string;
109
+ }
110
+ export interface VerifyMessageRequest extends RawRequest {
111
+ method: "verify-message";
112
+ params: {
113
+ typedData: typedData.TypedData;
114
+ signature: Signature;
115
+ };
116
+ }
117
+ export interface VerifyMessageResponse extends RawResponse {
118
+ method: "verify-message";
119
+ result?: boolean;
120
+ }
121
+ export interface VerifyMessageHashRequest extends RawRequest {
122
+ method: "verify-message-hash";
123
+ params: {
124
+ hash: BigNumberish;
125
+ signature: Signature;
126
+ };
127
+ }
128
+ export interface VerifyMessageHashResponse extends RawResponse {
129
+ method: "verify-message-hash";
130
+ result?: boolean;
131
+ }
132
+ export interface GetNonceRequest extends RawRequest {
133
+ method: "get-nonce";
134
+ }
135
+ export interface GetNonceResponse extends RawResponse {
136
+ method: "get-nonce";
137
+ result?: string;
138
+ }
139
+ export declare type RawRequest = {
140
+ origin?: string;
141
+ method: string;
142
+ params?: object | any[];
143
+ };
144
+ export declare type Request = RawRequest | ProbeRequest | ConnectRequest | DeployContractRequest | EstimateFeeRequest | ExecuteRequest | SignMessageRequest | HashMessageRequest | VerifyMessageHashRequest | VerifyMessageRequest | GetNonceRequest;
145
+ export declare type RawResponse = {
146
+ result?: any;
147
+ error?: unknown;
148
+ };
149
+ export declare type Response = RawResponse | ProbeResponse | DeployContractResponse | EstimateFeeResponse | ConnectResponse | SignMessageResponse | HashMessageResponse | VerifyMessageHashResponse | VerifyMessageResponse | GetNonceResponse;
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,3 +1,2 @@
1
- import { Scope } from "./types";
2
- export declare function diff(a: Scope[], b: Scope[]): Scope[];
3
- //# sourceMappingURL=utils.d.ts.map
1
+ import { Scope } from "./types";
2
+ export declare function diff(a: Scope[], b: Scope[]): Scope[];
package/lib/utils.js ADDED
@@ -0,0 +1,16 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import equal from "fast-deep-equal";
11
+ export function diff(a, b) {
12
+ return a.reduce(function (prev, scope) {
13
+ return b.some(function (approval) { return equal(approval, scope); }) ? prev : __spreadArray(__spreadArray([], prev, true), [scope], false);
14
+ }, []);
15
+ }
16
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAIpC,MAAM,UAAU,IAAI,CAAC,CAAU,EAAE,CAAU;IACvC,OAAO,CAAC,CAAC,MAAM,CACX,UAAC,IAAI,EAAE,KAAK;QACR,OAAA,CAAC,CAAC,IAAI,CAAC,UAAC,QAAQ,IAAK,OAAA,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAtB,CAAsB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,iCAAK,IAAI,UAAE,KAAK,SAAC;IAAtE,CAAsE,EAC1E,EAAa,CAChB,CAAC;AACN,CAAC"}
@@ -1,17 +1,16 @@
1
- import { Abi, Invocation, InvocationsSignerDetails, Signature, SignerInterface, typedData } from "starknet";
2
- declare type Assertion = PublicKeyCredential & {
3
- response: AuthenticatorAssertionResponse;
4
- };
5
- export declare class WebauthnSigner implements SignerInterface {
6
- private credentialId;
7
- private publicKey;
8
- constructor(credentialId: string, publicKey: string);
9
- getPubKey(): Promise<string>;
10
- sign(hash: string): Promise<Assertion>;
11
- formatAssertion(assertion: Assertion): Signature;
12
- hashTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): string;
13
- signTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
14
- signMessage(td: typedData.TypedData, accountAddress: string): Promise<Signature>;
15
- }
16
- export {};
17
- //# sourceMappingURL=webauthn.d.ts.map
1
+ import { Abi, Invocation, InvocationsSignerDetails, Signature, SignerInterface, typedData } from "starknet";
2
+ declare type Assertion = PublicKeyCredential & {
3
+ response: AuthenticatorAssertionResponse;
4
+ };
5
+ export declare class WebauthnSigner implements SignerInterface {
6
+ private credentialId;
7
+ private publicKey;
8
+ constructor(credentialId: string, publicKey: string);
9
+ getPubKey(): Promise<string>;
10
+ sign(hash: string): Promise<Assertion>;
11
+ formatAssertion(assertion: Assertion): Signature;
12
+ hashTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): string;
13
+ signTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
14
+ signMessage(td: typedData.TypedData, accountAddress: string): Promise<Signature>;
15
+ }
16
+ export {};
@@ -0,0 +1,191 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
+ if (ar || !(i in from)) {
40
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
+ ar[i] = from[i];
42
+ }
43
+ }
44
+ return to.concat(ar || Array.prototype.slice.call(from));
45
+ };
46
+ import { transaction, hash, typedData, number } from "starknet";
47
+ import base64url from "base64url";
48
+ var BASE = number.toBN(2).pow(86);
49
+ function split(n) {
50
+ var x = n.mod(BASE);
51
+ var y = n.div(BASE).mod(BASE);
52
+ var z = n.div(BASE).div(BASE);
53
+ return { x: x, y: y, z: z };
54
+ }
55
+ function convertUint8ArrayToWordArray(u8Array) {
56
+ var words = [], i = 0, len = u8Array.length;
57
+ while (i < len) {
58
+ words.push(((u8Array[i++] << 24) |
59
+ (u8Array[i++] << 16) |
60
+ (u8Array[i++] << 8) |
61
+ u8Array[i++]) >>>
62
+ 0);
63
+ }
64
+ return {
65
+ sigBytes: words.length * 4,
66
+ words: words,
67
+ };
68
+ }
69
+ var WebauthnSigner = /** @class */ (function () {
70
+ function WebauthnSigner(credentialId, publicKey) {
71
+ this.credentialId = credentialId;
72
+ this.publicKey = publicKey;
73
+ }
74
+ WebauthnSigner.prototype.getPubKey = function () {
75
+ return __awaiter(this, void 0, void 0, function () {
76
+ return __generator(this, function (_a) {
77
+ return [2 /*return*/, this.publicKey];
78
+ });
79
+ });
80
+ };
81
+ WebauthnSigner.prototype.sign = function (hash) {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ var challenge;
84
+ return __generator(this, function (_a) {
85
+ switch (_a.label) {
86
+ case 0:
87
+ challenge = Buffer.from(hash.slice(2).padStart(64, "0").slice(0, 64), "hex");
88
+ return [4 /*yield*/, navigator.credentials.get({
89
+ publicKey: {
90
+ challenge: challenge,
91
+ timeout: 60000,
92
+ rpId: "cartridge.gg",
93
+ allowCredentials: [
94
+ {
95
+ type: "public-key",
96
+ id: base64url.toBuffer(this.credentialId),
97
+ },
98
+ ],
99
+ userVerification: "required",
100
+ },
101
+ })];
102
+ case 1: return [2 /*return*/, (_a.sent())];
103
+ }
104
+ });
105
+ });
106
+ };
107
+ WebauthnSigner.prototype.formatAssertion = function (assertion) {
108
+ var authenticatorDataBytes = new Uint8Array(assertion.response.authenticatorData);
109
+ var authenticatorDataRem = 4 - (authenticatorDataBytes.length % 4);
110
+ if (authenticatorDataRem == 4) {
111
+ authenticatorDataRem = 0;
112
+ }
113
+ var authenticatorDataWords = convertUint8ArrayToWordArray(authenticatorDataBytes).words;
114
+ var clientDataJSONBytes = new Uint8Array(assertion.response.clientDataJSON);
115
+ var clientDataJSONRem = 4 - (clientDataJSONBytes.length % 4);
116
+ if (clientDataJSONRem == 4) {
117
+ clientDataJSONRem = 0;
118
+ }
119
+ var clientDataWords = convertUint8ArrayToWordArray(clientDataJSONBytes).words;
120
+ // Convert signature from ASN.1 sequence to "raw" format
121
+ var usignature = new Uint8Array(assertion.response.signature);
122
+ var rStart = usignature[4] === 0 ? 5 : 4;
123
+ var rEnd = rStart + 32;
124
+ var sStart = usignature[rEnd + 2] === 0 ? rEnd + 3 : rEnd + 2;
125
+ var r = number.toBN("0x" + Buffer.from(usignature.slice(rStart, rEnd)).toString("hex"));
126
+ var s = number.toBN("0x" + Buffer.from(usignature.slice(sStart)).toString("hex"));
127
+ var _a = split(r), r0 = _a.x, r1 = _a.y, r2 = _a.z;
128
+ var _b = split(s), s0 = _b.x, s1 = _b.y, s2 = _b.z;
129
+ return __spreadArray(__spreadArray(__spreadArray([
130
+ "0",
131
+ r0.toString(),
132
+ r1.toString(),
133
+ r2.toString(),
134
+ s0.toString(),
135
+ s1.toString(),
136
+ s2.toString(),
137
+ "9",
138
+ "0",
139
+ "".concat(clientDataWords.length),
140
+ "".concat(clientDataJSONRem)
141
+ ], clientDataWords.map(function (word) { return "".concat(word); }), true), [
142
+ "".concat(authenticatorDataWords.length),
143
+ "".concat(authenticatorDataRem)
144
+ ], false), authenticatorDataWords.map(function (word) { return "".concat(word); }), true);
145
+ };
146
+ WebauthnSigner.prototype.hashTransaction = function (transactions, transactionsDetail, abis) {
147
+ if (abis && abis.length !== transactions.length) {
148
+ throw new Error("ABI must be provided for each transaction or no transaction");
149
+ }
150
+ // now use abi to display decoded data somewhere, but as this signer is headless, we can't do that
151
+ var calldata = transaction.fromCallsToExecuteCalldataWithNonce(transactions, transactionsDetail.nonce);
152
+ return hash.calculcateTransactionHash(transactionsDetail.walletAddress, transactionsDetail.version, hash.getSelectorFromName("__execute__"), calldata, transactionsDetail.maxFee, transactionsDetail.chainId);
153
+ };
154
+ WebauthnSigner.prototype.signTransaction = function (transactions, transactionsDetail, abis) {
155
+ return __awaiter(this, void 0, void 0, function () {
156
+ var calldata, msgHash, assertion;
157
+ return __generator(this, function (_a) {
158
+ switch (_a.label) {
159
+ case 0:
160
+ if (abis && abis.length !== transactions.length) {
161
+ throw new Error("ABI must be provided for each transaction or no transaction");
162
+ }
163
+ calldata = transaction.fromCallsToExecuteCalldataWithNonce(transactions, transactionsDetail.nonce);
164
+ msgHash = hash.calculcateTransactionHash(transactionsDetail.walletAddress, transactionsDetail.version, hash.getSelectorFromName("__execute__"), calldata, transactionsDetail.maxFee, transactionsDetail.chainId);
165
+ return [4 /*yield*/, this.sign(msgHash)];
166
+ case 1:
167
+ assertion = _a.sent();
168
+ return [2 /*return*/, this.formatAssertion(assertion)];
169
+ }
170
+ });
171
+ });
172
+ };
173
+ WebauthnSigner.prototype.signMessage = function (td, accountAddress) {
174
+ return __awaiter(this, void 0, void 0, function () {
175
+ var msgHash, assertion;
176
+ return __generator(this, function (_a) {
177
+ switch (_a.label) {
178
+ case 0:
179
+ msgHash = typedData.getMessageHash(td, accountAddress);
180
+ return [4 /*yield*/, this.sign(msgHash)];
181
+ case 1:
182
+ assertion = _a.sent();
183
+ return [2 /*return*/, this.formatAssertion(assertion)];
184
+ }
185
+ });
186
+ });
187
+ };
188
+ return WebauthnSigner;
189
+ }());
190
+ export { WebauthnSigner };
191
+ //# sourceMappingURL=webauthn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webauthn.js","sourceRoot":"","sources":["../src/webauthn.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAML,WAAW,EACX,IAAI,EACJ,SAAS,EACT,MAAM,EACP,MAAM,UAAU,CAAC;AAClB,OAAO,SAAS,MAAM,WAAW,CAAC;AAGlC,IAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAMpC,SAAS,KAAK,CAAC,CAAe;IAC5B,IAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtB,IAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,IAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,EAAE,CAAC,GAAA,EAAE,CAAC,GAAA,EAAE,CAAC,GAAA,EAAE,CAAC;AACrB,CAAC;AAED,SAAS,4BAA4B,CAAC,OAAmB;IACvD,IAAI,KAAK,GAAG,EAAE,EACZ,CAAC,GAAG,CAAC,EACL,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAEvB,OAAO,CAAC,GAAG,GAAG,EAAE;QACd,K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 +1,16 @@
1
1
  {
2
2
  "name": "@cartridge/controller",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Cartridge Controller",
5
- "main": "dist/index.js",
6
- "module": "dist/index.es.js",
7
- "types": "dist/index.d.ts",
5
+ "main": "lib",
6
+ "types": "lib",
7
+ "type": "module",
8
8
  "scripts": {
9
- "build": "rimraf ./dist && rollup -c",
10
- "dev": "rollup -c -w",
11
- "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
12
- "test:watch": "jest --watchAll",
13
- "test": "jest --ci --runInBand"
9
+ "build": "tsc",
10
+ "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\""
14
11
  },
15
12
  "files": [
16
- "dist"
13
+ "lib"
17
14
  ],
18
15
  "devDependencies": {
19
16
  "@rollup/plugin-replace": "^4.0.0",
@@ -26,24 +23,7 @@
26
23
  "ts-jest": "^26.5.1",
27
24
  "ts-node": "^10.4.0",
28
25
  "tslib": "^2.3.1",
29
- "typescript": "^4.5.4"
30
- },
31
- "jest": {
32
- "setupFiles": [],
33
- "moduleFileExtensions": [
34
- "ts",
35
- "js",
36
- "json"
37
- ],
38
- "roots": [
39
- "src",
40
- "tests"
41
- ],
42
- "transform": {
43
- "^.+\\.tsx?$": "ts-jest"
44
- },
45
- "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
46
- "moduleNameMapper": {}
26
+ "typescript": "4.8.2"
47
27
  },
48
28
  "dependencies": {
49
29
  "base64url": "^3.0.1",
@@ -1 +0,0 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,GAAG,EACH,IAAI,EACJ,sBAAsB,IAAI,8BAA8B,EACxD,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,MAAM,EACN,QAAQ,EACR,UAAU,EACV,eAAe,EACf,sBAAsB,EACvB,MAAM,UAAU,CA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