SIP-8: Snap Locations
| Author | Olaf Tomalka |
|---|---|
| Discussions-To | https://github.com/MetaMask/SIPs/discussions/75 |
| Status | Implementation |
| Created | 2022-11-03 |
Table of Contents
Abstract
A specification of URIs the DApp can use under which the wallet looks for snaps. It describes location URIs which can be used to locate snap as well as specifying how to access relative files.
Motivation
Currently Snap IDs are used both as the unique identifier as well as location to look for a snap. This introduces weird behavior where a snap installed from different places (such as npm and http) with the same code is different while different snaps from one location (such as multiple deployments from http://localhost:8080) are treated as single continuously updated snap and share persistent state.
This SIP is part of separating Snap IDs into location and a unique identifier.
Specification
Such sections are considered non-normative.
Language
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” written in uppercase in this document are to be interpreted as described in RFC 2119
Snap Location
The location of a snap MUST be an URI as defined in RFC-3986.
URI consists of a
scheme,authorityand apath, which we use throughout this SIP.
Supported schemes
npm- The snap SHALL be searched for using registry.npmjs.com protocol.httpsSHALL be used as the underlying transport protocol.- The
authoritypart of the URI SHALL indicate the npmjs-like registry to use. TheauthorityMAY be omitted and the default https://registry.npmjs.com SHALL be used instead. - The
pathrepresents the package’s id namespaced to the registry. The wallet SHALL search forpackage.jsonin the root directory of the package. All files referenced inpackage.jsonSHALL be searched for relative to the root directory of the package.
- The
http/https- Thepackage.jsonMUST be under that URL. All files referenced inpackage.jsonSHALL be searched for relative to the path ofpackage.jsonusing relative URL resolution as described by RFC 1808.ipfs- TheauthorityMUST be an IPFS CID that is also a directory. The wallet SHALL search forpackage.jsonin root of that directory. All files referenced inpackage.jsonSHALL be looked relative to the root directory.
Test vectors
NPM
npm:my-snapscheme-npmauthority-https://registry.npmjs.compath-my-snap
npm://root@my-registry.com:8080/my-snapscheme-npmauthority-https://root@my-registry.com:8080path-my-snap
HTTP / HTTPS
Test vectors for HTTP are considered the same except the differing scheme
https://localhost:8080scheme-httpsauthority-localhost:8080path- (zero-length)package.json:main: "dist/index.js"-https://localhost:8080/dist/index.js
https://my-host.com/my-snapscheme-httpsauthority-my-host.compath-my-snappackage.json:main: "dist/index.js"-https://my-host.com/dist/index.js
https://my-host.com/my-snap/scheme-httpsauthority-my-host.compath-my-snap/package.json:main: "dist/index.js"-https://my-host.com/my-snap/dist/index.js
IPFS
ipfs://bafybeifpaez32hlrz5tmr7scndxtjgw3auuloyuyxblynqmjw5saapewmuscheme-ipfsauthority-bafybeifpaez32hlrz5tmr7scndxtjgw3auuloyuyxblynqmjw5saapewmupath- (zero-length)package.json:main: "dist/index.js"-ipfs://bafybeifpaez32hlrz5tmr7scndxtjgw3auuloyuyxblynqmjw5saapewmu/dist/index.js
Copyright
Copyright and related rights waived via CC0.
Citation
Please cite this document as:
Olaf Tomalka, "SIP-8: Snap Locations [DRAFT]," Snaps Improvement Proposals, no. 8, November 2022. [Online serial]. Available: https://github.com/MetaMask/SIPs/blob/master/SIPS/sip-8.md