@sovereign-sdk/signers 0.0.3 → 0.0.4
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 +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -5
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/snap.ts","../src/errors.ts"],"sourcesContent":["export * from \"./signer\";\nexport * from \"./snap\";\n","/// <reference path=\"./snap-env.d.ts\" />\n\nimport type { MetaMaskInpageProvider } from \"@metamask/providers\";\nimport { bytesToHex, hexToBytes } from \"@sovereign-sdk/utils\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/snap.ts","../src/errors.ts"],"sourcesContent":["export * from \"./signer\";\nexport * from \"./snap\";\n","/// <reference path=\"./snap-env.d.ts\" />\n\nimport type { MetaMaskInpageProvider } from \"@metamask/providers\";\nimport { bytesToHex, hexToBytes } from \"@sovereign-sdk/utils\";\nimport { SignerError } from \"./errors\";\nimport type { Signer, SignerOpt } from \"./signer\";\n\n/**\n * Options for initializing a MetaMask Snap signer.\n */\nexport type MetaMaskSnapSignerOpt = {\n /**\n * The {@link MetaMaskInpageProvider} to use for the signer.\n *\n * If not provided, the signer will attempt to use the global `window.ethereum` provider.\n */\n provider?: MetaMaskInpageProvider;\n /**\n * The snap ID to use for the signer.\n *\n * Defaults to `npm:@sovereign-sdk/metamask-snap`.\n * Can be changed to `local:localhost:8080` for local development.\n */\n snapId?: string;\n} & SignerOpt;\n\n/**\n * Create a new MetaMask Snap signer.\n *\n * @param options - The {@link MetaMaskSnapSignerOpt} options.\n * @returns A {@link Signer} implementation utilizing Sovereign's MetaMask Snap.\n */\nexport const newMetaMaskSnapSigner = ({\n curve,\n schema,\n snapId = \"npm:@sovereign-sdk/metamask-snap\",\n ...rest\n}: MetaMaskSnapSignerOpt): Signer => {\n const signerId = \"MetaMaskSnap\";\n const provider = rest.provider ?? window.ethereum;\n\n if (!provider) {\n throw new SignerError(\"Failed to find provider for signer\", signerId);\n }\n\n const assertSupported = async () => {\n try {\n await provider.request({\n method: \"wallet_getSnaps\",\n });\n } catch {\n throw new SignerError(\n \"Provider does not support MetaMask snaps\",\n signerId,\n );\n }\n };\n\n const path = 0;\n\n return {\n async publicKey() {\n await assertSupported();\n\n const args = {\n method: \"wallet_invokeSnap\",\n params: {\n snapId,\n request: {\n method: \"getPublicKey\",\n params: { path, curve },\n },\n },\n };\n // biome-ignore lint/suspicious/noExplicitAny: todo\n const { publicKey } = (await provider.request(args)) as any;\n\n return hexToBytes(publicKey);\n },\n async sign(message: Uint8Array) {\n await assertSupported();\n\n const args = {\n method: \"wallet_invokeSnap\",\n params: {\n snapId,\n request: {\n method: \"signTransaction\",\n params: { unsignedTxHex: bytesToHex(message), schema, curve, path },\n },\n },\n };\n // biome-ignore lint/suspicious/noExplicitAny: todo\n const { signature } = (await provider.request(args)) as any;\n\n return hexToBytes(signature);\n },\n };\n};\n","/**\n * An error that can be thrown by a signer.\n */\nexport class SignerError extends Error {\n public readonly signerId: string;\n\n /**\n * Create a new SignerError.\n *\n * @param message - The error message\n * @param signerId - The ID of the signer that threw the error\n */\n constructor(message: string, signerId: string) {\n super(`[${signerId}] ${message}`);\n\n this.signerId = signerId;\n this.name = this.constructor.name;\n this.stack = new Error().stack;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,mBAAuC;;;ACAhC,IAAM,cAAN,cAA0B,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASrC,YAAY,SAAiB,UAAkB;AAC7C,UAAM,IAAI,QAAQ,KAAK,OAAO,EAAE;AAEhC,SAAK,WAAW;AAChB,SAAK,OAAO,KAAK,YAAY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;AAElD,mBAAO,yBAAW,SAAS;AAAA,MAC7B;AAAA;AAAA,EACF;AACF;","names":["_a"]}
|
package/dist/index.mjs
CHANGED
|
@@ -41,7 +41,7 @@ import { bytesToHex, hexToBytes } from "@sovereign-sdk/utils";
|
|
|
41
41
|
var SignerError = class extends Error {
|
|
42
42
|
/**
|
|
43
43
|
* Create a new SignerError.
|
|
44
|
-
*
|
|
44
|
+
*
|
|
45
45
|
* @param message - The error message
|
|
46
46
|
* @param signerId - The ID of the signer that threw the error
|
|
47
47
|
*/
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/snap.ts","../src/errors.ts"],"sourcesContent":["/// <reference path=\"./snap-env.d.ts\" />\n\nimport type { MetaMaskInpageProvider } from \"@metamask/providers\";\nimport { bytesToHex, hexToBytes } from \"@sovereign-sdk/utils\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/snap.ts","../src/errors.ts"],"sourcesContent":["/// <reference path=\"./snap-env.d.ts\" />\n\nimport type { MetaMaskInpageProvider } from \"@metamask/providers\";\nimport { bytesToHex, hexToBytes } from \"@sovereign-sdk/utils\";\nimport { SignerError } from \"./errors\";\nimport type { Signer, SignerOpt } from \"./signer\";\n\n/**\n * Options for initializing a MetaMask Snap signer.\n */\nexport type MetaMaskSnapSignerOpt = {\n /**\n * The {@link MetaMaskInpageProvider} to use for the signer.\n *\n * If not provided, the signer will attempt to use the global `window.ethereum` provider.\n */\n provider?: MetaMaskInpageProvider;\n /**\n * The snap ID to use for the signer.\n *\n * Defaults to `npm:@sovereign-sdk/metamask-snap`.\n * Can be changed to `local:localhost:8080` for local development.\n */\n snapId?: string;\n} & SignerOpt;\n\n/**\n * Create a new MetaMask Snap signer.\n *\n * @param options - The {@link MetaMaskSnapSignerOpt} options.\n * @returns A {@link Signer} implementation utilizing Sovereign's MetaMask Snap.\n */\nexport const newMetaMaskSnapSigner = ({\n curve,\n schema,\n snapId = \"npm:@sovereign-sdk/metamask-snap\",\n ...rest\n}: MetaMaskSnapSignerOpt): Signer => {\n const signerId = \"MetaMaskSnap\";\n const provider = rest.provider ?? window.ethereum;\n\n if (!provider) {\n throw new SignerError(\"Failed to find provider for signer\", signerId);\n }\n\n const assertSupported = async () => {\n try {\n await provider.request({\n method: \"wallet_getSnaps\",\n });\n } catch {\n throw new SignerError(\n \"Provider does not support MetaMask snaps\",\n signerId,\n );\n }\n };\n\n const path = 0;\n\n return {\n async publicKey() {\n await assertSupported();\n\n const args = {\n method: \"wallet_invokeSnap\",\n params: {\n snapId,\n request: {\n method: \"getPublicKey\",\n params: { path, curve },\n },\n },\n };\n // biome-ignore lint/suspicious/noExplicitAny: todo\n const { publicKey } = (await provider.request(args)) as any;\n\n return hexToBytes(publicKey);\n },\n async sign(message: Uint8Array) {\n await assertSupported();\n\n const args = {\n method: \"wallet_invokeSnap\",\n params: {\n snapId,\n request: {\n method: \"signTransaction\",\n params: { unsignedTxHex: bytesToHex(message), schema, curve, path },\n },\n },\n };\n // biome-ignore lint/suspicious/noExplicitAny: todo\n const { signature } = (await provider.request(args)) as any;\n\n return hexToBytes(signature);\n },\n };\n};\n","/**\n * An error that can be thrown by a signer.\n */\nexport class SignerError extends Error {\n public readonly signerId: string;\n\n /**\n * Create a new SignerError.\n *\n * @param message - The error message\n * @param signerId - The ID of the signer that threw the error\n */\n constructor(message: string, signerId: string) {\n super(`[${signerId}] ${message}`);\n\n this.signerId = signerId;\n this.name = this.constructor.name;\n this.stack = new Error().stack;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAS,YAAY,kBAAkB;;;ACAhC,IAAM,cAAN,cAA0B,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASrC,YAAY,SAAiB,UAAkB;AAC7C,UAAM,IAAI,QAAQ,KAAK,OAAO,EAAE;AAEhC,SAAK,WAAW;AAChB,SAAK,OAAO,KAAK,YAAY;AAC7B,SAAK,Q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AAS;AAAA,MAC7B;AAAA;AAAA,EACF;AACF;","names":["_a"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sovereign-sdk/signers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Signer interface and default implementations for use with Sovereign SDK applications",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -19,13 +19,11 @@
|
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@metamask/providers": "^18.1.0",
|
|
22
|
-
"biome": "^0.3.3",
|
|
23
22
|
"tsup": "^8.3.0",
|
|
24
23
|
"typescript": "^5.6.3",
|
|
25
|
-
"vitest": "^
|
|
24
|
+
"vitest": "^3.0.5"
|
|
26
25
|
},
|
|
27
26
|
"peerDependencies": {
|
|
28
|
-
"biome": "^0.3.3",
|
|
29
27
|
"tsup": "^8.3.0",
|
|
30
28
|
"typescript": "^5.6.3"
|
|
31
29
|
},
|
|
@@ -33,7 +31,7 @@
|
|
|
33
31
|
"access": "public"
|
|
34
32
|
},
|
|
35
33
|
"dependencies": {
|
|
36
|
-
"@sovereign-sdk/utils": "^0.0.
|
|
34
|
+
"@sovereign-sdk/utils": "^0.0.3"
|
|
37
35
|
},
|
|
38
36
|
"scripts": {
|
|
39
37
|
"build": "tsup",
|