@metamask-previews/snap-networks-utils 1.0.0-preview-e7a796a2 → 1.0.0-preview-2aa5deb

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.
package/CHANGELOG.md CHANGED
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Added
11
11
 
12
+ - Add shared proof-of-ownership message parsing utilities, batch request/response structs, and batch request/response types. ([#268](https://github.com/MetaMask/internal-snaps/pull/268))
12
13
  - Add a `UuidStruct` Superstruct for validating UUID v4 strings. ([#243](https://github.com/MetaMask/internal-snaps/pull/243))
13
14
  - Add helpers `serialize`, `deserialize`, and `Serializable` for round-tripping `BigNumber`, `bigint`, `Uint8Array`, and `undefined` through snap state ([#197](https://github.com/MetaMask/internal-snaps/pull/197))
14
15
  - Add shared snap error utilities to the main package entry point ([#241](https://github.com/MetaMask/internal-snaps/pull/241))
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InFlightCoalescer = exports.normalizeError = exports.isSnapRpcError = exports.createWithCatchAndThrowSnapError = exports.createTrackError = exports.createSnapErrorHandling = exports.validateOrigin = exports.DEFAULT_METAMASK_ORIGIN = exports.DEFAULT_DEV_ORIGINS = exports.DEFAULT_PROD_ORIGINS = exports.createOriginPermissions = exports.deserialize = exports.serialize = exports.LogLevel = exports.Logger = exports.chunks = exports.batchesAllWithChunks = exports.batchesAllSettledWithChunks = exports.batchesAllSettled = exports.batchesAll = exports.UuidStruct = exports.UrlStruct = exports.sanitizeUri = exports.sanitizeControlCharacters = exports.buildUrl = exports.safeMerge = exports.RemoteFeatureFlagsProvider = exports.REMOTE_FEATURE_FLAGS_PROVIDER_NAME = exports.AssetsProvider = exports.ASSETS_PROVIDER_NAME = void 0;
3
+ exports.InFlightCoalescer = exports.normalizeError = exports.isSnapRpcError = exports.createWithCatchAndThrowSnapError = exports.createTrackError = exports.createSnapErrorHandling = exports.validateOrigin = exports.DEFAULT_METAMASK_ORIGIN = exports.DEFAULT_DEV_ORIGINS = exports.DEFAULT_PROD_ORIGINS = exports.createOriginPermissions = exports.PROOF_OF_OWNERSHIP_MESSAGE_PREFIX = exports.ProofOfOwnershipMessageStruct = exports.ProofOfOwnershipBatchSuccessStruct = exports.ProofOfOwnershipBatchResponseStruct = exports.ProofOfOwnershipBatchRequestParamsStruct = exports.ProofOfOwnershipBatchRequestItemStruct = exports.ProofOfOwnershipBatchItemResponseStruct = exports.ProofOfOwnershipBatchErrorStruct = exports.parseProofOfOwnershipMessage = exports.deserialize = exports.serialize = exports.LogLevel = exports.Logger = exports.chunks = exports.batchesAllWithChunks = exports.batchesAllSettledWithChunks = exports.batchesAllSettled = exports.batchesAll = exports.UuidStruct = exports.UrlStruct = exports.sanitizeUri = exports.sanitizeControlCharacters = exports.buildUrl = exports.safeMerge = exports.RemoteFeatureFlagsProvider = exports.REMOTE_FEATURE_FLAGS_PROVIDER_NAME = exports.AssetsProvider = exports.ASSETS_PROVIDER_NAME = void 0;
4
4
  var AssetsProvider_1 = require("./providers/assets/AssetsProvider.cjs");
5
5
  Object.defineProperty(exports, "ASSETS_PROVIDER_NAME", { enumerable: true, get: function () { return AssetsProvider_1.ASSETS_PROVIDER_NAME; } });
6
6
  Object.defineProperty(exports, "AssetsProvider", { enumerable: true, get: function () { return AssetsProvider_1.AssetsProvider; } });
@@ -30,6 +30,16 @@ Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function ()
30
30
  var serialization_1 = require("./utils/serialization/serialization.cjs");
31
31
  Object.defineProperty(exports, "serialize", { enumerable: true, get: function () { return serialization_1.serialize; } });
32
32
  Object.defineProperty(exports, "deserialize", { enumerable: true, get: function () { return serialization_1.deserialize; } });
33
+ var proofOfOwnership_1 = require("./utils/proofOfOwnership/proofOfOwnership.cjs");
34
+ Object.defineProperty(exports, "parseProofOfOwnershipMessage", { enumerable: true, get: function () { return proofOfOwnership_1.parseProofOfOwnershipMessage; } });
35
+ Object.defineProperty(exports, "ProofOfOwnershipBatchErrorStruct", { enumerable: true, get: function () { return proofOfOwnership_1.ProofOfOwnershipBatchErrorStruct; } });
36
+ Object.defineProperty(exports, "ProofOfOwnershipBatchItemResponseStruct", { enumerable: true, get: function () { return proofOfOwnership_1.ProofOfOwnershipBatchItemResponseStruct; } });
37
+ Object.defineProperty(exports, "ProofOfOwnershipBatchRequestItemStruct", { enumerable: true, get: function () { return proofOfOwnership_1.ProofOfOwnershipBatchRequestItemStruct; } });
38
+ Object.defineProperty(exports, "ProofOfOwnershipBatchRequestParamsStruct", { enumerable: true, get: function () { return proofOfOwnership_1.ProofOfOwnershipBatchRequestParamsStruct; } });
39
+ Object.defineProperty(exports, "ProofOfOwnershipBatchResponseStruct", { enumerable: true, get: function () { return proofOfOwnership_1.ProofOfOwnershipBatchResponseStruct; } });
40
+ Object.defineProperty(exports, "ProofOfOwnershipBatchSuccessStruct", { enumerable: true, get: function () { return proofOfOwnership_1.ProofOfOwnershipBatchSuccessStruct; } });
41
+ Object.defineProperty(exports, "ProofOfOwnershipMessageStruct", { enumerable: true, get: function () { return proofOfOwnership_1.ProofOfOwnershipMessageStruct; } });
42
+ Object.defineProperty(exports, "PROOF_OF_OWNERSHIP_MESSAGE_PREFIX", { enumerable: true, get: function () { return proofOfOwnership_1.PROOF_OF_OWNERSHIP_MESSAGE_PREFIX; } });
33
43
  var createOriginPermissions_1 = require("./utils/originPermissions/createOriginPermissions.cjs");
34
44
  Object.defineProperty(exports, "createOriginPermissions", { enumerable: true, get: function () { return createOriginPermissions_1.createOriginPermissions; } });
35
45
  Object.defineProperty(exports, "DEFAULT_PROD_ORIGINS", { enumerable: true, get: function () { return createOriginPermissions_1.DEFAULT_PROD_ORIGINS; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wEAI2C;AAHzC,sHAAA,oBAAoB,OAAA;AACpB,gHAAA,cAAc,OAAA;AAGhB,8GAIqE;AAHnE,gJAAA,kCAAkC,OAAA;AAClC,wIAAA,0BAA0B,OAAA;AAG5B,6DAAwD;AAA/C,sGAAA,SAAS,OAAA;AAClB,0DAAqD;AAA5C,oGAAA,QAAQ,OAAA;AAEjB,0DAGmC;AAFjC,qHAAA,yBAAyB,OAAA;AACzB,uGAAA,WAAW,OAAA;AAEb,6DAAwD;AAA/C,sGAAA,SAAS,OAAA;AAClB,gEAA2D;AAAlD,wGAAA,UAAU,OAAA;AACnB,iDAM6B;AAL3B,mGAAA,UAAU,OAAA;AACV,0GAAA,iBAAiB,OAAA;AACjB,oHAAA,2BAA2B,OAAA;AAC3B,6GAAA,oBAAoB,OAAA;AACpB,+FAAA,MAAM,OAAA;AAER,oDAAyD;AAAhD,gGAAA,MAAM,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAQzB,yEAA6E;AAApE,0GAAA,SAAS,OAAA;AAAE,4GAAA,WAAW,OAAA;AAE/B,iGAK2D;AAJzD,kIAAA,uBAAuB,OAAA;AACvB,+HAAA,oBAAoB,OAAA;AACpB,8HAAA,mBAAmB,OAAA;AACnB,kIAAA,uBAAuB,OAAA;AAGzB,+EAA0E;AAAjE,gHAAA,cAAc,OAAA;AACvB,mDAMwB;AALtB,iHAAA,uBAAuB,OAAA;AACvB,0GAAA,gBAAgB,OAAA;AAChB,0HAAA,gCAAgC,OAAA;AAChC,wGAAA,cAAc,OAAA;AACd,wGAAA,cAAc,OAAA;AAEhB,0EAAqE;AAA5D,sHAAA,iBAAiB,OAAA","sourcesContent":["export {\n ASSETS_PROVIDER_NAME,\n AssetsProvider,\n type AssetsProviderMessenger,\n} from './providers/assets/AssetsProvider';\nexport {\n REMOTE_FEATURE_FLAGS_PROVIDER_NAME,\n RemoteFeatureFlagsProvider,\n type RemoteFeatureFlagsProviderMessenger,\n} from './providers/remote-feature-flags/RemoteFeatureFlagsProvider';\nexport { safeMerge } from './utils/safeMerge/safeMerge';\nexport { buildUrl } from './utils/buildUrl/buildUrl';\nexport type { BuildUrlParams } from './utils/buildUrl/buildUrl';\nexport {\n sanitizeControlCharacters,\n sanitizeUri,\n} from './utils/sanitize/sanitize';\nexport { UrlStruct } from './utils/urlStruct/urlStruct';\nexport { UuidStruct } from './utils/uuidStruct/uuidStruct';\nexport {\n batchesAll,\n batchesAllSettled,\n batchesAllSettledWithChunks,\n batchesAllWithChunks,\n chunks,\n} from './utils/async/async';\nexport { Logger, LogLevel } from './utils/logger/Logger';\nexport type {\n LoggerOptions,\n LoggerMethod,\n LogMethod,\n LogMethodDecorator,\n LoggerDecorators,\n} from './utils/logger/Logger';\nexport { serialize, deserialize } from './utils/serialization/serialization';\nexport type { Serializable } from './utils/serialization/types';\nexport {\n createOriginPermissions,\n DEFAULT_PROD_ORIGINS,\n DEFAULT_DEV_ORIGINS,\n DEFAULT_METAMASK_ORIGIN,\n} from './utils/originPermissions/createOriginPermissions';\nexport type { CreateOriginPermissionsParams } from './utils/originPermissions/createOriginPermissions';\nexport { validateOrigin } from './utils/originPermissions/validateOrigin';\nexport {\n createSnapErrorHandling,\n createTrackError,\n createWithCatchAndThrowSnapError,\n isSnapRpcError,\n normalizeError,\n} from './utils/errors';\nexport { InFlightCoalescer } from './utils/dedupe/InFlightCoalescer';\nexport type {\n CreateSnapErrorHandlingOptions,\n CreateTrackErrorOptions,\n CreateWithCatchAndThrowSnapErrorOptions,\n LogErrorFn,\n NormalizeErrorFn,\n PrepareErrorForTrackingFn,\n ShouldTrackErrorFn,\n SnapRpcError,\n SnapTrackErrorRequest,\n TrackErrorCapableProvider,\n TrackErrorFn,\n} from './utils/errors';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wEAI2C;AAHzC,sHAAA,oBAAoB,OAAA;AACpB,gHAAA,cAAc,OAAA;AAGhB,8GAIqE;AAHnE,gJAAA,kCAAkC,OAAA;AAClC,wIAAA,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ers/assets/AssetsProvider';\nexport {\n REMOTE_FEATURE_FLAGS_PROVIDER_NAME,\n RemoteFeatureFlagsProvider,\n type RemoteFeatureFlagsProviderMessenger,\n} from './providers/remote-feature-flags/RemoteFeatureFlagsProvider';\nexport { safeMerge } from './utils/safeMerge/safeMerge';\nexport { buildUrl } from './utils/buildUrl/buildUrl';\nexport type { BuildUrlParams } from './utils/buildUrl/buildUrl';\nexport {\n sanitizeControlCharacters,\n sanitizeUri,\n} from './utils/sanitize/sanitize';\nexport { UrlStruct } from './utils/urlStruct/urlStruct';\nexport { UuidStruct } from './utils/uuidStruct/uuidStruct';\nexport {\n batchesAll,\n batchesAllSettled,\n batchesAllSettledWithChunks,\n batchesAllWithChunks,\n chunks,\n} from './utils/async/async';\nexport { Logger, LogLevel } from './utils/logger/Logger';\nexport type {\n LoggerOptions,\n LoggerMethod,\n LogMethod,\n LogMethodDecorator,\n LoggerDecorators,\n} from './utils/logger/Logger';\nexport { serialize, deserialize } from './utils/serialization/serialization';\nexport type { Serializable } from './utils/serialization/types';\nexport {\n parseProofOfOwnershipMessage,\n ProofOfOwnershipBatchErrorStruct,\n ProofOfOwnershipBatchItemResponseStruct,\n ProofOfOwnershipBatchRequestItemStruct,\n ProofOfOwnershipBatchRequestParamsStruct,\n ProofOfOwnershipBatchResponseStruct,\n ProofOfOwnershipBatchSuccessStruct,\n ProofOfOwnershipMessageStruct,\n PROOF_OF_OWNERSHIP_MESSAGE_PREFIX,\n} from './utils/proofOfOwnership/proofOfOwnership';\nexport type {\n ProofOfOwnershipBatchError,\n ProofOfOwnershipBatchItemResponse,\n ProofOfOwnershipBatchRequestItem,\n ProofOfOwnershipBatchRequestParams,\n ProofOfOwnershipBatchResponse,\n ProofOfOwnershipBatchSuccess,\n ProofOfOwnershipMessage,\n} from './utils/proofOfOwnership/proofOfOwnership';\nexport {\n createOriginPermissions,\n DEFAULT_PROD_ORIGINS,\n DEFAULT_DEV_ORIGINS,\n DEFAULT_METAMASK_ORIGIN,\n} from './utils/originPermissions/createOriginPermissions';\nexport type { CreateOriginPermissionsParams } from './utils/originPermissions/createOriginPermissions';\nexport { validateOrigin } from './utils/originPermissions/validateOrigin';\nexport {\n createSnapErrorHandling,\n createTrackError,\n createWithCatchAndThrowSnapError,\n isSnapRpcError,\n normalizeError,\n} from './utils/errors';\nexport { InFlightCoalescer } from './utils/dedupe/InFlightCoalescer';\nexport type {\n CreateSnapErrorHandlingOptions,\n CreateTrackErrorOptions,\n CreateWithCatchAndThrowSnapErrorOptions,\n LogErrorFn,\n NormalizeErrorFn,\n PrepareErrorForTrackingFn,\n ShouldTrackErrorFn,\n SnapRpcError,\n SnapTrackErrorRequest,\n TrackErrorCapableProvider,\n TrackErrorFn,\n} from './utils/errors';\n"]}
package/dist/index.d.cts CHANGED
@@ -11,6 +11,8 @@ export { Logger, LogLevel } from "./utils/logger/Logger.cjs";
11
11
  export type { LoggerOptions, LoggerMethod, LogMethod, LogMethodDecorator, LoggerDecorators, } from "./utils/logger/Logger.cjs";
12
12
  export { serialize, deserialize } from "./utils/serialization/serialization.cjs";
13
13
  export type { Serializable } from "./utils/serialization/types.cjs";
14
+ export { parseProofOfOwnershipMessage, ProofOfOwnershipBatchErrorStruct, ProofOfOwnershipBatchItemResponseStruct, ProofOfOwnershipBatchRequestItemStruct, ProofOfOwnershipBatchRequestParamsStruct, ProofOfOwnershipBatchResponseStruct, ProofOfOwnershipBatchSuccessStruct, ProofOfOwnershipMessageStruct, PROOF_OF_OWNERSHIP_MESSAGE_PREFIX, } from "./utils/proofOfOwnership/proofOfOwnership.cjs";
15
+ export type { ProofOfOwnershipBatchError, ProofOfOwnershipBatchItemResponse, ProofOfOwnershipBatchRequestItem, ProofOfOwnershipBatchRequestParams, ProofOfOwnershipBatchResponse, ProofOfOwnershipBatchSuccess, ProofOfOwnershipMessage, } from "./utils/proofOfOwnership/proofOfOwnership.cjs";
14
16
  export { createOriginPermissions, DEFAULT_PROD_ORIGINS, DEFAULT_DEV_ORIGINS, DEFAULT_METAMASK_ORIGIN, } from "./utils/originPermissions/createOriginPermissions.cjs";
15
17
  export type { CreateOriginPermissionsParams } from "./utils/originPermissions/createOriginPermissions.cjs";
16
18
  export { validateOrigin } from "./utils/originPermissions/validateOrigin.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,KAAK,uBAAuB,GAC7B,8CAA0C;AAC3C,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAC1B,KAAK,mCAAmC,GACzC,wEAAoE;AACrE,OAAO,EAAE,SAAS,EAAE,wCAAoC;AACxD,OAAO,EAAE,QAAQ,EAAE,sCAAkC;AACrD,YAAY,EAAE,cAAc,EAAE,sCAAkC;AAChE,OAAO,EACL,yBAAyB,EACzB,WAAW,GACZ,sCAAkC;AACnC,OAAO,EAAE,SAAS,EAAE,wCAAoC;AACxD,OAAO,EAAE,UAAU,EAAE,0CAAsC;AAC3D,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,GACP,gCAA4B;AAC7B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,kCAA8B;AACzD,YAAY,EACV,aAAa,EACb,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,gBAAgB,GACjB,kCAA8B;AAC/B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,gDAA4C;AAC7E,YAAY,EAAE,YAAY,EAAE,wCAAoC;AAChE,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,GACxB,8DAA0D;AAC3D,YAAY,EAAE,6BAA6B,EAAE,8DAA0D;AACvG,OAAO,EAAE,cAAc,EAAE,qDAAiD;AAC1E,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,gCAAgC,EAChC,cAAc,EACd,cAAc,GACf,iCAAuB;AACxB,OAAO,EAAE,iBAAiB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4B,EAC5B,uBAAuB,GACxB,sDAAkD;AACnD,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,GACxB,8DAA0D;AAC3D,YAAY,EAAE,6BAA6B,EAAE,8DAA0D;AACvG,OAAO,EAAE,cAAc,EAAE,qDAAiD;AAC1E,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,gCAAgC,EAChC,cAAc,EACd,cAAc,GACf,iCAAuB;AACxB,OAAO,EAAE,iBAAiB,EAAE,6CAAyC;AACrE,YAAY,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,uCAAuC,EACvC,UAAU,EACV,gBAAgB,EAChB,yBAAyB,EACzB,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,yBAAyB,EACzB,YAAY,GACb,iCAAuB"}
package/dist/index.d.mts CHANGED
@@ -11,6 +11,8 @@ export { Logger, LogLevel } from "./utils/logger/Logger.mjs";
11
11
  export type { LoggerOptions, LoggerMethod, LogMethod, LogMethodDecorator, LoggerDecorators, } from "./utils/logger/Logger.mjs";
12
12
  export { serialize, deserialize } from "./utils/serialization/serialization.mjs";
13
13
  export type { Serializable } from "./utils/serialization/types.mjs";
14
+ export { parseProofOfOwnershipMessage, ProofOfOwnershipBatchErrorStruct, ProofOfOwnershipBatchItemResponseStruct, ProofOfOwnershipBatchRequestItemStruct, ProofOfOwnershipBatchRequestParamsStruct, ProofOfOwnershipBatchResponseStruct, ProofOfOwnershipBatchSuccessStruct, ProofOfOwnershipMessageStruct, PROOF_OF_OWNERSHIP_MESSAGE_PREFIX, } from "./utils/proofOfOwnership/proofOfOwnership.mjs";
15
+ export type { ProofOfOwnershipBatchError, ProofOfOwnershipBatchItemResponse, ProofOfOwnershipBatchRequestItem, ProofOfOwnershipBatchRequestParams, ProofOfOwnershipBatchResponse, ProofOfOwnershipBatchSuccess, ProofOfOwnershipMessage, } from "./utils/proofOfOwnership/proofOfOwnership.mjs";
14
16
  export { createOriginPermissions, DEFAULT_PROD_ORIGINS, DEFAULT_DEV_ORIGINS, DEFAULT_METAMASK_ORIGIN, } from "./utils/originPermissions/createOriginPermissions.mjs";
15
17
  export type { CreateOriginPermissionsParams } from "./utils/originPermissions/createOriginPermissions.mjs";
16
18
  export { validateOrigin } from "./utils/originPermissions/validateOrigin.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,KAAK,uBAAuB,GAC7B,8CAA0C;AAC3C,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAC1B,KAAK,mCAAmC,GACzC,wEAAoE;AACrE,OAAO,EAAE,SAAS,EAAE,wCAAoC;AACxD,OAAO,EAAE,QAAQ,EAAE,sCAAkC;AACrD,YAAY,EAAE,cAAc,EAAE,sCAAkC;AAChE,OAAO,EACL,yBAAyB,EACzB,WAAW,GACZ,sCAAkC;AACnC,OAAO,EAAE,SAAS,EAAE,wCAAoC;AACxD,OAAO,EAAE,UAAU,EAAE,0CAAsC;AAC3D,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,GACP,gCAA4B;AAC7B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,kCAA8B;AACzD,YAAY,EACV,aAAa,EACb,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,gBAAgB,GACjB,kCAA8B;AAC/B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,gDAA4C;AAC7E,YAAY,EAAE,YAAY,EAAE,wCAAoC;AAChE,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,GACxB,8DAA0D;AAC3D,YAAY,EAAE,6BAA6B,EAAE,8DAA0D;AACvG,OAAO,EAAE,cAAc,EAAE,qDAAiD;AAC1E,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,gCAAgC,EAChC,cAAc,EACd,cA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,EAChC,kCAAkC,EAClC,6BAA6B,EAC7B,4BAA4B,EAC5B,uBAAuB,GACxB,sDAAkD;AACnD,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,GACxB,8DAA0D;AAC3D,YAAY,EAAE,6BAA6B,EAAE,8DAA0D;AACvG,OAAO,EAAE,cAAc,EAAE,qDAAiD;AAC1E,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,gCAAgC,EAChC,cAAc,EACd,cAAc,GACf,iCAAuB;AACxB,OAAO,EAAE,iBAAiB,EAAE,6CAAyC;AACrE,YAAY,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,uCAAuC,EACvC,UAAU,EACV,gBAAgB,EAChB,yBAAyB,EACzB,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,yBAAyB,EACzB,YAAY,GACb,iCAAuB"}
package/dist/index.mjs CHANGED
@@ -8,6 +8,7 @@ export { UuidStruct } from "./utils/uuidStruct/uuidStruct.mjs";
8
8
  export { batchesAll, batchesAllSettled, batchesAllSettledWithChunks, batchesAllWithChunks, chunks } from "./utils/async/async.mjs";
9
9
  export { Logger, LogLevel } from "./utils/logger/Logger.mjs";
10
10
  export { serialize, deserialize } from "./utils/serialization/serialization.mjs";
11
+ export { parseProofOfOwnershipMessage, ProofOfOwnershipBatchErrorStruct, ProofOfOwnershipBatchItemResponseStruct, ProofOfOwnershipBatchRequestItemStruct, ProofOfOwnershipBatchRequestParamsStruct, ProofOfOwnershipBatchResponseStruct, ProofOfOwnershipBatchSuccessStruct, ProofOfOwnershipMessageStruct, PROOF_OF_OWNERSHIP_MESSAGE_PREFIX } from "./utils/proofOfOwnership/proofOfOwnership.mjs";
11
12
  export { createOriginPermissions, DEFAULT_PROD_ORIGINS, DEFAULT_DEV_ORIGINS, DEFAULT_METAMASK_ORIGIN } from "./utils/originPermissions/createOriginPermissions.mjs";
12
13
  export { validateOrigin } from "./utils/originPermissions/validateOrigin.mjs";
13
14
  export { createSnapErrorHandling, createTrackError, createWithCatchAndThrowSnapError, isSnapRpcError, normalizeError } from "./utils/errors/index.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EAEf,8CAA0C;AAC3C,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAE3B,wEAAoE;AACrE,OAAO,EAAE,SAAS,EAAE,wCAAoC;AACxD,OAAO,EAAE,QAAQ,EAAE,sCAAkC;AAErD,OAAO,EACL,yBAAyB,EACzB,WAAW,EACZ,sCAAkC;AACnC,OAAO,EAAE,SAAS,EAAE,wCAAoC;AACxD,OAAO,EAAE,UAAU,EAAE,0CAAsC;AAC3D,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,EACP,gCAA4B;AAC7B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,kCAA8B;AAQzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,gDAA4C;AAE7E,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,EACxB,8DAA0D;AAE3D,OAAO,EAAE,cAAc,EAAE,qDAAiD;AAC1E,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,gCAAgC,EAChC,cAAc,EACd,cAAc,EACf,iCAAuB;AACxB,OAAO,EAAE,iBAAiB,EAAE,6CAAyC","sourcesContent":["export {\n ASSETS_PROVIDER_NAME,\n AssetsProvider,\n type AssetsProviderMessenger,\n} from './providers/assets/AssetsProvider';\nexport {\n REMOTE_FEATURE_FLAGS_PROVIDER_NAME,\n RemoteFeatureFlagsProvider,\n type RemoteFeatureFlagsProviderMessenger,\n} from './providers/remote-feature-flags/RemoteFeatureFlagsProvider';\nexport { safeMerge } from './utils/safeMerge/safeMerge';\nexport { buildUrl } from './utils/buildUrl/buildUrl';\nexport type { BuildUrlParams } from './utils/buildUrl/buildUrl';\nexport {\n sanitizeControlCharacters,\n sanitizeUri,\n} from './utils/sanitize/sanitize';\nexport { UrlStruct } from './utils/urlStruct/urlStruct';\nexport { UuidStruct } from './utils/uuidStruct/uuidStruct';\nexport {\n batchesAll,\n batchesAllSettled,\n batchesAllSettledWithChunks,\n batchesAllWithChunks,\n chunks,\n} from './utils/async/async';\nexport { Logger, LogLevel } from './utils/logger/Logger';\nexport type {\n LoggerOptions,\n LoggerMethod,\n LogMethod,\n LogMethodDecorator,\n LoggerDecorators,\n} from './utils/logger/Logger';\nexport { serialize, deserialize } from './utils/serialization/serialization';\nexport type { Serializable } from './utils/serialization/types';\nexport {\n createOriginPermissions,\n DEFAULT_PROD_ORIGINS,\n DEFAULT_DEV_ORIGINS,\n DEFAULT_METAMASK_ORIGIN,\n} from './utils/originPermissions/createOriginPermissions';\nexport type { CreateOriginPermissionsParams } from './utils/originPermissions/createOriginPermissions';\nexport { validateOrigin } from './utils/originPermissions/validateOrigin';\nexport {\n createSnapErrorHandling,\n createTrackError,\n createWithCatchAndThrowSnapError,\n isSnapRpcError,\n normalizeError,\n} from './utils/errors';\nexport { InFlightCoalescer } from './utils/dedupe/InFlightCoalescer';\nexport type {\n CreateSnapErrorHandlingOptions,\n CreateTrackErrorOptions,\n CreateWithCatchAndThrowSnapErrorOptions,\n LogErrorFn,\n NormalizeErrorFn,\n PrepareErrorForTrackingFn,\n ShouldTrackErrorFn,\n SnapRpcError,\n SnapTrackErrorRequest,\n TrackErrorCapableProvider,\n TrackErrorFn,\n} from './utils/errors';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EAEf,8CAA0C;AAC3C,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAE3B,wEAAoE;AACrE,OAAO,EAAE,SAAS,EAAE,wCAAoC;AACxD,OAAO,EAAE,QAAQ,EAAE,sCAAkC;AAErD,OAAO,EACL,yBAAyB,EACzB,WAAW,EACZ,sCAAkC;AACnC,OAAO,EAAE,SAAS,EAAE,wCAAoC;AACxD,OAAO,EAAE,UAAU,EAAE,0CAAsC;AAC3D,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,EACP,gCAA4B;AAC7B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,kCAA8B;AAQzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,gDAA4C;AAE7E,OAAO,EACL,4BAA4B,EAC5B,gCAAgC,EAChC,uCAAuC,EACvC,sCAAsC,EACtC,wCAAwC,EACxC,mCAAmC,EACnC,kCAAkC,EAClC,6BAA6B,EAC7B,iCAAiC,EAClC,sDAAkD;AAUnD,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,EACxB,8DAA0D;AAE3D,OAAO,EAAE,cAAc,EAAE,qDAAiD;AAC1E,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,gCAAgC,EAChC,cAAc,EACd,cAAc,EACf,iCAAuB;AACxB,OAAO,EAAE,iBAAiB,EAAE,6CAAyC","sourcesContent":["export {\n ASSETS_PROVIDER_NAME,\n AssetsProvider,\n type AssetsProviderMessenger,\n} from './providers/assets/AssetsProvider';\nexport {\n REMOTE_FEATURE_FLAGS_PROVIDER_NAME,\n RemoteFeatureFlagsProvider,\n type RemoteFeatureFlagsProviderMessenger,\n} from './providers/remote-feature-flags/RemoteFeatureFlagsProvider';\nexport { safeMerge } from './utils/safeMerge/safeMerge';\nexport { buildUrl } from './utils/buildUrl/buildUrl';\nexport type { BuildUrlParams } from './utils/buildUrl/buildUrl';\nexport {\n sanitizeControlCharacters,\n sanitizeUri,\n} from './utils/sanitize/sanitize';\nexport { UrlStruct } from './utils/urlStruct/urlStruct';\nexport { UuidStruct } from './utils/uuidStruct/uuidStruct';\nexport {\n batchesAll,\n batchesAllSettled,\n batchesAllSettledWithChunks,\n batchesAllWithChunks,\n chunks,\n} from './utils/async/async';\nexport { Logger, LogLevel } from './utils/logger/Logger';\nexport type {\n LoggerOptions,\n LoggerMethod,\n LogMethod,\n LogMethodDecorator,\n LoggerDecorators,\n} from './utils/logger/Logger';\nexport { serialize, deserialize } from './utils/serialization/serialization';\nexport type { Serializable } from './utils/serialization/types';\nexport {\n parseProofOfOwnershipMessage,\n ProofOfOwnershipBatchErrorStruct,\n ProofOfOwnershipBatchItemResponseStruct,\n ProofOfOwnershipBatchRequestItemStruct,\n ProofOfOwnershipBatchRequestParamsStruct,\n ProofOfOwnershipBatchResponseStruct,\n ProofOfOwnershipBatchSuccessStruct,\n ProofOfOwnershipMessageStruct,\n PROOF_OF_OWNERSHIP_MESSAGE_PREFIX,\n} from './utils/proofOfOwnership/proofOfOwnership';\nexport type {\n ProofOfOwnershipBatchError,\n ProofOfOwnershipBatchItemResponse,\n ProofOfOwnershipBatchRequestItem,\n ProofOfOwnershipBatchRequestParams,\n ProofOfOwnershipBatchResponse,\n ProofOfOwnershipBatchSuccess,\n ProofOfOwnershipMessage,\n} from './utils/proofOfOwnership/proofOfOwnership';\nexport {\n createOriginPermissions,\n DEFAULT_PROD_ORIGINS,\n DEFAULT_DEV_ORIGINS,\n DEFAULT_METAMASK_ORIGIN,\n} from './utils/originPermissions/createOriginPermissions';\nexport type { CreateOriginPermissionsParams } from './utils/originPermissions/createOriginPermissions';\nexport { validateOrigin } from './utils/originPermissions/validateOrigin';\nexport {\n createSnapErrorHandling,\n createTrackError,\n createWithCatchAndThrowSnapError,\n isSnapRpcError,\n normalizeError,\n} from './utils/errors';\nexport { InFlightCoalescer } from './utils/dedupe/InFlightCoalescer';\nexport type {\n CreateSnapErrorHandlingOptions,\n CreateTrackErrorOptions,\n CreateWithCatchAndThrowSnapErrorOptions,\n LogErrorFn,\n NormalizeErrorFn,\n PrepareErrorForTrackingFn,\n ShouldTrackErrorFn,\n SnapRpcError,\n SnapTrackErrorRequest,\n TrackErrorCapableProvider,\n TrackErrorFn,\n} from './utils/errors';\n"]}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProofOfOwnershipBatchResponseStruct = exports.ProofOfOwnershipBatchItemResponseStruct = exports.ProofOfOwnershipBatchErrorStruct = exports.ProofOfOwnershipBatchSuccessStruct = exports.ProofOfOwnershipBatchRequestParamsStruct = exports.ProofOfOwnershipBatchRequestItemStruct = exports.ProofOfOwnershipMessageStruct = exports.PROOF_OF_OWNERSHIP_MESSAGE_PREFIX = void 0;
4
+ exports.parseProofOfOwnershipMessage = parseProofOfOwnershipMessage;
5
+ const superstruct_1 = require("@metamask/superstruct");
6
+ const uuidStruct_1 = require("../uuidStruct/uuidStruct.cjs");
7
+ /**
8
+ * Prefix for proof-of-ownership messages signed by network snaps.
9
+ */
10
+ exports.PROOF_OF_OWNERSHIP_MESSAGE_PREFIX = 'metamask:proof-of-ownership:';
11
+ /**
12
+ * Validates parsed proof-of-ownership message fields.
13
+ */
14
+ exports.ProofOfOwnershipMessageStruct = (0, superstruct_1.object)({
15
+ nonce: (0, superstruct_1.nonempty)((0, superstruct_1.string)()),
16
+ address: (0, superstruct_1.nonempty)((0, superstruct_1.string)()),
17
+ });
18
+ /**
19
+ * Validates one proof-of-ownership batch request item.
20
+ */
21
+ exports.ProofOfOwnershipBatchRequestItemStruct = (0, superstruct_1.object)({
22
+ accountId: uuidStruct_1.UuidStruct,
23
+ message: (0, superstruct_1.string)(),
24
+ });
25
+ /**
26
+ * Validates proof-of-ownership batch request params.
27
+ */
28
+ exports.ProofOfOwnershipBatchRequestParamsStruct = (0, superstruct_1.object)({
29
+ items: (0, superstruct_1.array)(exports.ProofOfOwnershipBatchRequestItemStruct),
30
+ });
31
+ /**
32
+ * Validates one successful proof-of-ownership batch result.
33
+ */
34
+ exports.ProofOfOwnershipBatchSuccessStruct = (0, superstruct_1.object)({
35
+ accountId: uuidStruct_1.UuidStruct,
36
+ signature: (0, superstruct_1.string)(),
37
+ });
38
+ /**
39
+ * Validates one failed proof-of-ownership batch result.
40
+ */
41
+ exports.ProofOfOwnershipBatchErrorStruct = (0, superstruct_1.object)({
42
+ accountId: uuidStruct_1.UuidStruct,
43
+ error: (0, superstruct_1.nonempty)((0, superstruct_1.string)()),
44
+ });
45
+ /**
46
+ * Validates one proof-of-ownership batch result.
47
+ */
48
+ exports.ProofOfOwnershipBatchItemResponseStruct = (0, superstruct_1.union)([
49
+ exports.ProofOfOwnershipBatchSuccessStruct,
50
+ exports.ProofOfOwnershipBatchErrorStruct,
51
+ ]);
52
+ /**
53
+ * Validates a proof-of-ownership batch response.
54
+ */
55
+ exports.ProofOfOwnershipBatchResponseStruct = (0, superstruct_1.object)({
56
+ results: (0, superstruct_1.array)(exports.ProofOfOwnershipBatchItemResponseStruct),
57
+ });
58
+ /**
59
+ * Parses a plaintext proof-of-ownership message in the format
60
+ * `metamask:proof-of-ownership:{nonce}:{address}`.
61
+ *
62
+ * Address validity is intentionally not checked here because it is
63
+ * chain-specific. Callers should validate the returned address with the
64
+ * relevant network/address validator.
65
+ *
66
+ * @param message - The plaintext message to parse.
67
+ * @returns The parsed nonce and address.
68
+ * @throws Error if the message format is invalid.
69
+ */
70
+ function parseProofOfOwnershipMessage(message) {
71
+ if (!message.startsWith(exports.PROOF_OF_OWNERSHIP_MESSAGE_PREFIX)) {
72
+ throw new Error(`Message must start with "${exports.PROOF_OF_OWNERSHIP_MESSAGE_PREFIX}"`);
73
+ }
74
+ const remainder = message.slice(exports.PROOF_OF_OWNERSHIP_MESSAGE_PREFIX.length);
75
+ const separatorIndex = remainder.lastIndexOf(':');
76
+ if (separatorIndex === -1) {
77
+ throw new Error('Message must follow the format "metamask:proof-of-ownership:{nonce}:{address}"');
78
+ }
79
+ const nonce = remainder.slice(0, separatorIndex);
80
+ const address = remainder.slice(separatorIndex + 1);
81
+ if (nonce.length === 0) {
82
+ throw new Error('Message must include a non-empty nonce');
83
+ }
84
+ if (address.length === 0) {
85
+ throw new Error('Message must include a non-empty address');
86
+ }
87
+ return { nonce, address };
88
+ }
89
+ //# sourceMappingURL=proofOfOwnership.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proofOfOwnership.cjs","sourceRoot":"","sources":["../../../src/utils/proofOfOwnership/proofOfOwnership.ts"],"names":[],"mappings":";;;AA6HA,oEA6BC;AAzJD,uDAA+E;AAE/E,6DAAsD;AAEtD;;GAEG;AACU,QAAA,iCAAiC,GAAG,8BAA8B,CAAC;AAEhF;;GAEG;AACU,QAAA,6BAA6B,GAAG,IAAA,oBAAM,EAAC;IAClD,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACzB,OAAO,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAC5B,CAAC,CAAC;AASH;;GAEG;AACU,QAAA,sCAAsC,GAAG,IAAA,oBAAM,EAAC;IAC3D,SAAS,EAAE,uBAAU;IACrB,OAAO,EAAE,IAAA,oBAAM,GAAE;CAClB,CAAC,CAAC;AASH;;GAEG;AACU,QAAA,wCAAwC,GAAG,IAAA,oBAAM,EAAC;IAC7D,KAAK,EAAE,IAAA,mBAAK,EAAC,8CAAsC,CAAC;CACrD,CAAC,CAAC;AASH;;GAEG;AACU,QAAA,kCAAkC,GAAG,IAAA,oBAAM,EAAC;IACvD,SAAS,EAAE,uBAAU;IACrB,SAAS,EAAE,IAAA,oBAAM,GAAE;CACpB,CAAC,CAAC;AASH;;GAEG;AACU,QAAA,gCAAgC,GAAG,IAAA,oBAAM,EAAC;IACrD,SAAS,EAAE,uBAAU;IACrB,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAC1B,CAAC,CAAC;AASH;;GAEG;AACU,QAAA,uCAAuC,GAAG,IAAA,mBAAK,EAAC;IAC3D,0CAAkC;IAClC,wCAAgC;CACjC,CAAC,CAAC;AASH;;GAEG;AACU,QAAA,mCAAmC,GAAG,IAAA,oBAAM,EAAC;IACxD,OAAO,EAAE,IAAA,mBAAK,EAAC,+CAAuC,CAAC;CACxD,CAAC,CAAC;AASH;;;;;;;;;;;GAWG;AACH,SAAgB,4BAA4B,CAC1C,OAAe;IAEf,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,yCAAiC,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CACb,4BAA4B,yCAAiC,GAAG,CACjE,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,yCAAiC,CAAC,MAAM,CAAC,CAAC;IAC1E,MAAM,cAAc,GAAG,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAClD,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,gFAAgF,CACjF,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;IAEpD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { array, nonempty, object, string, union } from '@metamask/superstruct';\n\nimport { UuidStruct } from '../uuidStruct/uuidStruct';\n\n/**\n * Prefix for proof-of-ownership messages signed by network snaps.\n */\nexport const PROOF_OF_OWNERSHIP_MESSAGE_PREFIX = 'metamask:proof-of-ownership:';\n\n/**\n * Validates parsed proof-of-ownership message fields.\n */\nexport const ProofOfOwnershipMessageStruct = object({\n nonce: nonempty(string()),\n address: nonempty(string()),\n});\n\n/**\n * Parsed proof-of-ownership message fields.\n */\nexport type ProofOfOwnershipMessage = Infer<\n typeof ProofOfOwnershipMessageStruct\n>;\n\n/**\n * Validates one proof-of-ownership batch request item.\n */\nexport const ProofOfOwnershipBatchRequestItemStruct = object({\n accountId: UuidStruct,\n message: string(),\n});\n\n/**\n * One proof-of-ownership batch request item.\n */\nexport type ProofOfOwnershipBatchRequestItem = Infer<\n typeof ProofOfOwnershipBatchRequestItemStruct\n>;\n\n/**\n * Validates proof-of-ownership batch request params.\n */\nexport const ProofOfOwnershipBatchRequestParamsStruct = object({\n items: array(ProofOfOwnershipBatchRequestItemStruct),\n});\n\n/**\n * Proof-of-ownership batch request params.\n */\nexport type ProofOfOwnershipBatchRequestParams = Infer<\n typeof ProofOfOwnershipBatchRequestParamsStruct\n>;\n\n/**\n * Validates one successful proof-of-ownership batch result.\n */\nexport const ProofOfOwnershipBatchSuccessStruct = object({\n accountId: UuidStruct,\n signature: string(),\n});\n\n/**\n * One successful proof-of-ownership batch result.\n */\nexport type ProofOfOwnershipBatchSuccess = Infer<\n typeof ProofOfOwnershipBatchSuccessStruct\n>;\n\n/**\n * Validates one failed proof-of-ownership batch result.\n */\nexport const ProofOfOwnershipBatchErrorStruct = object({\n accountId: UuidStruct,\n error: nonempty(string()),\n});\n\n/**\n * One failed proof-of-ownership batch result.\n */\nexport type ProofOfOwnershipBatchError = Infer<\n typeof ProofOfOwnershipBatchErrorStruct\n>;\n\n/**\n * Validates one proof-of-ownership batch result.\n */\nexport const ProofOfOwnershipBatchItemResponseStruct = union([\n ProofOfOwnershipBatchSuccessStruct,\n ProofOfOwnershipBatchErrorStruct,\n]);\n\n/**\n * One proof-of-ownership batch result.\n */\nexport type ProofOfOwnershipBatchItemResponse = Infer<\n typeof ProofOfOwnershipBatchItemResponseStruct\n>;\n\n/**\n * Validates a proof-of-ownership batch response.\n */\nexport const ProofOfOwnershipBatchResponseStruct = object({\n results: array(ProofOfOwnershipBatchItemResponseStruct),\n});\n\n/**\n * Proof-of-ownership batch response shape.\n */\nexport type ProofOfOwnershipBatchResponse = Infer<\n typeof ProofOfOwnershipBatchResponseStruct\n>;\n\n/**\n * Parses a plaintext proof-of-ownership message in the format\n * `metamask:proof-of-ownership:{nonce}:{address}`.\n *\n * Address validity is intentionally not checked here because it is\n * chain-specific. Callers should validate the returned address with the\n * relevant network/address validator.\n *\n * @param message - The plaintext message to parse.\n * @returns The parsed nonce and address.\n * @throws Error if the message format is invalid.\n */\nexport function parseProofOfOwnershipMessage(\n message: string,\n): ProofOfOwnershipMessage {\n if (!message.startsWith(PROOF_OF_OWNERSHIP_MESSAGE_PREFIX)) {\n throw new Error(\n `Message must start with \"${PROOF_OF_OWNERSHIP_MESSAGE_PREFIX}\"`,\n );\n }\n\n const remainder = message.slice(PROOF_OF_OWNERSHIP_MESSAGE_PREFIX.length);\n const separatorIndex = remainder.lastIndexOf(':');\n if (separatorIndex === -1) {\n throw new Error(\n 'Message must follow the format \"metamask:proof-of-ownership:{nonce}:{address}\"',\n );\n }\n\n const nonce = remainder.slice(0, separatorIndex);\n const address = remainder.slice(separatorIndex + 1);\n\n if (nonce.length === 0) {\n throw new Error('Message must include a non-empty nonce');\n }\n\n if (address.length === 0) {\n throw new Error('Message must include a non-empty address');\n }\n\n return { nonce, address };\n}\n"]}
@@ -0,0 +1,143 @@
1
+ import type { Infer } from "@metamask/superstruct";
2
+ /**
3
+ * Prefix for proof-of-ownership messages signed by network snaps.
4
+ */
5
+ export declare const PROOF_OF_OWNERSHIP_MESSAGE_PREFIX = "metamask:proof-of-ownership:";
6
+ /**
7
+ * Validates parsed proof-of-ownership message fields.
8
+ */
9
+ export declare const ProofOfOwnershipMessageStruct: import("@metamask/superstruct").Struct<{
10
+ nonce: string;
11
+ address: string;
12
+ }, {
13
+ nonce: import("@metamask/superstruct").Struct<string, null>;
14
+ address: import("@metamask/superstruct").Struct<string, null>;
15
+ }>;
16
+ /**
17
+ * Parsed proof-of-ownership message fields.
18
+ */
19
+ export type ProofOfOwnershipMessage = Infer<typeof ProofOfOwnershipMessageStruct>;
20
+ /**
21
+ * Validates one proof-of-ownership batch request item.
22
+ */
23
+ export declare const ProofOfOwnershipBatchRequestItemStruct: import("@metamask/superstruct").Struct<{
24
+ message: string;
25
+ accountId: string;
26
+ }, {
27
+ accountId: import("@metamask/superstruct").Struct<string, null>;
28
+ message: import("@metamask/superstruct").Struct<string, null>;
29
+ }>;
30
+ /**
31
+ * One proof-of-ownership batch request item.
32
+ */
33
+ export type ProofOfOwnershipBatchRequestItem = Infer<typeof ProofOfOwnershipBatchRequestItemStruct>;
34
+ /**
35
+ * Validates proof-of-ownership batch request params.
36
+ */
37
+ export declare const ProofOfOwnershipBatchRequestParamsStruct: import("@metamask/superstruct").Struct<{
38
+ items: {
39
+ message: string;
40
+ accountId: string;
41
+ }[];
42
+ }, {
43
+ items: import("@metamask/superstruct").Struct<{
44
+ message: string;
45
+ accountId: string;
46
+ }[], import("@metamask/superstruct").Struct<{
47
+ message: string;
48
+ accountId: string;
49
+ }, {
50
+ accountId: import("@metamask/superstruct").Struct<string, null>;
51
+ message: import("@metamask/superstruct").Struct<string, null>;
52
+ }>>;
53
+ }>;
54
+ /**
55
+ * Proof-of-ownership batch request params.
56
+ */
57
+ export type ProofOfOwnershipBatchRequestParams = Infer<typeof ProofOfOwnershipBatchRequestParamsStruct>;
58
+ /**
59
+ * Validates one successful proof-of-ownership batch result.
60
+ */
61
+ export declare const ProofOfOwnershipBatchSuccessStruct: import("@metamask/superstruct").Struct<{
62
+ accountId: string;
63
+ signature: string;
64
+ }, {
65
+ accountId: import("@metamask/superstruct").Struct<string, null>;
66
+ signature: import("@metamask/superstruct").Struct<string, null>;
67
+ }>;
68
+ /**
69
+ * One successful proof-of-ownership batch result.
70
+ */
71
+ export type ProofOfOwnershipBatchSuccess = Infer<typeof ProofOfOwnershipBatchSuccessStruct>;
72
+ /**
73
+ * Validates one failed proof-of-ownership batch result.
74
+ */
75
+ export declare const ProofOfOwnershipBatchErrorStruct: import("@metamask/superstruct").Struct<{
76
+ error: string;
77
+ accountId: string;
78
+ }, {
79
+ accountId: import("@metamask/superstruct").Struct<string, null>;
80
+ error: import("@metamask/superstruct").Struct<string, null>;
81
+ }>;
82
+ /**
83
+ * One failed proof-of-ownership batch result.
84
+ */
85
+ export type ProofOfOwnershipBatchError = Infer<typeof ProofOfOwnershipBatchErrorStruct>;
86
+ /**
87
+ * Validates one proof-of-ownership batch result.
88
+ */
89
+ export declare const ProofOfOwnershipBatchItemResponseStruct: import("@metamask/superstruct").Struct<{
90
+ accountId: string;
91
+ signature: string;
92
+ } | {
93
+ error: string;
94
+ accountId: string;
95
+ }, null>;
96
+ /**
97
+ * One proof-of-ownership batch result.
98
+ */
99
+ export type ProofOfOwnershipBatchItemResponse = Infer<typeof ProofOfOwnershipBatchItemResponseStruct>;
100
+ /**
101
+ * Validates a proof-of-ownership batch response.
102
+ */
103
+ export declare const ProofOfOwnershipBatchResponseStruct: import("@metamask/superstruct").Struct<{
104
+ results: ({
105
+ accountId: string;
106
+ signature: string;
107
+ } | {
108
+ error: string;
109
+ accountId: string;
110
+ })[];
111
+ }, {
112
+ results: import("@metamask/superstruct").Struct<({
113
+ accountId: string;
114
+ signature: string;
115
+ } | {
116
+ error: string;
117
+ accountId: string;
118
+ })[], import("@metamask/superstruct").Struct<{
119
+ accountId: string;
120
+ signature: string;
121
+ } | {
122
+ error: string;
123
+ accountId: string;
124
+ }, null>>;
125
+ }>;
126
+ /**
127
+ * Proof-of-ownership batch response shape.
128
+ */
129
+ export type ProofOfOwnershipBatchResponse = Infer<typeof ProofOfOwnershipBatchResponseStruct>;
130
+ /**
131
+ * Parses a plaintext proof-of-ownership message in the format
132
+ * `metamask:proof-of-ownership:{nonce}:{address}`.
133
+ *
134
+ * Address validity is intentionally not checked here because it is
135
+ * chain-specific. Callers should validate the returned address with the
136
+ * relevant network/address validator.
137
+ *
138
+ * @param message - The plaintext message to parse.
139
+ * @returns The parsed nonce and address.
140
+ * @throws Error if the message format is invalid.
141
+ */
142
+ export declare function parseProofOfOwnershipMessage(message: string): ProofOfOwnershipMessage;
143
+ //# sourceMappingURL=proofOfOwnership.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proofOfOwnership.d.cts","sourceRoot":"","sources":["../../../src/utils/proofOfOwnership/proofOfOwnership.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAKnD;;GAEG;AACH,eAAO,MAAM,iCAAiC,iCAAiC,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,6BAA6B;;;;;;EAGxC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,KAAK,CACzC,OAAO,6BAA6B,CACrC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sCAAsC;;;;;;EAGjD,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG,KAAK,CAClD,OAAO,sCAAsC,CAC9C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wCAAwC;;;;;;;;;;;;;;;;EAEnD,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG,KAAK,CACpD,OAAO,wCAAwC,CAChD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kCAAkC;;;;;;EAG7C,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,KAAK,CAC9C,OAAO,kCAAkC,CAC1C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gCAAgC;;;;;;EAG3C,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,KAAK,CAC5C,OAAO,gCAAgC,CACxC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uCAAuC;;;;;;QAGlD,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,iCAAiC,GAAG,KAAK,CACnD,OAAO,uCAAuC,CAC/C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mCAAmC;;;;;;;;;;;;;;;;;;;;;;EAE9C,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,KAAK,CAC/C,OAAO,mCAAmC,CAC3C,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,MAAM,GACd,uBAAuB,CA2BzB"}
@@ -0,0 +1,143 @@
1
+ import type { Infer } from "@metamask/superstruct";
2
+ /**
3
+ * Prefix for proof-of-ownership messages signed by network snaps.
4
+ */
5
+ export declare const PROOF_OF_OWNERSHIP_MESSAGE_PREFIX = "metamask:proof-of-ownership:";
6
+ /**
7
+ * Validates parsed proof-of-ownership message fields.
8
+ */
9
+ export declare const ProofOfOwnershipMessageStruct: import("@metamask/superstruct").Struct<{
10
+ nonce: string;
11
+ address: string;
12
+ }, {
13
+ nonce: import("@metamask/superstruct").Struct<string, null>;
14
+ address: import("@metamask/superstruct").Struct<string, null>;
15
+ }>;
16
+ /**
17
+ * Parsed proof-of-ownership message fields.
18
+ */
19
+ export type ProofOfOwnershipMessage = Infer<typeof ProofOfOwnershipMessageStruct>;
20
+ /**
21
+ * Validates one proof-of-ownership batch request item.
22
+ */
23
+ export declare const ProofOfOwnershipBatchRequestItemStruct: import("@metamask/superstruct").Struct<{
24
+ message: string;
25
+ accountId: string;
26
+ }, {
27
+ accountId: import("@metamask/superstruct").Struct<string, null>;
28
+ message: import("@metamask/superstruct").Struct<string, null>;
29
+ }>;
30
+ /**
31
+ * One proof-of-ownership batch request item.
32
+ */
33
+ export type ProofOfOwnershipBatchRequestItem = Infer<typeof ProofOfOwnershipBatchRequestItemStruct>;
34
+ /**
35
+ * Validates proof-of-ownership batch request params.
36
+ */
37
+ export declare const ProofOfOwnershipBatchRequestParamsStruct: import("@metamask/superstruct").Struct<{
38
+ items: {
39
+ message: string;
40
+ accountId: string;
41
+ }[];
42
+ }, {
43
+ items: import("@metamask/superstruct").Struct<{
44
+ message: string;
45
+ accountId: string;
46
+ }[], import("@metamask/superstruct").Struct<{
47
+ message: string;
48
+ accountId: string;
49
+ }, {
50
+ accountId: import("@metamask/superstruct").Struct<string, null>;
51
+ message: import("@metamask/superstruct").Struct<string, null>;
52
+ }>>;
53
+ }>;
54
+ /**
55
+ * Proof-of-ownership batch request params.
56
+ */
57
+ export type ProofOfOwnershipBatchRequestParams = Infer<typeof ProofOfOwnershipBatchRequestParamsStruct>;
58
+ /**
59
+ * Validates one successful proof-of-ownership batch result.
60
+ */
61
+ export declare const ProofOfOwnershipBatchSuccessStruct: import("@metamask/superstruct").Struct<{
62
+ accountId: string;
63
+ signature: string;
64
+ }, {
65
+ accountId: import("@metamask/superstruct").Struct<string, null>;
66
+ signature: import("@metamask/superstruct").Struct<string, null>;
67
+ }>;
68
+ /**
69
+ * One successful proof-of-ownership batch result.
70
+ */
71
+ export type ProofOfOwnershipBatchSuccess = Infer<typeof ProofOfOwnershipBatchSuccessStruct>;
72
+ /**
73
+ * Validates one failed proof-of-ownership batch result.
74
+ */
75
+ export declare const ProofOfOwnershipBatchErrorStruct: import("@metamask/superstruct").Struct<{
76
+ error: string;
77
+ accountId: string;
78
+ }, {
79
+ accountId: import("@metamask/superstruct").Struct<string, null>;
80
+ error: import("@metamask/superstruct").Struct<string, null>;
81
+ }>;
82
+ /**
83
+ * One failed proof-of-ownership batch result.
84
+ */
85
+ export type ProofOfOwnershipBatchError = Infer<typeof ProofOfOwnershipBatchErrorStruct>;
86
+ /**
87
+ * Validates one proof-of-ownership batch result.
88
+ */
89
+ export declare const ProofOfOwnershipBatchItemResponseStruct: import("@metamask/superstruct").Struct<{
90
+ accountId: string;
91
+ signature: string;
92
+ } | {
93
+ error: string;
94
+ accountId: string;
95
+ }, null>;
96
+ /**
97
+ * One proof-of-ownership batch result.
98
+ */
99
+ export type ProofOfOwnershipBatchItemResponse = Infer<typeof ProofOfOwnershipBatchItemResponseStruct>;
100
+ /**
101
+ * Validates a proof-of-ownership batch response.
102
+ */
103
+ export declare const ProofOfOwnershipBatchResponseStruct: import("@metamask/superstruct").Struct<{
104
+ results: ({
105
+ accountId: string;
106
+ signature: string;
107
+ } | {
108
+ error: string;
109
+ accountId: string;
110
+ })[];
111
+ }, {
112
+ results: import("@metamask/superstruct").Struct<({
113
+ accountId: string;
114
+ signature: string;
115
+ } | {
116
+ error: string;
117
+ accountId: string;
118
+ })[], import("@metamask/superstruct").Struct<{
119
+ accountId: string;
120
+ signature: string;
121
+ } | {
122
+ error: string;
123
+ accountId: string;
124
+ }, null>>;
125
+ }>;
126
+ /**
127
+ * Proof-of-ownership batch response shape.
128
+ */
129
+ export type ProofOfOwnershipBatchResponse = Infer<typeof ProofOfOwnershipBatchResponseStruct>;
130
+ /**
131
+ * Parses a plaintext proof-of-ownership message in the format
132
+ * `metamask:proof-of-ownership:{nonce}:{address}`.
133
+ *
134
+ * Address validity is intentionally not checked here because it is
135
+ * chain-specific. Callers should validate the returned address with the
136
+ * relevant network/address validator.
137
+ *
138
+ * @param message - The plaintext message to parse.
139
+ * @returns The parsed nonce and address.
140
+ * @throws Error if the message format is invalid.
141
+ */
142
+ export declare function parseProofOfOwnershipMessage(message: string): ProofOfOwnershipMessage;
143
+ //# sourceMappingURL=proofOfOwnership.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proofOfOwnership.d.mts","sourceRoot":"","sources":["../../../src/utils/proofOfOwnership/proofOfOwnership.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAKnD;;GAEG;AACH,eAAO,MAAM,iCAAiC,iCAAiC,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,6BAA6B;;;;;;EAGxC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,KAAK,CACzC,OAAO,6BAA6B,CACrC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sCAAsC;;;;;;EAGjD,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG,KAAK,CAClD,OAAO,sCAAsC,CAC9C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wCAAwC;;;;;;;;;;;;;;;;EAEnD,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG,KAAK,CACpD,OAAO,wCAAwC,CAChD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kCAAkC;;;;;;EAG7C,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,KAAK,CAC9C,OAAO,kCAAkC,CAC1C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gCAAgC;;;;;;EAG3C,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,KAAK,CAC5C,OAAO,gCAAgC,CACxC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uCAAuC;;;;;;QAGlD,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,iCAAiC,GAAG,KAAK,CACnD,OAAO,uCAAuC,CAC/C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mCAAmC;;;;;;;;;;;;;;;;;;;;;;EAE9C,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,KAAK,CAC/C,OAAO,mCAAmC,CAC3C,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,MAAM,GACd,uBAAuB,CA2BzB"}
@@ -0,0 +1,85 @@
1
+ import { array, nonempty, object, string, union } from "@metamask/superstruct";
2
+ import { UuidStruct } from "../uuidStruct/uuidStruct.mjs";
3
+ /**
4
+ * Prefix for proof-of-ownership messages signed by network snaps.
5
+ */
6
+ export const PROOF_OF_OWNERSHIP_MESSAGE_PREFIX = 'metamask:proof-of-ownership:';
7
+ /**
8
+ * Validates parsed proof-of-ownership message fields.
9
+ */
10
+ export const ProofOfOwnershipMessageStruct = object({
11
+ nonce: nonempty(string()),
12
+ address: nonempty(string()),
13
+ });
14
+ /**
15
+ * Validates one proof-of-ownership batch request item.
16
+ */
17
+ export const ProofOfOwnershipBatchRequestItemStruct = object({
18
+ accountId: UuidStruct,
19
+ message: string(),
20
+ });
21
+ /**
22
+ * Validates proof-of-ownership batch request params.
23
+ */
24
+ export const ProofOfOwnershipBatchRequestParamsStruct = object({
25
+ items: array(ProofOfOwnershipBatchRequestItemStruct),
26
+ });
27
+ /**
28
+ * Validates one successful proof-of-ownership batch result.
29
+ */
30
+ export const ProofOfOwnershipBatchSuccessStruct = object({
31
+ accountId: UuidStruct,
32
+ signature: string(),
33
+ });
34
+ /**
35
+ * Validates one failed proof-of-ownership batch result.
36
+ */
37
+ export const ProofOfOwnershipBatchErrorStruct = object({
38
+ accountId: UuidStruct,
39
+ error: nonempty(string()),
40
+ });
41
+ /**
42
+ * Validates one proof-of-ownership batch result.
43
+ */
44
+ export const ProofOfOwnershipBatchItemResponseStruct = union([
45
+ ProofOfOwnershipBatchSuccessStruct,
46
+ ProofOfOwnershipBatchErrorStruct,
47
+ ]);
48
+ /**
49
+ * Validates a proof-of-ownership batch response.
50
+ */
51
+ export const ProofOfOwnershipBatchResponseStruct = object({
52
+ results: array(ProofOfOwnershipBatchItemResponseStruct),
53
+ });
54
+ /**
55
+ * Parses a plaintext proof-of-ownership message in the format
56
+ * `metamask:proof-of-ownership:{nonce}:{address}`.
57
+ *
58
+ * Address validity is intentionally not checked here because it is
59
+ * chain-specific. Callers should validate the returned address with the
60
+ * relevant network/address validator.
61
+ *
62
+ * @param message - The plaintext message to parse.
63
+ * @returns The parsed nonce and address.
64
+ * @throws Error if the message format is invalid.
65
+ */
66
+ export function parseProofOfOwnershipMessage(message) {
67
+ if (!message.startsWith(PROOF_OF_OWNERSHIP_MESSAGE_PREFIX)) {
68
+ throw new Error(`Message must start with "${PROOF_OF_OWNERSHIP_MESSAGE_PREFIX}"`);
69
+ }
70
+ const remainder = message.slice(PROOF_OF_OWNERSHIP_MESSAGE_PREFIX.length);
71
+ const separatorIndex = remainder.lastIndexOf(':');
72
+ if (separatorIndex === -1) {
73
+ throw new Error('Message must follow the format "metamask:proof-of-ownership:{nonce}:{address}"');
74
+ }
75
+ const nonce = remainder.slice(0, separatorIndex);
76
+ const address = remainder.slice(separatorIndex + 1);
77
+ if (nonce.length === 0) {
78
+ throw new Error('Message must include a non-empty nonce');
79
+ }
80
+ if (address.length === 0) {
81
+ throw new Error('Message must include a non-empty address');
82
+ }
83
+ return { nonce, address };
84
+ }
85
+ //# sourceMappingURL=proofOfOwnership.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proofOfOwnership.mjs","sourceRoot":"","sources":["../../../src/utils/proofOfOwnership/proofOfOwnership.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B;AAE/E,OAAO,EAAE,UAAU,EAAE,qCAAiC;AAEtD;;GAEG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,8BAA8B,CAAC;AAEhF;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,MAAM,CAAC;IAClD,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IACzB,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;CAC5B,CAAC,CAAC;AASH;;GAEG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,MAAM,CAAC;IAC3D,SAAS,EAAE,UAAU;IACrB,OAAO,EAAE,MAAM,EAAE;CAClB,CAAC,CAAC;AASH;;GAEG;AACH,MAAM,CAAC,MAAM,wCAAwC,GAAG,MAAM,CAAC;IAC7D,KAAK,EAAE,KAAK,CAAC,sCAAsC,CAAC;CACrD,CAAC,CAAC;AASH;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,MAAM,CAAC;IACvD,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,MAAM,EAAE;CACpB,CAAC,CAAC;AASH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,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { array, nonempty, object, string, union } from '@metamask/superstruct';\n\nimport { UuidStruct } from '../uuidStruct/uuidStruct';\n\n/**\n * Prefix for proof-of-ownership messages signed by network snaps.\n */\nexport const PROOF_OF_OWNERSHIP_MESSAGE_PREFIX = 'metamask:proof-of-ownership:';\n\n/**\n * Validates parsed proof-of-ownership message fields.\n */\nexport const ProofOfOwnershipMessageStruct = object({\n nonce: nonempty(string()),\n address: nonempty(string()),\n});\n\n/**\n * Parsed proof-of-ownership message fields.\n */\nexport type ProofOfOwnershipMessage = Infer<\n typeof ProofOfOwnershipMessageStruct\n>;\n\n/**\n * Validates one proof-of-ownership batch request item.\n */\nexport const ProofOfOwnershipBatchRequestItemStruct = object({\n accountId: UuidStruct,\n message: string(),\n});\n\n/**\n * One proof-of-ownership batch request item.\n */\nexport type ProofOfOwnershipBatchRequestItem = Infer<\n typeof ProofOfOwnershipBatchRequestItemStruct\n>;\n\n/**\n * Validates proof-of-ownership batch request params.\n */\nexport const ProofOfOwnershipBatchRequestParamsStruct = object({\n items: array(ProofOfOwnershipBatchRequestItemStruct),\n});\n\n/**\n * Proof-of-ownership batch request params.\n */\nexport type ProofOfOwnershipBatchRequestParams = Infer<\n typeof ProofOfOwnershipBatchRequestParamsStruct\n>;\n\n/**\n * Validates one successful proof-of-ownership batch result.\n */\nexport const ProofOfOwnershipBatchSuccessStruct = object({\n accountId: UuidStruct,\n signature: string(),\n});\n\n/**\n * One successful proof-of-ownership batch result.\n */\nexport type ProofOfOwnershipBatchSuccess = Infer<\n typeof ProofOfOwnershipBatchSuccessStruct\n>;\n\n/**\n * Validates one failed proof-of-ownership batch result.\n */\nexport const ProofOfOwnershipBatchErrorStruct = object({\n accountId: UuidStruct,\n error: nonempty(string()),\n});\n\n/**\n * One failed proof-of-ownership batch result.\n */\nexport type ProofOfOwnershipBatchError = Infer<\n typeof ProofOfOwnershipBatchErrorStruct\n>;\n\n/**\n * Validates one proof-of-ownership batch result.\n */\nexport const ProofOfOwnershipBatchItemResponseStruct = union([\n ProofOfOwnershipBatchSuccessStruct,\n ProofOfOwnershipBatchErrorStruct,\n]);\n\n/**\n * One proof-of-ownership batch result.\n */\nexport type ProofOfOwnershipBatchItemResponse = Infer<\n typeof ProofOfOwnershipBatchItemResponseStruct\n>;\n\n/**\n * Validates a proof-of-ownership batch response.\n */\nexport const ProofOfOwnershipBatchResponseStruct = object({\n results: array(ProofOfOwnershipBatchItemResponseStruct),\n});\n\n/**\n * Proof-of-ownership batch response shape.\n */\nexport type ProofOfOwnershipBatchResponse = Infer<\n typeof ProofOfOwnershipBatchResponseStruct\n>;\n\n/**\n * Parses a plaintext proof-of-ownership message in the format\n * `metamask:proof-of-ownership:{nonce}:{address}`.\n *\n * Address validity is intentionally not checked here because it is\n * chain-specific. Callers should validate the returned address with the\n * relevant network/address validator.\n *\n * @param message - The plaintext message to parse.\n * @returns The parsed nonce and address.\n * @throws Error if the message format is invalid.\n */\nexport function parseProofOfOwnershipMessage(\n message: string,\n): ProofOfOwnershipMessage {\n if (!message.startsWith(PROOF_OF_OWNERSHIP_MESSAGE_PREFIX)) {\n throw new Error(\n `Message must start with \"${PROOF_OF_OWNERSHIP_MESSAGE_PREFIX}\"`,\n );\n }\n\n const remainder = message.slice(PROOF_OF_OWNERSHIP_MESSAGE_PREFIX.length);\n const separatorIndex = remainder.lastIndexOf(':');\n if (separatorIndex === -1) {\n throw new Error(\n 'Message must follow the format \"metamask:proof-of-ownership:{nonce}:{address}\"',\n );\n }\n\n const nonce = remainder.slice(0, separatorIndex);\n const address = remainder.slice(separatorIndex + 1);\n\n if (nonce.length === 0) {\n throw new Error('Message must include a non-empty nonce');\n }\n\n if (address.length === 0) {\n throw new Error('Message must include a non-empty address');\n }\n\n return { nonce, address };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/snap-networks-utils",
3
- "version": "1.0.0-preview-e7a796a2",
3
+ "version": "1.0.0-preview-2aa5deb",
4
4
  "description": "Shared utilities for MetaMask network snaps",
5
5
  "keywords": [
6
6
  "Ethereum",