@iota/wallet-standard 0.1.0

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +201 -0
  3. package/README.md +6 -0
  4. package/dist/cjs/chains.d.ts +7 -0
  5. package/dist/cjs/chains.js +30 -0
  6. package/dist/cjs/chains.js.map +7 -0
  7. package/dist/cjs/detect.d.ts +7 -0
  8. package/dist/cjs/detect.js +37 -0
  9. package/dist/cjs/detect.js.map +7 -0
  10. package/dist/cjs/features/index.d.ts +19 -0
  11. package/dist/cjs/features/index.js +22 -0
  12. package/dist/cjs/features/index.js.map +7 -0
  13. package/dist/cjs/features/iotaSignAndExecuteTransactionBlock.d.ts +31 -0
  14. package/dist/cjs/features/iotaSignAndExecuteTransactionBlock.js +17 -0
  15. package/dist/cjs/features/iotaSignAndExecuteTransactionBlock.js.map +7 -0
  16. package/dist/cjs/features/iotaSignMessage.d.ts +38 -0
  17. package/dist/cjs/features/iotaSignMessage.js +17 -0
  18. package/dist/cjs/features/iotaSignMessage.js.map +7 -0
  19. package/dist/cjs/features/iotaSignPersonalMessage.d.ts +28 -0
  20. package/dist/cjs/features/iotaSignPersonalMessage.js +17 -0
  21. package/dist/cjs/features/iotaSignPersonalMessage.js.map +7 -0
  22. package/dist/cjs/features/iotaSignTransactionBlock.d.ts +30 -0
  23. package/dist/cjs/features/iotaSignTransactionBlock.js +17 -0
  24. package/dist/cjs/features/iotaSignTransactionBlock.js.map +7 -0
  25. package/dist/cjs/index.d.ts +5 -0
  26. package/dist/cjs/index.js +22 -0
  27. package/dist/cjs/index.js.map +7 -0
  28. package/dist/cjs/package.json +5 -0
  29. package/dist/cjs/wallet.d.ts +11 -0
  30. package/dist/cjs/wallet.js +17 -0
  31. package/dist/cjs/wallet.js.map +7 -0
  32. package/dist/esm/chains.d.ts +7 -0
  33. package/dist/esm/chains.js +10 -0
  34. package/dist/esm/chains.js.map +7 -0
  35. package/dist/esm/detect.d.ts +7 -0
  36. package/dist/esm/detect.js +17 -0
  37. package/dist/esm/detect.js.map +7 -0
  38. package/dist/esm/features/index.d.ts +19 -0
  39. package/dist/esm/features/index.js +5 -0
  40. package/dist/esm/features/index.js.map +7 -0
  41. package/dist/esm/features/iotaSignAndExecuteTransactionBlock.d.ts +31 -0
  42. package/dist/esm/features/iotaSignAndExecuteTransactionBlock.js +1 -0
  43. package/dist/esm/features/iotaSignAndExecuteTransactionBlock.js.map +7 -0
  44. package/dist/esm/features/iotaSignMessage.d.ts +38 -0
  45. package/dist/esm/features/iotaSignMessage.js +1 -0
  46. package/dist/esm/features/iotaSignMessage.js.map +7 -0
  47. package/dist/esm/features/iotaSignPersonalMessage.d.ts +28 -0
  48. package/dist/esm/features/iotaSignPersonalMessage.js +1 -0
  49. package/dist/esm/features/iotaSignPersonalMessage.js.map +7 -0
  50. package/dist/esm/features/iotaSignTransactionBlock.d.ts +30 -0
  51. package/dist/esm/features/iotaSignTransactionBlock.js +1 -0
  52. package/dist/esm/features/iotaSignTransactionBlock.js.map +7 -0
  53. package/dist/esm/index.d.ts +5 -0
  54. package/dist/esm/index.js +5 -0
  55. package/dist/esm/index.js.map +7 -0
  56. package/dist/esm/package.json +5 -0
  57. package/dist/esm/wallet.d.ts +11 -0
  58. package/dist/esm/wallet.js +1 -0
  59. package/dist/esm/wallet.js.map +7 -0
  60. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  61. package/dist/tsconfig.tsbuildinfo +1 -0
  62. package/package.json +41 -0
  63. package/src/chains.ts +16 -0
  64. package/src/detect.ts +32 -0
  65. package/src/features/index.ts +50 -0
  66. package/src/features/iotaSignAndExecuteTransactionBlock.ts +46 -0
  67. package/src/features/iotaSignMessage.ts +47 -0
  68. package/src/features/iotaSignPersonalMessage.ts +39 -0
  69. package/src/features/iotaSignTransactionBlock.ts +41 -0
  70. package/src/index.ts +10 -0
  71. package/src/wallet.ts +16 -0
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@iota/wallet-standard",
3
+ "version": "0.1.0",
4
+ "description": "A suite of standard utilities for implementing wallets based on the Wallet Standard.",
5
+ "license": "Apache-2.0",
6
+ "author": "IOTA Foundation <contact@iota.org>",
7
+ "type": "commonjs",
8
+ "main": "./dist/cjs/index.js",
9
+ "module": "./dist/esm/index.js",
10
+ "types": "./dist/cjs/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/esm/index.js",
14
+ "require": "./dist/cjs/index.js"
15
+ }
16
+ },
17
+ "sideEffects": false,
18
+ "files": [
19
+ "CHANGELOG.md",
20
+ "dist",
21
+ "src"
22
+ ],
23
+ "dependencies": {
24
+ "@wallet-standard/core": "1.0.3",
25
+ "@iota/iota-sdk": "0.1.0"
26
+ },
27
+ "devDependencies": {
28
+ "typescript": "^5.3.3",
29
+ "@iota/build-scripts": "0.0.0"
30
+ },
31
+ "scripts": {
32
+ "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
33
+ "build": "build-package",
34
+ "prettier:check": "prettier -c --ignore-unknown --ignore-path=../../.prettierignore --ignore-path=.prettierignore .",
35
+ "prettier:fix": "prettier -w --ignore-unknown --ignore-path=../../.prettierignore --ignore-path=.prettierignore .",
36
+ "eslint:check": "eslint --max-warnings=0 .",
37
+ "eslint:fix": "pnpm run eslint:check --fix",
38
+ "lint": "pnpm run eslint:check && pnpm run prettier:check",
39
+ "lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix"
40
+ }
41
+ }
package/src/chains.ts ADDED
@@ -0,0 +1,16 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import { getAllNetworks } from '@iota/iota-sdk/client';
6
+ import type { IdentifierString } from '@wallet-standard/core';
7
+
8
+ export const SUPPORTED_CHAINS = Object.values(getAllNetworks()).map((network) => network.chain);
9
+
10
+ /**
11
+ * Utility that returns whether or not a chain identifier is a supported chain.
12
+ * @param chain a chain identifier in the form of `${string}:{$string}`
13
+ */
14
+ export function isSupportedChain(chain: IdentifierString): boolean {
15
+ return SUPPORTED_CHAINS.includes(chain);
16
+ }
package/src/detect.ts ADDED
@@ -0,0 +1,32 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import type { Wallet, WalletWithFeatures } from '@wallet-standard/core';
6
+
7
+ import type { MinimallyRequiredFeatures, WalletWithIotaFeatures } from './features/index.js';
8
+
9
+ // These features are absolutely required for wallets to function in the Iota ecosystem.
10
+ // Eventually, as wallets have more consistent support of features, we may want to extend this list.
11
+ const REQUIRED_FEATURES: (keyof MinimallyRequiredFeatures)[] = [
12
+ 'standard:connect',
13
+ 'standard:events',
14
+ ];
15
+
16
+ /** @deprecated Use isWalletWithRequiredFeatureSet instead since it provides more accurate typing! */
17
+ export function isWalletWithIotaFeatures(
18
+ wallet: Wallet,
19
+ /** Extra features that are required to be present, in addition to the expected feature set. */
20
+ features: string[] = [],
21
+ ): wallet is WalletWithIotaFeatures {
22
+ return [...REQUIRED_FEATURES, ...features].every((feature) => feature in wallet.features);
23
+ }
24
+
25
+ export function isWalletWithRequiredFeatureSet<AdditionalFeatures extends Wallet['features']>(
26
+ wallet: Wallet,
27
+ additionalFeatures: (keyof AdditionalFeatures)[] = [],
28
+ ): wallet is WalletWithFeatures<MinimallyRequiredFeatures & AdditionalFeatures> {
29
+ return [...REQUIRED_FEATURES, ...additionalFeatures].every(
30
+ (feature) => feature in wallet.features,
31
+ );
32
+ }
@@ -0,0 +1,50 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import type {
6
+ IdentifierRecord,
7
+ StandardConnectFeature,
8
+ StandardDisconnectFeature,
9
+ StandardEventsFeature,
10
+ WalletWithFeatures,
11
+ } from '@wallet-standard/core';
12
+
13
+ import type { IotaSignAndExecuteTransactionBlockFeature } from './iotaSignAndExecuteTransactionBlock.js';
14
+ import type { IotaSignMessageFeature } from './iotaSignMessage.js';
15
+ import type { IotaSignPersonalMessageFeature } from './iotaSignPersonalMessage.js';
16
+ import type { IotaSignTransactionBlockFeature } from './iotaSignTransactionBlock.js';
17
+
18
+ /**
19
+ * Wallet Standard features that are unique to Iota, and that all Iota wallets are expected to implement.
20
+ */
21
+ export type IotaFeatures = IotaSignTransactionBlockFeature &
22
+ IotaSignAndExecuteTransactionBlockFeature &
23
+ IotaSignPersonalMessageFeature &
24
+ // This deprecated feature should be removed once wallets update to the new method:
25
+ Partial<IotaSignMessageFeature>;
26
+
27
+ export type WalletWithIotaFeatures = WalletWithFeatures<
28
+ StandardConnectFeature &
29
+ StandardEventsFeature &
30
+ IotaFeatures &
31
+ // Disconnect is an optional feature:
32
+ Partial<StandardDisconnectFeature>
33
+ >;
34
+
35
+ /**
36
+ * Represents a wallet with the absolute minimum feature set required to function in the Iota ecosystem.
37
+ */
38
+ export type WalletWithRequiredFeatures = WalletWithFeatures<
39
+ MinimallyRequiredFeatures &
40
+ Partial<IotaFeatures> &
41
+ Partial<StandardDisconnectFeature> &
42
+ IdentifierRecord<unknown>
43
+ >;
44
+
45
+ export type MinimallyRequiredFeatures = StandardConnectFeature & StandardEventsFeature;
46
+
47
+ export * from './iotaSignMessage.js';
48
+ export * from './iotaSignTransactionBlock.js';
49
+ export * from './iotaSignAndExecuteTransactionBlock.js';
50
+ export * from './iotaSignPersonalMessage.js';
@@ -0,0 +1,46 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import type {
6
+ ExecuteTransactionRequestType,
7
+ IotaTransactionBlockResponse,
8
+ IotaTransactionBlockResponseOptions,
9
+ } from '@iota/iota-sdk/client';
10
+
11
+ import type { IotaSignTransactionBlockInput } from './iotaSignTransactionBlock.js';
12
+
13
+ /** The latest API version of the signAndExecuteTransactionBlock API. */
14
+ export type IotaSignAndExecuteTransactionBlockVersion = '1.0.0';
15
+
16
+ /**
17
+ * A Wallet Standard feature for signing a transaction, and submitting it to the
18
+ * network. The wallet is expected to submit the transaction to the network via RPC,
19
+ * and return the transaction response.
20
+ */
21
+ export type IotaSignAndExecuteTransactionBlockFeature = {
22
+ /** Namespace for the feature. */
23
+ 'iota:signAndExecuteTransactionBlock': {
24
+ /** Version of the feature API. */
25
+ version: IotaSignAndExecuteTransactionBlockVersion;
26
+ signAndExecuteTransactionBlock: IotaSignAndExecuteTransactionBlockMethod;
27
+ };
28
+ };
29
+
30
+ export type IotaSignAndExecuteTransactionBlockMethod = (
31
+ input: IotaSignAndExecuteTransactionBlockInput,
32
+ ) => Promise<IotaSignAndExecuteTransactionBlockOutput>;
33
+
34
+ /** Input for signing and sending transactions. */
35
+ export interface IotaSignAndExecuteTransactionBlockInput extends IotaSignTransactionBlockInput {
36
+ /**
37
+ * `WaitForEffectsCert` or `WaitForLocalExecution`, see details in `ExecuteTransactionRequestType`.
38
+ * Defaults to `WaitForLocalExecution` if options.showEffects or options.showEvents is true
39
+ */
40
+ requestType?: ExecuteTransactionRequestType;
41
+ /** specify which fields to return (e.g., transaction, effects, events, etc). By default, only the transaction digest will be returned. */
42
+ options?: IotaTransactionBlockResponseOptions;
43
+ }
44
+
45
+ /** Output of signing and sending transactions. */
46
+ export interface IotaSignAndExecuteTransactionBlockOutput extends IotaTransactionBlockResponse {}
@@ -0,0 +1,47 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import type { WalletAccount } from '@wallet-standard/core';
6
+
7
+ /**
8
+ * The latest API version of the signMessage API.
9
+ * @deprecated Wallets can still implement this method for compatibility, but this has been replaced by the `iota:signPersonalMessage` feature
10
+ */
11
+ export type IotaSignMessageVersion = '1.0.0';
12
+
13
+ /**
14
+ * A Wallet Standard feature for signing a personal message, and returning the
15
+ * message bytes that were signed, and message signature.
16
+ *
17
+ * @deprecated Wallets can still implement this method for compatibility, but this has been replaced by the `iota:signPersonalMessage` feature
18
+ */
19
+ export type IotaSignMessageFeature = {
20
+ /** Namespace for the feature. */
21
+ 'iota:signMessage': {
22
+ /** Version of the feature API. */
23
+ version: IotaSignMessageVersion;
24
+ signMessage: IotaSignMessageMethod;
25
+ };
26
+ };
27
+
28
+ /** @deprecated Wallets can still implement this method for compatibility, but this has been replaced by the `iota:signPersonalMessage` feature */
29
+ export type IotaSignMessageMethod = (input: IotaSignMessageInput) => Promise<IotaSignMessageOutput>;
30
+
31
+ /**
32
+ * Input for signing messages.
33
+ * @deprecated Wallets can still implement this method for compatibility, but this has been replaced by the `iota:signPersonalMessage` feature
34
+ */
35
+ export interface IotaSignMessageInput {
36
+ message: Uint8Array;
37
+ account: WalletAccount;
38
+ }
39
+
40
+ /**
41
+ * Output of signing messages.
42
+ * @deprecated Wallets can still implement this method for compatibility, but this has been replaced by the `iota:signPersonalMessage` feature
43
+ */
44
+ export interface IotaSignMessageOutput {
45
+ messageBytes: string;
46
+ signature: string;
47
+ }
@@ -0,0 +1,39 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import type { WalletAccount } from '@wallet-standard/core';
6
+
7
+ /** The latest API version of the signPersonalMessage API. */
8
+ export type IotaSignPersonalMessageVersion = '1.0.0';
9
+
10
+ /**
11
+ * A Wallet Standard feature for signing a personal message, and returning the
12
+ * message bytes that were signed, and message signature.
13
+ */
14
+ export type IotaSignPersonalMessageFeature = {
15
+ /** Namespace for the feature. */
16
+ 'iota:signPersonalMessage': {
17
+ /** Version of the feature API. */
18
+ version: IotaSignPersonalMessageVersion;
19
+ signPersonalMessage: IotaSignPersonalMessageMethod;
20
+ };
21
+ };
22
+
23
+ export type IotaSignPersonalMessageMethod = (
24
+ input: IotaSignPersonalMessageInput,
25
+ ) => Promise<IotaSignPersonalMessageOutput>;
26
+
27
+ /** Input for signing personal messages. */
28
+ export interface IotaSignPersonalMessageInput {
29
+ message: Uint8Array;
30
+ account: WalletAccount;
31
+ }
32
+
33
+ /** Output of signing personal messages. */
34
+ export interface IotaSignPersonalMessageOutput extends SignedPersonalMessage {}
35
+
36
+ export interface SignedPersonalMessage {
37
+ bytes: string;
38
+ signature: string;
39
+ }
@@ -0,0 +1,41 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import type { TransactionBlock } from '@iota/iota-sdk/transactions';
6
+ import type { IdentifierString, WalletAccount } from '@wallet-standard/core';
7
+
8
+ /** The latest API version of the signTransactionBlock API. */
9
+ export type IotaSignTransactionBlockVersion = '1.0.0';
10
+
11
+ /**
12
+ * A Wallet Standard feature for signing a transaction, and returning the
13
+ * serialized transaction and transaction signature.
14
+ */
15
+ export type IotaSignTransactionBlockFeature = {
16
+ /** Namespace for the feature. */
17
+ 'iota:signTransactionBlock': {
18
+ /** Version of the feature API. */
19
+ version: IotaSignTransactionBlockVersion;
20
+ signTransactionBlock: IotaSignTransactionBlockMethod;
21
+ };
22
+ };
23
+
24
+ export type IotaSignTransactionBlockMethod = (
25
+ input: IotaSignTransactionBlockInput,
26
+ ) => Promise<IotaSignTransactionBlockOutput>;
27
+
28
+ /** Input for signing transactions. */
29
+ export interface IotaSignTransactionBlockInput {
30
+ transactionBlock: TransactionBlock;
31
+ account: WalletAccount;
32
+ chain: IdentifierString;
33
+ }
34
+
35
+ /** Output of signing transactions. */
36
+ export interface IotaSignTransactionBlockOutput extends SignedTransactionBlock {}
37
+
38
+ export interface SignedTransactionBlock {
39
+ transactionBlockBytes: string;
40
+ signature: string;
41
+ }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ export * from '@wallet-standard/core';
6
+
7
+ export type { Wallet } from './wallet.js';
8
+ export * from './features/index.js';
9
+ export * from './detect.js';
10
+ export * from './chains.js';
package/src/wallet.ts ADDED
@@ -0,0 +1,16 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ declare module '@wallet-standard/core' {
6
+ export interface Wallet {
7
+ /**
8
+ * Unique identifier of the Wallet.
9
+ *
10
+ * If not provided, the wallet name will be used as the identifier.
11
+ */
12
+ readonly id?: string;
13
+ }
14
+ }
15
+
16
+ export type { Wallet } from '@wallet-standard/core';