@metamask/profile-sync-controller 1.0.0 → 1.0.1

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 (88) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/controllers/user-storage/UserStorageController.cjs +56 -15
  3. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  4. package/dist/controllers/user-storage/UserStorageController.d.cts +12 -2
  5. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  6. package/dist/controllers/user-storage/UserStorageController.d.mts +12 -2
  7. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  8. package/dist/controllers/user-storage/UserStorageController.mjs +57 -16
  9. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  10. package/dist/controllers/user-storage/__fixtures__/mockAccounts.cjs +11 -0
  11. package/dist/controllers/user-storage/__fixtures__/mockAccounts.cjs.map +1 -1
  12. package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.cts +1 -0
  13. package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.cts.map +1 -1
  14. package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.mts +1 -0
  15. package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.mts.map +1 -1
  16. package/dist/controllers/user-storage/__fixtures__/mockAccounts.mjs +11 -0
  17. package/dist/controllers/user-storage/__fixtures__/mockAccounts.mjs.map +1 -1
  18. package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs +15 -7
  19. package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs.map +1 -1
  20. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.cts +5 -0
  21. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.cts.map +1 -1
  22. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts +5 -0
  23. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts.map +1 -1
  24. package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs +14 -7
  25. package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs.map +1 -1
  26. package/dist/controllers/user-storage/__fixtures__/mockServices.cjs +18 -7
  27. package/dist/controllers/user-storage/__fixtures__/mockServices.cjs.map +1 -1
  28. package/dist/controllers/user-storage/__fixtures__/mockServices.d.cts +2 -1
  29. package/dist/controllers/user-storage/__fixtures__/mockServices.d.cts.map +1 -1
  30. package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts +2 -1
  31. package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts.map +1 -1
  32. package/dist/controllers/user-storage/__fixtures__/mockServices.mjs +17 -7
  33. package/dist/controllers/user-storage/__fixtures__/mockServices.mjs.map +1 -1
  34. package/dist/controllers/user-storage/index.cjs +1 -0
  35. package/dist/controllers/user-storage/index.cjs.map +1 -1
  36. package/dist/controllers/user-storage/index.d.cts +1 -0
  37. package/dist/controllers/user-storage/index.d.cts.map +1 -1
  38. package/dist/controllers/user-storage/index.d.mts +1 -0
  39. package/dist/controllers/user-storage/index.d.mts.map +1 -1
  40. package/dist/controllers/user-storage/index.mjs +1 -0
  41. package/dist/controllers/user-storage/index.mjs.map +1 -1
  42. package/dist/controllers/user-storage/network-syncing/services.cjs +2 -1
  43. package/dist/controllers/user-storage/network-syncing/services.cjs.map +1 -1
  44. package/dist/controllers/user-storage/network-syncing/services.d.cts.map +1 -1
  45. package/dist/controllers/user-storage/network-syncing/services.d.mts.map +1 -1
  46. package/dist/controllers/user-storage/network-syncing/services.mjs +2 -1
  47. package/dist/controllers/user-storage/network-syncing/services.mjs.map +1 -1
  48. package/dist/controllers/user-storage/services.cjs +32 -1
  49. package/dist/controllers/user-storage/services.cjs.map +1 -1
  50. package/dist/controllers/user-storage/services.d.cts +10 -2
  51. package/dist/controllers/user-storage/services.d.cts.map +1 -1
  52. package/dist/controllers/user-storage/services.d.mts +10 -2
  53. package/dist/controllers/user-storage/services.d.mts.map +1 -1
  54. package/dist/controllers/user-storage/services.mjs +30 -0
  55. package/dist/controllers/user-storage/services.mjs.map +1 -1
  56. package/dist/sdk/__fixtures__/mock-userstorage.cjs +15 -3
  57. package/dist/sdk/__fixtures__/mock-userstorage.cjs.map +1 -1
  58. package/dist/sdk/__fixtures__/mock-userstorage.d.cts +1 -0
  59. package/dist/sdk/__fixtures__/mock-userstorage.d.cts.map +1 -1
  60. package/dist/sdk/__fixtures__/mock-userstorage.d.mts +1 -0
  61. package/dist/sdk/__fixtures__/mock-userstorage.d.mts.map +1 -1
  62. package/dist/sdk/__fixtures__/mock-userstorage.mjs +13 -2
  63. package/dist/sdk/__fixtures__/mock-userstorage.mjs.map +1 -1
  64. package/dist/sdk/index.cjs +1 -0
  65. package/dist/sdk/index.cjs.map +1 -1
  66. package/dist/sdk/index.d.cts +1 -0
  67. package/dist/sdk/index.d.cts.map +1 -1
  68. package/dist/sdk/index.d.mts +1 -0
  69. package/dist/sdk/index.d.mts.map +1 -1
  70. package/dist/sdk/index.mjs +1 -0
  71. package/dist/sdk/index.mjs.map +1 -1
  72. package/dist/sdk/user-storage.cjs +35 -1
  73. package/dist/sdk/user-storage.cjs.map +1 -1
  74. package/dist/sdk/user-storage.d.cts +3 -2
  75. package/dist/sdk/user-storage.d.cts.map +1 -1
  76. package/dist/sdk/user-storage.d.mts +3 -2
  77. package/dist/sdk/user-storage.d.mts.map +1 -1
  78. package/dist/sdk/user-storage.mjs +35 -1
  79. package/dist/sdk/user-storage.mjs.map +1 -1
  80. package/dist/shared/storage-schema.cjs +9 -4
  81. package/dist/shared/storage-schema.cjs.map +1 -1
  82. package/dist/shared/storage-schema.d.cts +12 -10
  83. package/dist/shared/storage-schema.d.cts.map +1 -1
  84. package/dist/shared/storage-schema.d.mts +12 -10
  85. package/dist/shared/storage-schema.d.mts.map +1 -1
  86. package/dist/shared/storage-schema.mjs +8 -3
  87. package/dist/shared/storage-schema.mjs.map +1 -1
  88. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"storage-schema.mjs","sourceRoot":"","sources":["../../src/shared/storage-schema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AAa,CAAC;IAEhC,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAsC,EACtC,UAAkB;IAElB,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC;IAErD,OAAO,GAAG,OAAO,IAAI,SAAS,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { createSHA256Hash } from './encryption';\n\n/**\n * The User Storage Endpoint requires a feature name and a namespace key.\n * Developers can provide additional features and keys by extending these types below.\n *\n * Adding ALLOW_ARBITRARY_KEYS as the first key in the array allows for any key to be used for this feature.\n * This can be useful for features where keys are not deterministic (eg. accounts addresses).\n */\nconst ALLOW_ARBITRARY_KEYS = 'ALLOW_ARBITRARY_KEYS' as const;\n\nexport const USER_STORAGE_SCHEMA = {\n notifications: ['notification_settings'],\n accounts: [ALLOW_ARBITRARY_KEYS], // keyed by account addresses\n networks: [ALLOW_ARBITRARY_KEYS], // keyed by chains/networks\n} as const;\n\ntype UserStorageSchema = typeof USER_STORAGE_SCHEMA;\n\nexport type UserStorageFeatures = keyof UserStorageSchema;\nexport type UserStorageFeatureKeys<Feature extends UserStorageFeatures> =\n UserStorageSchema[Feature][0] extends typeof ALLOW_ARBITRARY_KEYS\n ? string\n : UserStorageSchema[Feature][number];\n\ntype UserStorageFeatureAndKey = {\n feature: UserStorageFeatures;\n key: UserStorageFeatureKeys<UserStorageFeatures>;\n};\n\nexport type UserStoragePathWithFeatureOnly = keyof UserStorageSchema;\nexport type UserStoragePathWithKeyOnly = {\n [K in UserStorageFeatures]: `${UserStorageFeatureKeys<K>}`;\n}[UserStoragePathWithFeatureOnly];\nexport type UserStoragePathWithFeatureAndKey = {\n [K in UserStorageFeatures]: `${K}.${UserStorageFeatureKeys<K>}`;\n}[UserStoragePathWithFeatureOnly];\n\nexport const getFeatureAndKeyFromPath = (\n path: UserStoragePathWithFeatureAndKey,\n): UserStorageFeatureAndKey => {\n const pathRegex = /^\\w+\\.\\w+$/u;\n\n if (!pathRegex.test(path)) {\n throw new Error(\n `user-storage - path is not in the correct format. Correct format: 'feature.key'`,\n );\n }\n\n const [feature, key] = path.split('.') as [\n UserStorageFeatures,\n UserStorageFeatureKeys<UserStorageFeatures>,\n ];\n\n if (!(feature in USER_STORAGE_SCHEMA)) {\n throw new Error(`user-storage - invalid feature provided: ${feature}`);\n }\n\n const validFeature = USER_STORAGE_SCHEMA[feature] as readonly string[];\n\n if (\n !validFeature.includes(key) &&\n !validFeature.includes(ALLOW_ARBITRARY_KEYS)\n ) {\n const validKeys = USER_STORAGE_SCHEMA[feature].join(', ');\n\n throw new Error(\n `user-storage - invalid key provided for this feature: ${key}. Valid keys: ${validKeys}`,\n );\n }\n\n return { feature, key };\n};\n\nexport const isPathWithFeatureAndKey = (\n path: string,\n): path is UserStoragePathWithFeatureAndKey => {\n const pathRegex = /^\\w+\\.\\w+$/u;\n\n return pathRegex.test(path);\n};\n\n/**\n * Constructs a unique entry path for a user.\n * This can be done due to the uniqueness of the storage key (no users will share the same storage key).\n * The users entry is a unique hash that cannot be reversed.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param storageKey - users storage key\n * @returns path to store entry\n */\nexport function createEntryPath(\n path: UserStoragePathWithFeatureAndKey,\n storageKey: string,\n): string {\n const { feature, key } = getFeatureAndKeyFromPath(path);\n const hashedKey = createSHA256Hash(key + storageKey);\n\n return `${feature}/${hashedKey}`;\n}\n"]}
