@msafe/sui3-sdk 0.0.2-pre-9f39791.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 (60) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc +87 -0
  3. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  4. package/.idea/jsLinters/eslint.xml +6 -0
  5. package/.idea/misc.xml +6 -0
  6. package/.idea/modules.xml +8 -0
  7. package/.idea/msafe-sui3-sdk.iml +9 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/.prettierrc +22 -0
  10. package/README.md +3 -0
  11. package/jest.config.ts +63 -0
  12. package/package.json +54 -0
  13. package/scripts/prerelease.sh +5 -0
  14. package/src/backend/CoreDatabase.ts +55 -0
  15. package/src/backend/PseudoBackend.ts +851 -0
  16. package/src/backend/interface.ts +57 -0
  17. package/src/backend/types.ts +22 -0
  18. package/src/core/CreateHelper.ts +76 -0
  19. package/src/core/MSafeAccount.ts +167 -0
  20. package/src/core/MSafeClient.ts +91 -0
  21. package/src/core/MessageHelper.ts +63 -0
  22. package/src/core/PublicKeyHelper.ts +88 -0
  23. package/src/core/index.ts +4 -0
  24. package/src/globals/MSafeGlobals.ts +48 -0
  25. package/src/globals/const.ts +95 -0
  26. package/src/globals/index.ts +2 -0
  27. package/src/index.ts +5 -0
  28. package/src/transactions/coin-transfer.ts +64 -0
  29. package/src/transactions/index.ts +1 -0
  30. package/src/transactions/intention.ts +63 -0
  31. package/src/transactions/object-transfer.ts +66 -0
  32. package/src/transactions/reject.ts +17 -0
  33. package/src/transactions/stream.ts +1 -0
  34. package/src/types/creation.ts +19 -0
  35. package/src/types/index.ts +3 -0
  36. package/src/types/msafe.ts +79 -0
  37. package/src/types/wallet.ts +23 -0
  38. package/src/utils/buffer.ts +11 -0
  39. package/src/utils/coin.ts +64 -0
  40. package/src/utils/crypto.ts +95 -0
  41. package/src/utils/format.ts +25 -0
  42. package/src/utils/index.ts +6 -0
  43. package/src/utils/multi-sig.ts +113 -0
  44. package/src/utils/sui.ts +90 -0
  45. package/temp_package.json +54 -0
  46. package/test/lib/TestHelper.ts +94 -0
  47. package/test/lib/account.ts +87 -0
  48. package/test/lib/config.ts +9 -0
  49. package/test/lib/faucet.ts +49 -0
  50. package/test/unit/backend/backend.test.ts +367 -0
  51. package/test/unit/core/CreateHelper.test.ts +121 -0
  52. package/test/unit/core/MessageHelper.test.ts +32 -0
  53. package/test/unit/core/PublicKeyHelper.test.ts +80 -0
  54. package/test/unit/core/msafe.test.ts +298 -0
  55. package/test/unit/utils/buffer.test.ts +17 -0
  56. package/test/unit/utils/crypto.test.ts +32 -0
  57. package/test/unit/utils/multi-sig.test.ts +47 -0
  58. package/test/unit/utils/sui.test.ts +25 -0
  59. package/tsconfig.json +37 -0
  60. package/tsup.config.ts +9 -0
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ dist/*
2
+ node_modules/*
3
+ loader.js
package/.eslintrc ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2021": true,
5
+ "es2022": true
6
+ },
7
+ "extends": ["airbnb-base", "airbnb-typescript/base", "plugin:@typescript-eslint/recommended", "prettier"],
8
+ "plugins": ["@typescript-eslint", "prettier", "unused-imports", "import"],
9
+ "overrides": [
10
+ {
11
+ "files": ["test/**/*.ts", "**/*.test.ts"],
12
+ "rules": {
13
+ "@typescript-eslint/no-non-null-assertion": "off",
14
+ "no-param-reassign": "off",
15
+ "@typescript-eslint/no-explicit-any": "off",
16
+ "no-continue": "off",
17
+ "@typescript-eslint/no-unused-vars": "off"
18
+ }
19
+ }
20
+ ],
21
+ "parser": "@typescript-eslint/parser",
22
+ "parserOptions": {
23
+ "ecmaVersion": "latest",
24
+ "sourceType": "module",
25
+ "project": "./tsconfig.json"
26
+ },
27
+ "ignorePatterns": ["coverage/"],
28
+ "rules": {
29
+ "no-use-before-define": "off",
30
+ "no-useless-constructor": "off",
31
+ "import/extensions": [
32
+ "error",
33
+ "ignorePackages",
34
+ {
35
+ "js": "never",
36
+ "jsx": "never",
37
+ "ts": "never",
38
+ "tsx": "never"
39
+ }
40
+ ],
41
+ "import/order": [
42
+ "error",
43
+ {
44
+ "groups": [
45
+ "builtin",
46
+ "external",
47
+ "internal",
48
+ ["sibling", "parent"],
49
+ "index",
50
+ "unknown"
51
+ ],
52
+ "newlines-between": "always",
53
+ "alphabetize": {
54
+ "order": "asc",
55
+ "caseInsensitive": true
56
+ }
57
+ }
58
+ ],
59
+ "import/prefer-default-export": "off",
60
+ "no-shadow": "off",
61
+ "@typescript-eslint/no-shadow": "error",
62
+ "@typescript-eslint/naming-convention": "error",
63
+ "prettier/prettier": "error",
64
+ "@typescript-eslint/no-explicit-any": "off",
65
+ "no-underscore-dangle": "off",
66
+ "no-await-in-loop": "off",
67
+ "max-classes-per-file": "off",
68
+ "no-plusplus": "off",
69
+ "no-continue": "off",
70
+ "@typescript-eslint/no-unused-vars": "error",
71
+ "no-unused-vars": "off",
72
+ "unused-imports/no-unused-imports": "error",
73
+ "unused-imports/no-unused-vars": [
74
+ "warn",
75
+ { "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
76
+ ],
77
+ "class-methods-use-this": "off",
78
+ "curly": ["error", "all"],
79
+ "no-console": "off",
80
+ "@typescript-eslint/no-use-before-define": "off"
81
+ },
82
+ "settings": {
83
+ "import/resolver": {
84
+ "typescript": {}
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5
+ </profile>
6
+ </component>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="EslintConfiguration">
4
+ <option name="fix-on-save" value="true" />
5
+ </component>
6
+ </project>
package/.idea/misc.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager">
4
+ <output url="file://$PROJECT_DIR$/out" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/msafe-sui3-sdk.iml" filepath="$PROJECT_DIR$/.idea/msafe-sui3-sdk.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="inheritedJdk" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ </component>
9
+ </module>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
package/.prettierrc ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "printWidth": 120,
3
+ "tabWidth": 2,
4
+ "useTabs": false,
5
+ "semi": true,
6
+ "singleQuote": true,
7
+ "quoteProps": "as-needed",
8
+ "trailingComma": "all",
9
+ "bracketSpacing": true,
10
+ "bracketSameLine": false,
11
+ "arrowParens": "always",
12
+ "rangeStart": 0,
13
+ "rangeEnd": 1000000000000,
14
+ "requirePragma": false,
15
+ "insertPragma": false,
16
+ "proseWrap": "preserve",
17
+ "htmlWhitespaceSensitivity": "css",
18
+ "vueIndentScriptAndStyle": false,
19
+ "endOfLine": "lf",
20
+ "embeddedLanguageFormatting": "auto",
21
+ "singleAttributePerLine": false
22
+ }
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # msafe-sui3-sdk
2
+
3
+ SDK for MSafe SUI V3
package/jest.config.ts ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * For a detailed explanation regarding each configuration property, visit:
3
+ * https://jestjs.io/docs/configuration
4
+ */
5
+
6
+ import type { Config } from 'jest';
7
+
8
+ const config: Config = {
9
+ // Automatically clear mock calls, instances, contexts and results before every test
10
+ clearMocks: true,
11
+
12
+ // The directory where Jest should output its coverage files
13
+ coverageDirectory: 'coverage',
14
+
15
+ // Indicates which provider should be used to instrument code for coverage
16
+ coverageProvider: 'v8',
17
+
18
+ // A set of global variables that need to be available in all test environments
19
+ // globals: {
20
+ // 'ts-jest': {
21
+ // tsconfig: './tsconfig.json',
22
+ // useESM: true,
23
+ // },
24
+ // },
25
+
26
+ // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
27
+ maxWorkers: 1,
28
+
29
+ // An array of directory names to be searched recursively up from the requiring module's location
30
+ moduleDirectories: ['node_modules'],
31
+
32
+ // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
33
+ moduleNameMapper: {
34
+ '^@/(.*)$': '<rootDir>/src/$1',
35
+ },
36
+
37
+ // A preset that is used as a base for Jest's configuration
38
+ preset: 'ts-jest',
39
+
40
+ // The root directory that Jest should scan for tests and modules within
41
+ rootDir: './',
42
+
43
+ // The glob patterns Jest uses to detect test files
44
+ testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'],
45
+
46
+ // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
47
+ testPathIgnorePatterns: ['/node_modules/'],
48
+
49
+ // A map from regular expressions to paths to transformers
50
+ transform: {
51
+ '^.+\\.tsx?$': [
52
+ 'ts-jest',
53
+ {
54
+ tsconfig: './tsconfig.json',
55
+ useESM: true,
56
+ },
57
+ ],
58
+ },
59
+
60
+ testTimeout: 600 * 1000,
61
+ };
62
+
63
+ export default config;
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@msafe/sui3-sdk",
3
+ "version": "0.0.2-pre-9f39791.0",
4
+ "description": "SDK for MSafe SUI V3",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "source": "./src/index.ts",
9
+ "import": "./dist/index.js",
10
+ "require": "./dist/index.cjs"
11
+ }
12
+ },
13
+ "repository": "git@github.com:Momentum-Safe/msafe-sui3-sdk.git",
14
+ "author": "MSafe <admin@m-safe.io>",
15
+ "license": "MIT",
16
+ "devDependencies": {
17
+ "@types/jest": "^29.5.8",
18
+ "@types/node": "^20.9.2",
19
+ "@typescript-eslint/eslint-plugin": "^6.5.0",
20
+ "@typescript-eslint/parser": "^6.5.0",
21
+ "eslint": "^8.48.0",
22
+ "eslint-config-airbnb-base": "^15.0.0",
23
+ "eslint-config-airbnb-typescript": "^17.1.0",
24
+ "eslint-config-prettier": "^9.0.0",
25
+ "eslint-import-resolver-alias": "^1.1.2",
26
+ "eslint-import-resolver-typescript": "^3.6.0",
27
+ "eslint-plugin-import": "^2.28.1",
28
+ "eslint-plugin-prettier": "^5.0.0",
29
+ "eslint-plugin-unused-imports": "^3.0.0",
30
+ "exponential-backoff": "^3.1.1",
31
+ "jest": "^29.7.0",
32
+ "prettier": "^3.0.3",
33
+ "ts-jest": "^29.1.1",
34
+ "ts-node": "^10.9.1",
35
+ "tsconfig-paths": "^4.2.0",
36
+ "tsup": "^8.0.1",
37
+ "typescript": "^5.2.2"
38
+ },
39
+ "scripts": {
40
+ "test": "jest",
41
+ "unit-ci": "TEST_ENV=UNIT jest",
42
+ "clean": "rm -rf ./dist",
43
+ "lint": "eslint . --ext .ts,.tsx",
44
+ "build": "yarn clean && yarn _build:node",
45
+ "_build:node": "tsup --format cjs,esm --dts",
46
+ "prerelease": "yarn build && chmod +x ./scripts/prerelease.sh && ./scripts/prerelease.sh"
47
+ },
48
+ "dependencies": {
49
+ "@msafe/sui3-model": "^1.0.9-pre-5a4e334.0",
50
+ "@mysten/sui.js": "0.46.1",
51
+ "reflect-metadata": "^0.1.13",
52
+ "typeorm": "0.3.17"
53
+ }
54
+ }
@@ -0,0 +1,5 @@
1
+ GIT_COMMIT_SHORT=$(git rev-parse --short HEAD)
2
+
3
+ cp package.json temp_package.json
4
+ yarn publish --non-interactive --prerelease --preid pre-"${GIT_COMMIT_SHORT}" --no-git-tag-version --access public
5
+ mv temp_package.json package.json
@@ -0,0 +1,55 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+ import 'reflect-metadata';
3
+
4
+ import { CoreModel, User, UserSetting } from '@msafe/sui3-model/core';
5
+ import { PublicKey } from '@mysten/sui.js/cryptography';
6
+
7
+ import { DBConfig } from '@/globals/const';
8
+ import { PublicKeySerde } from '@/utils/crypto';
9
+
10
+ export const WALLET_TYPE_KEY = 'wallet_type';
11
+
12
+ export class CoreDB {
13
+ private constructor(public readonly coreModel: CoreModel) {}
14
+
15
+ static async New(dbConfig: DBConfig) {
16
+ const core = await CoreModel.New(dbConfig);
17
+ return new CoreDB(core);
18
+ }
19
+
20
+ async upsertUser(input: { address: string; publicKey: PublicKey; lastLogin: Date }) {
21
+ const currentUser = await this.coreModel.user.findOneBy({
22
+ address: input.address,
23
+ });
24
+ if (currentUser !== null) {
25
+ currentUser.lastLogin = input.lastLogin;
26
+ await this.coreModel.user.save(currentUser);
27
+ } else {
28
+ const serializedPublicKey = PublicKeySerde.ser(input.publicKey);
29
+ const user: User = {
30
+ address: input.address,
31
+ publicKey: serializedPublicKey.publicKey,
32
+ schema: serializedPublicKey.scheme,
33
+ nonce: 0,
34
+ lastLogin: new Date(),
35
+ };
36
+ await this.coreModel.user.save(user);
37
+ }
38
+ }
39
+
40
+ async updateUserWalletType(input: { address: string; walletType: string }) {
41
+ const exist = await this.coreModel.userSetting.findOneBy({
42
+ userAddress: input.address,
43
+ key: WALLET_TYPE_KEY,
44
+ });
45
+ const walletType = input.walletType.trim();
46
+ if (exist === null || exist.value !== walletType) {
47
+ const userSetting: UserSetting = {
48
+ userAddress: input.address,
49
+ key: WALLET_TYPE_KEY,
50
+ value: walletType,
51
+ };
52
+ await this.coreModel.userSetting.save(userSetting);
53
+ }
54
+ }
55
+ }