@iota/wallet-standard 0.0.0-dev-20251015065834

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 (78) hide show
  1. package/CHANGELOG.md +189 -0
  2. package/LICENSE +201 -0
  3. package/README.md +8 -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 +3 -0
  8. package/dist/cjs/detect.js +33 -0
  9. package/dist/cjs/detect.js.map +7 -0
  10. package/dist/cjs/features/index.d.ts +20 -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/iotaReportTransactionEffects.d.ts +22 -0
  14. package/dist/cjs/features/iotaReportTransactionEffects.js +17 -0
  15. package/dist/cjs/features/iotaReportTransactionEffects.js.map +7 -0
  16. package/dist/cjs/features/iotaSignAndExecuteTransaction.d.ts +29 -0
  17. package/dist/cjs/features/iotaSignAndExecuteTransaction.js +17 -0
  18. package/dist/cjs/features/iotaSignAndExecuteTransaction.js.map +7 -0
  19. package/dist/cjs/features/iotaSignPersonalMessage.d.ts +30 -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/iotaSignTransaction.d.ts +34 -0
  23. package/dist/cjs/features/iotaSignTransaction.js +17 -0
  24. package/dist/cjs/features/iotaSignTransaction.js.map +7 -0
  25. package/dist/cjs/index.d.ts +6 -0
  26. package/dist/cjs/index.js +32 -0
  27. package/dist/cjs/index.js.map +7 -0
  28. package/dist/cjs/package.json +5 -0
  29. package/dist/cjs/types.d.ts +156 -0
  30. package/dist/cjs/types.js +17 -0
  31. package/dist/cjs/types.js.map +7 -0
  32. package/dist/cjs/wallet.d.ts +18 -0
  33. package/dist/cjs/wallet.js +41 -0
  34. package/dist/cjs/wallet.js.map +7 -0
  35. package/dist/esm/chains.d.ts +7 -0
  36. package/dist/esm/chains.js +10 -0
  37. package/dist/esm/chains.js.map +7 -0
  38. package/dist/esm/detect.d.ts +3 -0
  39. package/dist/esm/detect.js +13 -0
  40. package/dist/esm/detect.js.map +7 -0
  41. package/dist/esm/features/index.d.ts +20 -0
  42. package/dist/esm/features/index.js +5 -0
  43. package/dist/esm/features/index.js.map +7 -0
  44. package/dist/esm/features/iotaReportTransactionEffects.d.ts +22 -0
  45. package/dist/esm/features/iotaReportTransactionEffects.js +1 -0
  46. package/dist/esm/features/iotaReportTransactionEffects.js.map +7 -0
  47. package/dist/esm/features/iotaSignAndExecuteTransaction.d.ts +29 -0
  48. package/dist/esm/features/iotaSignAndExecuteTransaction.js +1 -0
  49. package/dist/esm/features/iotaSignAndExecuteTransaction.js.map +7 -0
  50. package/dist/esm/features/iotaSignPersonalMessage.d.ts +30 -0
  51. package/dist/esm/features/iotaSignPersonalMessage.js +1 -0
  52. package/dist/esm/features/iotaSignPersonalMessage.js.map +7 -0
  53. package/dist/esm/features/iotaSignTransaction.d.ts +34 -0
  54. package/dist/esm/features/iotaSignTransaction.js +1 -0
  55. package/dist/esm/features/iotaSignTransaction.js.map +7 -0
  56. package/dist/esm/index.d.ts +6 -0
  57. package/dist/esm/index.js +11 -0
  58. package/dist/esm/index.js.map +7 -0
  59. package/dist/esm/package.json +5 -0
  60. package/dist/esm/types.d.ts +156 -0
  61. package/dist/esm/types.js +1 -0
  62. package/dist/esm/types.js.map +7 -0
  63. package/dist/esm/wallet.d.ts +18 -0
  64. package/dist/esm/wallet.js +21 -0
  65. package/dist/esm/wallet.js.map +7 -0
  66. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  67. package/dist/tsconfig.tsbuildinfo +1 -0
  68. package/package.json +43 -0
  69. package/src/chains.ts +16 -0
  70. package/src/detect.ts +23 -0
  71. package/src/features/index.ts +49 -0
  72. package/src/features/iotaReportTransactionEffects.ts +31 -0
  73. package/src/features/iotaSignAndExecuteTransaction.ts +40 -0
  74. package/src/features/iotaSignPersonalMessage.ts +41 -0
  75. package/src/features/iotaSignTransaction.ts +44 -0
  76. package/src/index.ts +11 -0
  77. package/src/types.ts +173 -0
  78. package/src/wallet.ts +54 -0
