Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 91 additions & 14 deletions specification/flows/section/algorithms.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ <h4>Wallet address request</h4>
</li>
</ol>
</li>
<li>
If |details| is null, return failure.
</li>
<li>
Return |details|.
</li>
Expand Down Expand Up @@ -173,7 +176,7 @@ <h4>Outgoing payment and quote grant request</h4>
</li>
<li>
Perform a [=fetch request=] with |request| and with |processResponseConsumeBody| set to
the following steps, given a [=response=] and |response|'s [=request/body=] |responseBody|:
the following steps, given a [=response=] |response| and |response|'s [=response/body=] |responseBody|:
<ol>
<li>
Let |json| be the result of [=extract the JSON fetch response=] from |response| and |responseBody|.
Expand All @@ -189,6 +192,12 @@ <h4>Outgoing payment and quote grant request</h4>
</li>
</ol>
</li>
<li>
If |grant| is null, return failure.
</li>
<li>
Return |grant|.
</li>
</ol>
</div>

Expand Down Expand Up @@ -335,7 +344,7 @@ <h4>Incoming payment grant request</h4>
<li>Let |grant| be null.</li>
<li>
Perform a [=fetch request=] with |request| and with |processResponseConsumeBody| set to the following steps,
given a [=response=] and |response|'s [=request/body=] |responseBody|:
given a [=response=] |response| and |response|'s [=response/body=] |responseBody|:
<ol>
<li>
Let |json| be the result of [=extract the JSON fetch response=] from |response| and |responseBody|.
Expand Down Expand Up @@ -443,27 +452,70 @@ <h4>Continue grant request</h4>
<li>
Run the [=generate an HTTP message signature=] algorithm on |request| with |accessToken|.
</li>
<li>Let |grant| be null.</li>
<li>Let |result| be failure.</li>
<li>
Perform a [=fetch request=] with |request| and with |processResponseConsumeBody| set to the following steps,
given a [=response=] |response| with [=response/body=] |responseBody|:
<ol>
<li>
If |response| is a [=network error=], its [=response/status=] is `429`, or its [=response/status=]
is in the range 500 to 599, inclusive, set |result| to `"retry"` and abort these steps.
</li>
<li>
If |response|'s [=response/status=] is not an [=ok status=]:
<ol>
<li>
Let |errorJson| be null.
</li>
<li>
If |responseBody| is a [=byte sequence=], set |errorJson| to the result of
[=parse JSON bytes to an infra value=] passing |responseBody|. If this throws an exception,
set |errorJson| to null.
<p class="note">
An error response is not necessarily JSON, for example an HTML error page from a proxy.
</p>
</li>
<li data-cite="infra">
If |errorJson| is a [=map=] and either |errorJson|["error"] is the string `"too_fast"`, or
|errorJson|["error"] is a [=map=] whose "code" member is the string `"too_fast"`,
set |result| to `"retry"`.
<p class="note">
<a data-cite="GNAP#name-error-response">GNAP</a> allows the error to be either a string code or
an object with a `code` member, such as <code>{"error": {"code": "too_fast"}}</code>.
</p>
</li>
<li>Abort these steps.</li>
</ol>
<p class="note">
Any other error response, such as a <a data-cite="GNAP#name-error-response">GNAP error</a> with
code `user_denied`, `request_denied`, `invalid_continuation` or `expired`, leaves |result| as failure.
</p>
</li>
<li>
Let |json| be the result of [=extract the JSON fetch response=] from |response| and |responseBody|.
</li>
<li>
Convert |json| to a {{ PendingGrant }} or {{ Grant }}, |grantResponse|.
If |json| has an `access_token` member, convert |json| to a {{ Grant }}, |grantResponse:Grant|.
Otherwise, convert |json|["continue"] to a {{ Continue }}, |grantResponse:Continue|.
<p class="note">
The continuation request can return either a {{ PendingGrant }} or a {{ Grant }}.
A finalized grant includes an access token. A grant that is still pending only returns a new
continuation handle, and does not necessarily repeat the {{PendingGrant/interact}} member, so
it is not converted to a {{PendingGrant}}.
</p>
</li>
<li>
If one of the previous two steps threw an exception, return failure.
If one of the previous two steps threw an exception, abort these steps.
</li>
<li>Set |grant| to |grantResponse|.</li>
<li>Set |result| to |grantResponse|.</li>
</ol>
</li>
<li>Return |grant|.</li>
<li>
Return |result|.
<p class="note">
The result is a {{ Grant }} if the grant was finalized, a {{ Continue }} if the grant is still pending,
`"retry"` if the request failed for a transient reason and can be repeated, or failure otherwise.
</p>
</li>
</ol>
</div>
</section>
Expand All @@ -472,7 +524,8 @@ <h4>Continue grant request</h4>
<h4>Cancel grant request</h4>
<p>The cancel grant request, refers to the <a data-cite="opas/operations/delete-continue#">Open Payments cancel grant request</a>.</p>
<div class="algorithm">
When asked to <dfn>send a cancel grant request</dfn>, given |continueUri|, |accessToken|, perform the following steps.
When asked to <dfn>send a cancel grant request</dfn>, given |continueUri|, |accessToken| and an optional
boolean |notifyUser:boolean| (default true), perform the following steps.
<ol>
<li>
Let |uri| be the result of running [=URL parser=] with |continueUri|.
Expand Down Expand Up @@ -512,7 +565,8 @@ <h4>Cancel grant request</h4>
Perform a [=fetch request=] with |request|, given a [=response=]:
<ol>
<li>
If {{"NetworkError"}} is thrown, notify the user that the browser could not cancel the grant.
If {{"NetworkError"}} is thrown and |notifyUser| is true, notify the user that the browser could not
cancel the grant.
</li>
<li>
If the [=status=] is `204`, the grant was successfully canceled and the storage can be cleared.
Expand Down Expand Up @@ -677,7 +731,7 @@ <h4>Create incoming payment</h4>
</li>
<li>
Perform a [=fetch request=] with |request| and with |processResponseConsumeBody| set to the following steps,
given a [=response=] and |response|'s [=request/body=] |responseBody|:
given a [=response=] |response| and |response|'s [=response/body=] |responseBody|:
<ol>
<li>
Let |json| be the result of [=extract the JSON fetch response=] from |response| and |responseBody|.
Expand Down Expand Up @@ -839,24 +893,47 @@ <h3>Helper algorithms</h3>
<h4>Fetch request</h4>
<div class="algorithm">
To perform a <dfn>fetch request</dfn> given a [=request=] |request| and
an algorithm |processResponseConsumeBody|, execute the following steps:
an algorithm |processResponseConsumeBody|, perform the following steps:
<ol>
<li>
Let |done:boolean| be false.
</li>
<li>
[=Queue a global task=] on the [=networking task source=] to [=fetch=] |request|
with [=fetch/processResponseEndOfBody=] set to |processResponseConsumeBody|.
with [=fetch/processResponseConsumeBody=] set to the following steps, given a [=response=] |response|
and null, failure, or a [=byte sequence=] |responseBody|:
<ol>
<li>
Run |processResponseConsumeBody| given |response| and |responseBody|.
</li>
<li>
Set |done| to true.
</li>
</ol>
</li>
<li>
Wait until |done| is true.
</li>
</ol>
<p class="note">
Because this algorithm waits for the response to be processed, the calling algorithm can read any value
set by |processResponseConsumeBody| after this algorithm returns. Callers run [=in parallel=], so waiting
does not block the user interface. Returning from |processResponseConsumeBody| only ends those steps,
not the calling algorithm.
</p>
</div>
</section>

