@dynamic-labs/waas-ton 4.51.0 → 4.52.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 (75) hide show
  1. package/CHANGELOG.md +6619 -0
  2. package/LICENSE +21 -0
  3. package/_virtual/_tslib.cjs +36 -0
  4. package/_virtual/_tslib.js +32 -0
  5. package/package.cjs +8 -0
  6. package/package.js +4 -0
  7. package/package.json +13 -6
  8. package/src/DynamicWaasTonConnectors.cjs +12 -0
  9. package/src/DynamicWaasTonConnectors.d.ts +2 -0
  10. package/src/DynamicWaasTonConnectors.js +8 -0
  11. package/src/connector/DynamicWaasTonConnector.cjs +282 -0
  12. package/src/connector/DynamicWaasTonConnector.d.ts +153 -0
  13. package/src/connector/DynamicWaasTonConnector.js +278 -0
  14. package/src/connector/TonWalletConnector.cjs +41 -0
  15. package/src/connector/TonWalletConnector.d.ts +29 -0
  16. package/src/connector/TonWalletConnector.js +37 -0
  17. package/src/index.cjs +34 -0
  18. package/src/index.d.ts +7 -0
  19. package/src/index.js +19 -0
  20. package/src/signer/DynamicWaasTonSigner.cjs +61 -0
  21. package/src/signer/DynamicWaasTonSigner.d.ts +20 -0
  22. package/src/signer/DynamicWaasTonSigner.js +57 -0
  23. package/src/types/index.cjs +13 -0
  24. package/src/types/index.d.ts +71 -0
  25. package/src/types/index.js +11 -0
  26. package/src/utils/convertSendTransactionRequest/convertSendTransactionRequest.cjs +117 -0
  27. package/src/utils/convertSendTransactionRequest/convertSendTransactionRequest.d.ts +9 -0
  28. package/src/utils/convertSendTransactionRequest/convertSendTransactionRequest.js +113 -0
  29. package/src/utils/convertSendTransactionRequest/index.d.ts +1 -0
  30. package/src/utils/executeTransaction/executeTransaction.cjs +55 -0
  31. package/src/utils/executeTransaction/executeTransaction.d.ts +25 -0
  32. package/src/utils/executeTransaction/executeTransaction.js +51 -0
  33. package/src/utils/extractDisplayInfoFromRequest/extractDisplayInfoFromRequest.cjs +51 -0
  34. package/src/utils/extractDisplayInfoFromRequest/extractDisplayInfoFromRequest.d.ts +18 -0
  35. package/src/utils/extractDisplayInfoFromRequest/extractDisplayInfoFromRequest.js +47 -0
  36. package/src/utils/extractDisplayInfoFromRequest/index.d.ts +1 -0
  37. package/src/utils/generateTonConnectProofHash/generateTonConnectProofHash.cjs +89 -0
  38. package/src/utils/generateTonConnectProofHash/generateTonConnectProofHash.d.ts +24 -0
  39. package/src/utils/generateTonConnectProofHash/generateTonConnectProofHash.js +85 -0
  40. package/src/utils/getJettonWalletAddress/getJettonWalletAddress.cjs +32 -0
  41. package/src/utils/getJettonWalletAddress/getJettonWalletAddress.d.ts +17 -0
  42. package/src/utils/getJettonWalletAddress/getJettonWalletAddress.js +28 -0
  43. package/src/utils/getWalletSeqno/getWalletSeqno.cjs +22 -0
  44. package/src/utils/getWalletSeqno/getWalletSeqno.d.ts +9 -0
  45. package/src/utils/getWalletSeqno/getWalletSeqno.js +18 -0
  46. package/src/utils/index.d.ts +10 -0
  47. package/src/utils/logger/logger.cjs +14 -0
  48. package/src/utils/logger/logger.d.ts +3 -0
  49. package/src/utils/logger/logger.js +7 -0
  50. package/src/utils/prepareJettonTransfer/prepareJettonTransfer.cjs +78 -0
  51. package/src/utils/prepareJettonTransfer/prepareJettonTransfer.d.ts +31 -0
  52. package/src/utils/prepareJettonTransfer/prepareJettonTransfer.js +74 -0
  53. package/src/utils/prepareTonTransfer/prepareTonTransfer.cjs +45 -0
  54. package/src/utils/prepareTonTransfer/prepareTonTransfer.d.ts +23 -0
  55. package/src/utils/prepareTonTransfer/prepareTonTransfer.js +41 -0
  56. package/src/utils/prepareTransaction/prepareTransaction.cjs +65 -0
  57. package/src/utils/prepareTransaction/prepareTransaction.d.ts +32 -0
  58. package/src/utils/prepareTransaction/prepareTransaction.js +61 -0
  59. package/src/wallet/WaasTonWallet.cjs +31 -0
  60. package/src/wallet/WaasTonWallet.d.ts +10 -0
  61. package/src/wallet/WaasTonWallet.js +27 -0
  62. package/.eslintrc.json +0 -33
  63. package/jest.config.ts +0 -29
  64. package/project.json +0 -47
  65. package/rollup.config.cjs +0 -7
  66. package/src/index.ts +0 -18
  67. package/src/types/index.ts +0 -39
  68. package/src/utils/index.ts +0 -1
  69. package/src/utils/logger/logger.spec.ts +0 -7
  70. package/src/utils/logger/logger.ts +0 -6
  71. package/test/mocks/browserWalletClientMock.ts +0 -38
  72. package/test/setupAfterEnv.config.ts +0 -7
  73. package/tsconfig.json +0 -23
  74. package/tsconfig.lib.json +0 -10
  75. package/tsconfig.spec.json +0 -14