@@ -0,0 +1,49 @@
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 { IotaReportTransactionEffectsFeature } from './iotaReportTransactionEffects.js';
14
+ import type { IotaSignAndExecuteTransactionFeature } from './iotaSignAndExecuteTransaction.js';
15
+ import type { IotaSignPersonalMessageFeature } from './iotaSignPersonalMessage.js';
16
+ import type { IotaSignTransactionFeature } from './iotaSignTransaction.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 = IotaSignPersonalMessageFeature &
22
+ IotaSignAndExecuteTransactionFeature &
23
+ IotaSignTransactionFeature &
24
+ Partial<IotaReportTransactionEffectsFeature>;
25
+
26
+ export type IotaWalletFeatures = StandardConnectFeature &
27
+ StandardEventsFeature &
28
+ IotaFeatures &
29
+ // Disconnect is an optional feature:
30
+ Partial<StandardDisconnectFeature>;
31
+
32
+ export type WalletWithIotaFeatures = WalletWithFeatures<IotaWalletFeatures>;
33
+
34
+ /**
35
+ * Represents a wallet with the absolute minimum feature set required to function in the IOTA ecosystem.
36
+ */
37
+ export type WalletWithRequiredFeatures = WalletWithFeatures<
38
+ MinimallyRequiredFeatures &
39
+ Partial<IotaFeatures> &
40
+ Partial<StandardDisconnectFeature> &
41
+ IdentifierRecord<unknown>
42
+ >;
43
+
44
+ export type MinimallyRequiredFeatures = StandardConnectFeature & StandardEventsFeature;
45
+
46
+ export * from './iotaSignTransaction.js';
47
+ export * from './iotaSignAndExecuteTransaction.js';
48
+ export * from './iotaSignPersonalMessage.js';
49
+ export * from './iotaReportTransactionEffects.js';
@@ -0,0 +1,31 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import type { IdentifierString, WalletAccount } from '@wallet-standard/core';
6
+
7
+ /**
8
+ * A Wallet Standard feature for reporting the effects of a transaction block executed by a dapp
9
+ * The feature allows wallets to updated their caches using the effects of the transaction
10
+ * executed outside of the wallet
11
+ */
12
+ export type IotaReportTransactionEffectsFeature = {
13
+ /** Namespace for the feature. */
14
+ 'iota:reportTransactionEffects': {
15
+ /** Version of the feature API. */
16
+ version: '1.0.0';
17
+ reportTransactionEffects: IotaReportTransactionEffectsMethod;
18
+ };
19
+ };
20
+
21
+ export type IotaReportTransactionEffectsMethod = (
22
+ input: IotaReportTransactionEffectsInput,
23
+ ) => Promise<void>;
24
+
25
+ /** Input for signing transactions. */
26
+ export interface IotaReportTransactionEffectsInput {
27
+ account: WalletAccount;
28
+ chain: IdentifierString;
29
+ /** Transaction effects as base64 encoded bcs. */
30
+ effects: string;
31
+ }
@@ -0,0 +1,40 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import type { IotaTransactionBlockResponseOptions } from '@iota/iota-sdk/client';
6
+ import type { SignedTransaction, IotaSignTransactionInput } from './iotaSignTransaction.js';
7
+
8
+ /** The latest API version of the signAndExecuteTransactionBlock API. */
9
+ export type IotaSignAndExecuteTransactionVersion = '2.0.0';
10
+
11
+ /**
12
+ * A Wallet Standard feature for signing a transaction, and submitting it to the
13
+ * network. The wallet is expected to submit the transaction to the network via RPC,
14
+ * and return the transaction response.
15
+ */
16
+ export type IotaSignAndExecuteTransactionFeature = {
17
+ /** Namespace for the feature. */
18
+ 'iota:signAndExecuteTransaction': {
19
+ /** Version of the feature API. */
20
+ version: IotaSignAndExecuteTransactionVersion;
21
+ signAndExecuteTransaction: IotaSignAndExecuteTransactionMethod;
22
+ };
23
+ };
24
+
25
+ export type IotaSignAndExecuteTransactionMethod = (
26
+ input: IotaSignAndExecuteTransactionInput,
27
+ ) => Promise<IotaSignAndExecuteTransactionOutput>;
28
+
29
+ /** Input for signing and sending transactions. */
30
+ export interface IotaSignAndExecuteTransactionInput extends IotaSignTransactionInput {
31
+ /** specify which fields to return (e.g., transaction, effects, events, etc). By default, only the transaction digest will be returned. */
32
+ options?: IotaTransactionBlockResponseOptions;
33
+ }
34
+
35
+ /** Output of signing and sending transactions. */
36
+ export interface IotaSignAndExecuteTransactionOutput extends SignedTransaction {
37
+ digest: string;
38
+ /** Transaction effects as base64 encoded bcs. */
39
+ effects: string;
40
+ }
@@ -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 { 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
+ /** Base64 encoded message bytes */
38
+ bytes: string;
39
+ /** Base64 encoded signature */
40
+ signature: string;
41
+ }
@@ -0,0 +1,44 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import type { IdentifierString, WalletAccount } from '@wallet-standard/core';
6
+
7
+ /** The latest API version of the signTransaction API. */
8
+ export type IotaSignTransactionVersion = '2.0.0';
9
+
10
+ /**
11
+ * A Wallet Standard feature for signing a transaction, and returning the
12
+ * serialized transaction and transaction signature.
13
+ */
14
+ export type IotaSignTransactionFeature = {
15
+ /** Namespace for the feature. */
16
+ 'iota:signTransaction': {
17
+ /** Version of the feature API. */
18
+ version: IotaSignTransactionVersion;
19
+ signTransaction: IotaSignTransactionMethod;
20
+ };
21
+ };
22
+
23
+ export type IotaSignTransactionMethod = (
24
+ input: IotaSignTransactionInput,
25
+ ) => Promise<SignedTransaction>;
26
+
27
+ /** Input for signing transactions. */
28
+ export interface IotaSignTransactionInput {
29
+ transaction: { toJSON: () => Promise<string> };
30
+ account: WalletAccount;
31
+ chain: IdentifierString;
32
+ signal?: AbortSignal;
33
+ }
34
+
35
+ /** Output of signing transactions. */
36
+
37
+ export interface SignedTransaction {
38
+ /** Transaction as base64 encoded bcs. */
39
+ bytes: string;
40
+ /** Base64 encoded signature */
41
+ signature: string;
42
+ }
43
+
44
+ export interface IotaSignTransactionOutput extends SignedTransaction {}
package/src/index.ts ADDED
@@ -0,0 +1,11 @@
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, signAndExecuteTransaction, signTransaction } from './wallet.js';
8
+ export * from './features/index.js';
9
+ export * from './detect.js';
10
+ export * from './chains.js';
11
+ export * from './types.js';
package/src/types.ts ADDED
@@ -0,0 +1,173 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ /** Contains data related to the gas payment for a Transaction */
6
+ export interface GasData {
7
+ /** The budget set for this transaction */
8
+ budget: string | number | null;
9
+ /** The gas price used for this transaction */
10
+ price: string | number | null;
11
+ /** The owner of the gas coins used to fund the transactions, this is either the sender or the gas sponsor */
12
+ owner: string | null;
13
+ /** The list of IOTA coins to fund the transaction */
14
+ payment: { objectId: string; version: string; digest: string }[] | null;
15
+ }
16
+
17
+ /**
18
+ * Represent the serialized state of a partially built Transaction
19
+ * This format is designed to support transactions that have not been fully build
20
+ * allowing most properties to be omitted or set to null. It also supports
21
+ * unresolved object references, unresolved pure values, and Transaction Intents.
22
+ */
23
+ export interface SerializedTransactionDataV2 {
24
+ version: 2;
25
+ /** The sender of the transaction */
26
+ sender: string | null | undefined;
27
+ /** The expiration of the transaction */
28
+ expiration: { Epoch: number } | { None: true } | null | undefined;
29
+ /** The gas data */
30
+ gasData: GasData;
31
+ /** The inputs to the transaction */
32
+ inputs: CallArg[];
33
+ /** The commands to execute */
34
+ commands: Command[];
35
+ /** Extra metadata for implementation specific use-cases */
36
+ extensions?: { [key: string]: unknown };
37
+ }
38
+
39
+ /**
40
+ * Represents an input to a Transaction, either as a fully resolved Object or Pure input
41
+ * or as an unresolved partial reference which needs to be resolved before the transaction
42
+ * can be serialized to bcs and executed.
43
+ */
44
+ export type CallArg =
45
+ | {
46
+ Object: ObjectArg;
47
+ }
48
+ | {
49
+ Pure: PureArg;
50
+ }
51
+ | {
52
+ UnresolvedPure: UnresolvedPureArg;
53
+ }
54
+ | {
55
+ UnresolvedObject: UnresolvedObjectArg;
56
+ };
57
+
58
+ export type ObjectArg =
59
+ | {
60
+ ImmOrOwnedObject: {
61
+ objectId: string;
62
+ version: string | number;
63
+ digest: string;
64
+ };
65
+ }
66
+ | {
67
+ SharedObject: {
68
+ objectId: string;
69
+ initialSharedVersion: string;
70
+ mutable: boolean;
71
+ };
72
+ }
73
+ | {
74
+ Receiving: {
75
+ objectId: string;
76
+ version: string | number;
77
+ digest: string;
78
+ };
79
+ };
80
+
81
+ export interface PureArg {
82
+ bytes: string;
83
+ }
84
+
85
+ /**
86
+ * Represents an un-serialized pure value.
87
+ * The correct bcs schema will need to be determined before this value can be serialized to bcs */
88
+ export interface UnresolvedPureArg {
89
+ value: unknown;
90
+ }
91
+
92
+ /**
93
+ * Represents an unresolved object reference. This allows objects to be referenced by only their ID.
94
+ * version and digest details may also be added to unresolved object references.
95
+ * To fully resolve a reference, the correct ObjectArg type needs to be determined based on the type of object,
96
+ * and how it used in the transaction (eg, is it used mutably if it's shared, and is it a receiving object if it's not shared)
97
+ */
98
+ export interface UnresolvedObjectArg {
99
+ objectId: string;
100
+ version?: string | null | undefined;
101
+ digest?: string | null | undefined;
102
+ initialSharedVersion?: string | null | undefined;
103
+ }
104
+
105
+ export type Argument =
106
+ | {
107
+ GasCoin: true;
108
+ }
109
+ | {
110
+ Input: number;
111
+ }
112
+ | {
113
+ Result: number;
114
+ }
115
+ | {
116
+ NestedResult: [number, number];
117
+ };
118
+
119
+ export type Command =
120
+ | {
121
+ MoveCall: {
122
+ package: string;
123
+ module: string;
124
+ function: string;
125
+ typeArguments: string[];
126
+ arguments: Argument[];
127
+ };
128
+ }
129
+ | {
130
+ TransferObjects: {
131
+ objects: Argument[];
132
+ address: Argument;
133
+ };
134
+ }
135
+ | {
136
+ SplitCoins: {
137
+ coin: Argument;
138
+ amounts: Argument[];
139
+ };
140
+ }
141
+ | {
142
+ MergeCoins: {
143
+ destination: Argument;
144
+ sources: Argument[];
145
+ };
146
+ }
147
+ | {
148
+ Publish: {
149
+ modules: string[];
150
+ dependencies: string[];
151
+ };
152
+ }
153
+ | {
154
+ MakeMoveVec: {
155
+ type: string | null;
156
+ elements: Argument[];
157
+ };
158
+ }
159
+ | {
160
+ Upgrade: {
161
+ modules: string[];
162
+ dependencies: string[];
163
+ package: string;
164
+ ticket: Argument;
165
+ };
166
+ }
167
+ | {
168
+ $Intent: {
169
+ name: string;
170
+ inputs: { [key: string]: Argument | Argument[] };
171
+ data: { [key: string]: unknown };
172
+ };
173
+ };
package/src/wallet.ts ADDED
@@ -0,0 +1,54 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // Modifications Copyright (c) 2024 IOTA Stiftung
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ import type { WalletWithFeatures } from '@wallet-standard/core';
6
+
7
+ import type {
8
+ IotaSignAndExecuteTransactionInput,
9
+ IotaSignTransactionInput,
10
+ IotaWalletFeatures,
11
+ } from './features/index.js';
12
+
13
+ declare module '@wallet-standard/core' {
14
+ export interface Wallet {
15
+ /**
16
+ * Unique identifier of the Wallet.
17
+ *
18
+ * If not provided, the wallet name will be used as the identifier.
19
+ */
20
+ readonly id?: string;
21
+ }
22
+
23
+ export interface StandardConnectOutput {
24
+ supportedIntents?: string[];
25
+ }
26
+ }
27
+
28
+ export type { Wallet } from '@wallet-standard/core';
29
+
30
+ export async function signAndExecuteTransaction(
31
+ wallet: WalletWithFeatures<Partial<IotaWalletFeatures>>,
32
+ input: IotaSignAndExecuteTransactionInput,
33
+ ) {
34
+ if (!wallet.features['iota:signAndExecuteTransaction']) {
35
+ throw new Error(
36
+ `Provided wallet (${wallet.name}) does not support the signAndExecuteTransaction feature.`,
37
+ );
38
+ }
39
+
40
+ return wallet.features['iota:signAndExecuteTransaction'].signAndExecuteTransaction(input);
41
+ }
42
+
43
+ export async function signTransaction(
44
+ wallet: WalletWithFeatures<Partial<IotaWalletFeatures>>,
45
+ input: IotaSignTransactionInput,
46
+ ) {
47
+ if (!wallet.features['iota:signTransaction']) {
48
+ throw new Error(
49
+ `Provided wallet (${wallet.name}) does not support the signTransaction feature.`,
50
+ );
51
+ }
52
+
53
+ return wallet.features['iota:signTransaction'].signTransaction(input);
54
+ }