Skip to content

Commit

Permalink
fix: add browser usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Mar 8, 2021
1 parent 46fe419 commit 1d9de89
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ This specification is only a draft at this stage and has not been submitted.
- [Advanced: Parse a Condition](#advanced-parse-a-condition)
- [Advanced: Parse and Reserialize a THRESHOLD-SHA-256 Fulfillment](#advanced-parse-and-reserialize-a-threshold-sha-256-fulfillment)
- [Advanced: Manually Create a Condition](#advanced-manually-create-a-condition)
- [In browser environment](#in-browser-environment)

## API Documentation

Expand Down Expand Up @@ -320,3 +321,25 @@ myCondition.setCost(0)
console.log(myCondition.serializeUri())
// prints 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
```

### In browser environment

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CryptoConditions</title>
</head>
<body>
<script src="https://unpkg.com/[email protected]/dist/browser/CryptoConditions.window.min.js"></script>
<script>
const conditionUri = 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
const validationResult = CryptoConditions.validateCondition(condition)
console.log(`Condition ${conditionUri} is valid ? ${validationResult}`)
alert(JSON.stringify(CryptoConditions.Condition.fromUri(conditionUri), null, 2))
</script>
</body>
</html>
```
22 changes: 22 additions & 0 deletions docs/README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,25 @@ myCondition.setCost(0)
console.log(myCondition.serializeUri())
// prints 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
```

### In browser environment

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CryptoConditions</title>
</head>
<body>
<script src="https://unpkg.com/[email protected]/dist/browser/CryptoConditions.window.min.js"></script>
<script>
const conditionUri = 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
const validationResult = CryptoConditions.validateCondition(condition)
console.log(`Condition ${conditionUri} is valid ? ${validationResult}`)
alert(JSON.stringify(CryptoConditions.Condition.fromUri(conditionUri), null, 2))
</script>
</body>
</html>
```

0 comments on commit 1d9de89

Please sign in to comment.