1
+ {"version":3,"file":"storage-schema.mjs","sourceRoot":"","sources":["../../src/shared/storage-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,+BAAqB;AAEhD;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,sBAA+B,CAAC;AAE7D,MAAM,CAAC,MAAM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AAuB,GAAG,CACrC,IAAY,EAC8B,EAAE;IAC5C,MAAM,SAAS,GAAG,aAAa,CAAC;IAEhC,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAsC,EACtC,UAAkB;IAElB,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC;IAErD,OAAO,GAAG,OAAO,IAAI,SAAS,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { createSHA256Hash } from './encryption';\n\n/**\n * The User Storage Endpoint requires a feature name and a namespace key.\n * Developers can provide additional features and keys by extending these types below.\n *\n * Adding ALLOW_ARBITRARY_KEYS as the first key in the array allows for any key to be used for this feature.\n * This can be useful for features where keys are not deterministic (eg. accounts addresses).\n */\nconst ALLOW_ARBITRARY_KEYS = 'ALLOW_ARBITRARY_KEYS' as const;\n\nexport const USER_STORAGE_FEATURE_NAMES = {\n notifications: 'notifications',\n accounts: 'accounts_v2',\n networks: 'networks',\n} as const;\n\nexport type UserStorageFeatureNames =\n (typeof USER_STORAGE_FEATURE_NAMES)[keyof typeof USER_STORAGE_FEATURE_NAMES];\n\nexport const USER_STORAGE_SCHEMA = {\n [USER_STORAGE_FEATURE_NAMES.notifications]: ['notification_settings'],\n [USER_STORAGE_FEATURE_NAMES.accounts]: [ALLOW_ARBITRARY_KEYS], // keyed by account addresses\n [USER_STORAGE_FEATURE_NAMES.networks]: [ALLOW_ARBITRARY_KEYS], // keyed by chains/networks\n} as const;\n\ntype UserStorageSchema = typeof USER_STORAGE_SCHEMA;\n\nexport type UserStorageFeatureKeys<Feature extends UserStorageFeatureNames> =\n UserStorageSchema[Feature][0] extends typeof ALLOW_ARBITRARY_KEYS\n ? string\n : UserStorageSchema[Feature][number];\n\ntype UserStorageFeatureAndKey = {\n feature: UserStorageFeatureNames;\n key: UserStorageFeatureKeys<UserStorageFeatureNames>;\n};\n\nexport type UserStoragePathWithFeatureOnly = UserStorageFeatureNames;\nexport type UserStoragePathWithFeatureAndKey = {\n [K in UserStorageFeatureNames]: `${K}.${UserStorageFeatureKeys<K>}`;\n}[UserStoragePathWithFeatureOnly];\n\nexport const getFeatureAndKeyFromPath = (\n path: UserStoragePathWithFeatureAndKey,\n): UserStorageFeatureAndKey => {\n const pathRegex = /^\\w+\\.\\w+$/u;\n\n if (!pathRegex.test(path)) {\n throw new Error(\n `user-storage - path is not in the correct format. Correct format: 'feature.key'`,\n );\n }\n\n const [feature, key] = path.split('.') as [\n UserStorageFeatureNames,\n UserStorageFeatureKeys<UserStorageFeatureNames>,\n ];\n\n if (!(feature in USER_STORAGE_SCHEMA)) {\n throw new Error(`user-storage - invalid feature provided: ${feature}`);\n }\n\n const validFeature = USER_STORAGE_SCHEMA[feature] as readonly string[];\n\n if (\n !validFeature.includes(key) &&\n !validFeature.includes(ALLOW_ARBITRARY_KEYS)\n ) {\n const validKeys = USER_STORAGE_SCHEMA[feature].join(', ');\n\n throw new Error(\n `user-storage - invalid key provided for this feature: ${key}. Valid keys: ${validKeys}`,\n );\n }\n\n return { feature, key };\n};\n\nexport const isPathWithFeatureAndKey = (\n path: string,\n): path is UserStoragePathWithFeatureAndKey => {\n const pathRegex = /^\\w+\\.\\w+$/u;\n\n return pathRegex.test(path);\n};\n\n/**\n * Constructs a unique entry path for a user.\n * This can be done due to the uniqueness of the storage key (no users will share the same storage key).\n * The users entry is a unique hash that cannot be reversed.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param storageKey - users storage key\n * @returns path to store entry\n */\nexport function createEntryPath(\n path: UserStoragePathWithFeatureAndKey,\n storageKey: string,\n): string {\n const { feature, key } = getFeatureAndKeyFromPath(path);\n const hashedKey = createSHA256Hash(key + storageKey);\n\n return `${feature}/${hashedKey}`;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/profile-sync-controller",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "The profile sync helps developers synchronize data across multiple clients and devices in a privacy-preserving way. All data saved in the user storage database is encrypted client-side to preserve privacy. The user storage provides a modular design, giving developers the flexibility to construct and manage their storage spaces in a way that best suits their needs",
5
5
  "keywords": [
6
6
  "MetaMask",