@@ -0,0 +1,61 @@
1
+ 'use client'
2
+ import { Address, beginCell, WalletContractV5R1 } from '@ton/ton';
3
+ import { storeOutList } from '@ton/core';
4
+ import { CHAIN } from '../../types/index.js';
5
+
6
+ /**
7
+ * Prepares a v5r1 wallet transaction from an array of actions
8
+ *
9
+ * @param params - Parameters for preparing the transaction
10
+ * @returns The hash to sign and transaction data
11
+ */
12
+ const prepareTransaction = (params) => {
13
+ const { actionsArray, walletAddress, seqno, validUntil, timeout, networkGlobalId = CHAIN.MAINNET, } = params;
14
+ const walletAddr = Address.parse(walletAddress);
15
+ // Build actions cell from actions array
16
+ const actionsCell = beginCell().store(storeOutList(actionsArray)).endCell();
17
+ const actions = beginCell()
18
+ .storeBit(1) // storeMaybeRef - we have basic actions
19
+ .storeRef(actionsCell) // ref to basic actions
20
+ .storeBit(0) // no extended actions
21
+ .endCell();
22
+ // Calculate walletId following v5r1 spec:
23
+ // walletId = networkGlobalId XOR context
24
+ // context = (1 bit: isClient=1) + (8 bits: workchain) + (8 bits: version=0) + (15 bits: subwallet=0)
25
+ const context = beginCell()
26
+ .storeUint(1, 1) // isClientContext
27
+ .storeInt(walletAddr.workChain, 8) // workchain
28
+ .storeUint(0, 8) // wallet_version (v5r1 = 0)
29
+ .storeUint(0, 15) // subwalletNumber
30
+ .endCell()
31
+ .beginParse()
32
+ .loadInt(32);
33
+ const walletIdValue = BigInt(networkGlobalId) ^ BigInt(context);
34
+ // Build the signing message according to v5r1 spec
35
+ // opcode | walletId | valid_until/timeout | seqno | actions
36
+ const signingMessage = beginCell()
37
+ .storeUint(WalletContractV5R1.OpCodes.auth_signed_external, 32)
38
+ .storeInt(walletIdValue, 32)
39
+ .storeUint(validUntil, 32)
40
+ .storeUint(seqno, 32)
41
+ .storeSlice(actions.beginParse());
42
+ // Calculate hash to sign
43
+ const dataToSign = signingMessage.endCell();
44
+ const hashToSign = dataToSign.hash();
45
+ const hashToSignHex = hashToSign.toString('hex');
46
+ // Store the signing message
47
+ const messageBody = dataToSign.toBoc().toString('base64');
48
+ const transactionData = {
49
+ address: walletAddress,
50
+ messageBody,
51
+ seqno,
52
+ timeout,
53
+ };
54
+ return {
55
+ hashToSign,
56
+ hashToSignHex,
57
+ transactionData,
58
+ };
59
+ };
60
+
61
+ export { prepareTransaction };
@@ -0,0 +1,31 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
+
9
+ // Needs to extend TonWallet when ton-core package is ready
10
+ class WaasTonWallet extends walletConnectorCore.Wallet {
11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
+ sendBalance(params) {
13
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
14
+ throw new Error('Not implemented');
15
+ });
16
+ }
17
+ getSigner() {
18
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
19
+ yield this._connector.getWalletClientByAddress({
20
+ accountAddress: this.address,
21
+ });
22
+ const signer = yield this._connector.getSigner();
23
+ if (!signer) {
24
+ throw new Error('Unable to retrieve TON signer');
25
+ }
26
+ return signer;
27
+ });
28
+ }
29
+ }
30
+
31
+ exports.WaasTonWallet = WaasTonWallet;
@@ -0,0 +1,10 @@
1
+ import { Wallet } from '@dynamic-labs/wallet-connector-core';
2
+ import { DynamicWaasTonConnector } from '../connector/DynamicWaasTonConnector';
3
+ import { DynamicWaasTonSigner } from '../signer/DynamicWaasTonSigner';
4
+ export declare class WaasTonWallet extends Wallet<DynamicWaasTonConnector> {
5
+ sendBalance(params: {
6
+ amount: string;
7
+ toAddress: string;
8
+ }): Promise<string | undefined>;
9
+ getSigner(): Promise<DynamicWaasTonSigner>;
10
+ }
@@ -0,0 +1,27 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { Wallet } from '@dynamic-labs/wallet-connector-core';
4
+
5
+ // Needs to extend TonWallet when ton-core package is ready
6
+ class WaasTonWallet extends Wallet {
7
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
+ sendBalance(params) {
9
+ return __awaiter(this, void 0, void 0, function* () {
10
+ throw new Error('Not implemented');
11
+ });
12
+ }
13
+ getSigner() {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ yield this._connector.getWalletClientByAddress({
16
+ accountAddress: this.address,
17
+ });
18
+ const signer = yield this._connector.getSigner();
19
+ if (!signer) {
20
+ throw new Error('Unable to retrieve TON signer');
21
+ }
22
+ return signer;
23
+ });
24
+ }
25
+ }
26
+
27
+ export { WaasTonWallet };
package/.eslintrc.json DELETED
@@ -1,33 +0,0 @@
1
- {
2
- "extends": ["../../.eslintrc.json"],
3
- "ignorePatterns": ["!**/*"],
4
- "overrides": [
5
- {
6
- "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
- "rules": {
8
- "import/no-namespace": "off",
9
- "no-restricted-syntax": [
10
- "error",
11
- {
12
- "selector": "MemberExpression[object.name='window'][property.name='location']",
13
- "message": "Use PlatformService from @dynamic-labs/utils package instead of directly accessing window.location."
14
- }
15
- ]
16
- }
17
- },
18
- {
19
- "files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
20
- "rules": {
21
- "no-restricted-syntax": "off"
22
- }
23
- },
24
- {
25
- "files": ["*.ts", "*.tsx"],
26
- "rules": {}
27
- },
28
- {
29
- "files": ["*.js", "*.jsx"],
30
- "rules": {}
31
- }
32
- ]
33
- }
package/jest.config.ts DELETED
@@ -1,29 +0,0 @@
1
- /* eslint-disable */
2
- /* eslint-disable sort-keys */
3
-
4
- const esModules = [
5
- '@dynamic-labs-wallet/forward-mpc-client',
6
- '@dynamic-labs-wallet/forward-mpc-shared',
7
- '@noble/.*',
8
- '@evervault/wasm-attestation-bindings',
9
- ].join('|');
10
-
11
- export default {
12
- displayName: 'waas-ton',
13
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
14
- preset: '../../jest.preset.js',
15
- resetMocks: false,
16
- transform: {
17
- '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',
18
- 'node_modules/@onflow': 'ts-jest',
19
- '^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/react/babel'] }],
20
- },
21
- transformIgnorePatterns: [`node_modules/(?!(${esModules}|@simplewebauthn)/)`],
22
- moduleNameMapper: {
23
- '@dynamic-labs-wallet/browser-wallet-client':
24
- '<rootDir>/test/mocks/browserWalletClientMock.ts',
25
- },
26
- maxWorkers: '2',
27
- workerIdleMemoryLimit: '1.25gb',
28
- setupFilesAfterEnv: ['./test/setupAfterEnv.config.ts'],
29
- };
package/project.json DELETED
@@ -1,47 +0,0 @@
1
- {
2
- "name": "waas-ton",
3
- "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "packages/waas-ton/src",
5
- "projectType": "library",
6
- "targets": {
7
- "post-build": {},
8
- "build": {
9
- "executor": "@nrwl/rollup:rollup",
10
- "outputs": ["{options.outputPath}"],
11
- "dependsOn": ["^build"],
12
- "options": {
13
- "outputPath": "dist/packages/waas-ton",
14
- "entryFile": "packages/waas-ton/src/index.ts",
15
- "tsConfig": "packages/waas-ton/tsconfig.lib.json",
16
- "project": "packages/waas-ton/package.json",
17
- "rollupConfig": "packages/waas-ton/rollup.config.cjs",
18
- "buildableProjectDepsInPackageJsonType": "dependencies",
19
- "updateBuildableProjectDepsInPackageJson": true,
20
- "compiler": "tsc",
21
- "format": ["esm", "cjs"]
22
- }
23
- },
24
- "lint": {
25
- "executor": "@nrwl/linter:eslint",
26
- "outputs": ["{options.outputFile}"],
27
- "options": {
28
- "lintFilePatterns": ["packages/waas-ton/**/*.ts"]
29
- }
30
- },
31
- "test": {
32
- "executor": "@nrwl/jest:jest",
33
- "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
34
- "options": {
35
- "jestConfig": "packages/waas-ton/jest.config.ts",
36
- "passWithNoTests": true
37
- },
38
- "configurations": {
39
- "ci": {
40
- "ci": true,
41
- "codeCoverage": true
42
- }
43
- }
44
- }
45
- },
46
- "tags": []
47
- }
package/rollup.config.cjs DELETED
@@ -1,7 +0,0 @@
1
- /* eslint-disable no-undef */
2
- const { globalConfig } = require('../../rollup.config.base.cjs');
3
-
4
- module.exports = (config) => {
5
- globalConfig(config);
6
- return config;
7
- };
package/src/index.ts DELETED
@@ -1,18 +0,0 @@
1
- import { toNano } from '@ton/core';
2
- import { TonClient } from '@ton/ton';
3
- import { mnemonicToWalletKey } from '@ton/crypto';
4
-
5
- import { SignMessageContext } from '@dynamic-labs/sdk-api-core';
6
- import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
7
-
8
- import { version as packageVersion } from '../package.json';
9
-
10
- assertPackageVersion('@dynamic-labs/waas-ton', packageVersion);
11
-
12
- export { TonClient, toNano, mnemonicToWalletKey, type SignMessageContext };
13
-
14
- export type {
15
- TonConnectDomain,
16
- TonConnectProof,
17
- TonTransactionData,
18
- } from './types';
@@ -1,39 +0,0 @@
1
- /**
2
- * Domain information for TON Connect protocol
3
- */
4
- export interface TonConnectDomain {
5
- /** Length of domain value in bytes */
6
- lengthBytes: number;
7
- /** Domain value (e.g., example.com) */
8
- value: string;
9
- }
10
-
11
- /**
12
- * Complete TON Connect proof object
13
- */
14
- export interface TonConnectProof {
15
- /** Wallet address string */
16
- address: string;
17
- /** Domain information */
18
- domain: TonConnectDomain;
19
- /** Unix timestamp in seconds */
20
- timestamp: number;
21
- /** Payload string */
22
- payload: string;
23
- /** Signature as base64 string */
24
- signature: string;
25
- }
26
-
27
- /**
28
- * Generic transaction data that can be used for any TON transaction type
29
- */
30
- export interface TonTransactionData {
31
- /** Sender wallet address */
32
- address: string;
33
- /** Current wallet seqno */
34
- seqno: number;
35
- /** Base64-encoded message body (the transaction to be signed) */
36
- messageBody: string;
37
- /** Transaction timeout in seconds */
38
- timeout: number;
39
- }
@@ -1 +0,0 @@
1
- export * from './logger/logger';
@@ -1,7 +0,0 @@
1
- import { logger } from './logger';
2
-
3
- describe('logger', () => {
4
- it('should be defined', () => {
5
- expect(logger).toBeDefined();
6
- });
7
- });
@@ -1,6 +0,0 @@
1
- import { Logger, InstrumentOptions } from '@dynamic-labs/logger';
2
-
3
- export const logger = new Logger('@dynamic-labs/waas-ton');
4
-
5
- // Export the Logger class to ensure we're using the same reference
6
- export { Logger, type InstrumentOptions };
@@ -1,38 +0,0 @@
1
- export const createWalletAccountMock = jest.fn();
2
- export const exportClientKeysharesMock = jest.fn();
3
- export const getWalletMock = jest.fn();
4
- export const signMessageMock = jest.fn();
5
- export const exportPrivateKeyMock = jest.fn();
6
- export const importPrivateKeyMock = jest.fn();
7
- export const backupKeySharesToGoogleDriveMock = jest.fn();
8
- export const delegateKeySharesMock = jest.fn();
9
- export const refreshWalletAccountSharesMock = jest.fn();
10
- export const updatePasswordMock = jest.fn();
11
- export const signRawMessageMock = jest.fn();
12
-
13
- export const AuthMode = {
14
- HEADER: 'header',
15
- COOKIE: 'cookie',
16
- };
17
-
18
- export class DynamicWalletClient {
19
- initialize = jest.fn();
20
- createWalletAccount = createWalletAccountMock;
21
- exportClientKeyshares = exportClientKeysharesMock;
22
- getWallet = getWalletMock;
23
- signMessage = signMessageMock;
24
- exportPrivateKey = exportPrivateKeyMock;
25
- importPrivateKey = importPrivateKeyMock;
26
- backupKeySharesToGoogleDrive = backupKeySharesToGoogleDriveMock;
27
- delegateKeyShares = delegateKeySharesMock;
28
- refreshWalletAccountShares = refreshWalletAccountSharesMock;
29
- updatePassword = updatePasswordMock;
30
- signRawMessage = signRawMessageMock;
31
- chainName = 'TON';
32
- cleanup = jest.fn();
33
- }
34
-
35
- export const ThresholdSignatureScheme = {
36
- TWO_OF_TWO: 'TWO_OF_TWO',
37
- TWO_OF_THREE: 'TWO_OF_THREE',
38
- };
@@ -1,7 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- import { TextEncoder, TextDecoder } from 'text-encoding';
3
-
4
- global.TextDecoder = TextDecoder;
5
- global.TextEncoder = TextEncoder;
6
-
7
- jest.mock('@dynamic-labs/logger');
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "esModuleInterop": false,
5
- "allowSyntheticDefaultImports": true,
6
- "forceConsistentCasingInFileNames": true,
7
- "strict": true,
8
- "noImplicitOverride": true,
9
- "noPropertyAccessFromIndexSignature": false,
10
- "noImplicitReturns": true,
11
- "noFallthroughCasesInSwitch": true
12
- },
13
- "files": [],
14
- "include": [],
15
- "references": [
16
- {
17
- "path": "./tsconfig.lib.json"
18
- },
19
- {
20
- "path": "./tsconfig.spec.json"
21
- }
22
- ]
23
- }
package/tsconfig.lib.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "declaration": true,
6
- "types": ["node"]
7
- },
8
- "include": ["src/**/*.ts"],
9
- "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
10
- }
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node"]
7
- },
8
- "include": [
9
- "jest.config.ts",
10
- "src/**/*.test.ts",
11
- "src/**/*.spec.ts",
12
- "src/**/*.d.ts"
13
- ]
14
- }