<section>
<h4>Extract JSON from fetch response</h4>
<div class="algorithm">
<p>To <dfn>extract the JSON fetch response</dfn> a [=response=] response:
<p>To <dfn>extract the JSON fetch response</dfn> given a [=response=] |response| and
null, failure, or a [=byte sequence=] |responseBody|, perform the following steps:
<ol>
<li>
If |response| is a [=network error=] or its [=status=] is not an [=ok status=], throw a new {{"NetworkError"}}.
</li>
<li>If |responseBody| is null or failure, throw a new {{"NetworkError"}}.</li>
<li>
Let |mimeType| be the result of [=header list/extract a MIME type=] from |response|'s [=header list=].
</li>
Expand Down
4 changes: 2 additions & 2 deletions specification/flows/section/session-flow.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ <h3>Session initiation</h3>
Let |websiteWalletAddress:DOMString| be the value of the {{HTMLLinkElement/href}} of |linkElement|.
</li>
<li>
Let |websiteWalletDetails:WalletAddressDetails?| be the result of [=send a wallet address request=] with |websiteWalletAddress|.
Let |websiteWalletDetails:WalletAddressDetails| be the result of [=send a wallet address request=] with |websiteWalletAddress|.
</li>
<li>
If |websiteWalletDetails| is null, return.
If |websiteWalletDetails| is failure, return.
</li>
<li>
Let |authKeys:AuthKeys?| be the result of [=get auth keys=].
Expand Down
27 changes: 8 additions & 19 deletions specification/flows/section/storage.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,19 @@ <h3>Storage operations</h3>
</div>

<div class="algorithm">
<p>To <dfn>store wallet credentials</dfn>, given |walletAddressDetails:WalletAddressDetails|:</p>
<p>To <dfn>store wallet connection</dfn>, given |walletAddressDetails:WalletAddressDetails|, |grant:Grant|
and |maxRateOfPay:DOMString|:</p>
<ol>
<li>Let |storage| be the result of [=get storage=].</li>
<li>Set |storage|'s {{Storage/wallet}} to |walletAddressDetails|.</li>
<li>Set |storage|'s {{Storage/grant}} to |grant|.</li>
<li>Set |storage|'s {{Storage/maxRateOfPay}} to |maxRateOfPay|.</li>
<li>[=Persist storage=] with |storage|.</li>
</ol>
<p class="note">
The wallet, grant and max rate of pay are persisted in a single step so that an interruption cannot leave
a partially stored wallet connection.
</p>
<p class="note">
Each invocation of this algorithm establishes a new wallet connection. Implementations
that track per-connection payment history SHOULD associate sessions and payments with
Expand All @@ -103,24 +110,6 @@ <h3>Storage operations</h3>
</p>
</div>

<div class="algorithm">
<p>To <dfn>store grant credentials</dfn>, given |grant:Grant|:</p>
<ol>
<li>Let |storage| be the result of [=get storage=].</li>
<li>Set |storage|'s {{Storage/grant}} to |grant|.</li>
<li>[=Persist storage=] with |storage|.</li>
</ol>
</div>

<div class="algorithm">
<p>To <dfn>store max rate of pay</dfn>, given |maxRateOfPay:DOMString|:</p>
<ol>
<li>Let |storage| be the result of [=get storage=].</li>
<li>Set |storage|'s {{Storage/maxRateOfPay}} to |maxRateOfPay|.</li>
<li>[=Persist storage=] with |storage|.</li>
</ol>
</div>

<div class="algorithm">
<p>To <dfn>update grant access token</dfn>, given |accessToken:DOMString|:</p>
<ol>
Expand Down
Loading