Skip to content

Commit

Permalink
docs: update typedoc
Browse files Browse the repository at this point in the history
  • Loading branch information
jeasonstudio committed May 7, 2024
1 parent b3e012b commit c44b942
Show file tree
Hide file tree
Showing 15 changed files with 214 additions and 193 deletions.
133 changes: 53 additions & 80 deletions documents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,119 +51,92 @@ $ npm install @ordjs/runestone

### Runestone

```javascript
import { Runestone } from '@ordjs/runestone';
const fromHexString = (hexString) =>
Uint8Array.from(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
Rune protocol messages, called runestones, are stored in Bitcoin transaction outputs.

const toHexString = (bytes) =>
bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
#### Decipher Runestones

```typescript
import { Runestone, Transaction } from '@ordjs/runestone';

// decipher
// See https://mempool.space/tx/2bb85f4b004be6da54f766c17c1e855187327112c231ef2ff35ebad0ea67c69e
const tx = {
const tx: Transaction = {
output: [{
// // OP_RETURN OP_PUSHNUM_13 ...
script_pubkey: fromHexString('6a5d1f02010480bbb180c5ddf4ede90303a40805b5e9070680809dd085bedd031601'),
script_pubkey: '6a5d1f02010480bbb180c5ddf4ede90303a40805b5e9070680809dd085bedd031601',
value: 0,
}],
};

const runestone = Runestone.decipher(tx);
console.log(JSON.stringify(runestone.toString()));
/*
{
"edicts": [],
"etching": {
"divisibility": 2,
"premine": 11000000000,
"rune": {
"value": 67090369340599845000
},
"spacers": 7967,
"symbol": "ᚠ",
"terms": {
"amount": 100,
"cap": 1111111,
"height": {
"start": null,
"end": null
},
"offset": {
"start": null,
"end": null
}
},
"turbo": true
},
"mint": null,
"pointer": null
}
*/

// encipher
console.log(toHexString(runestone.encipher()));
// 6a5d21020704b5e1d8e1c8eeb788a3070102039f3e05a02d0680dc9afd280a6408c7e843
// runestone.divisibility => 2
// runestone.premine => 11000000000
// runestone.symbol => ᚠ
// runestone.terms.amount => 100
```

### Rune ID
#### Encipher Runestones

```javascript
import { RuneId } from '@ordjs/runestone';
To deploy a new rune ticker, this will require a commitment in an input script.

const runeId = new RuneId(840000n, 1);
```typescript
import { Runestone, Etching, SpacedRune, Terms } from '@ordjs/runestone';

console.log('runeId:', runeId.toString(), runeId.block, runeId.tx); // 840000:1 840000n 1
console.log('delta:', runeId.delta(new RuneId(840001n, 10000)).start); // 1n
console.log('next:', runeId.next(1n, 1).toString()); // 840001:1
console.log(RuneId.fromString('840000:1').toString()); // 840000:1
```
const etching = new Etching(SpacedRune.fromString('HI•JEASON'));
etching.terms = new Terms(69n, 420n);
etching.divisibility = 0;
etching.premine = 0n;
etching.symbol = '$';

const runestone = new Runestone();
runestone.etching = etching;

### Rune
console.log(runestone.encipher());
// 6a5d16020704b7fcb396fa0101000302052406000a4508a403
// send runestone.encipher() to the blockchain
```

```javascript
import { Rune } from '@ordjs/runestone';
To mint `UNCOMMON•GOODS`:

const rune = new Rune(67090369340599840949n);
```typescript
import { Runestone, RuneId } from '@ordjs/runestone';

console.log('value:', rune.value); // 67090369340599840949n
console.log('isReserved:', rune.isReserved()); // false
console.log('name:', rune.toString()); // ZZZZZFEHUZZZZZ
console.log('commitment:', rune.commitment());
// Uint8Array(9) [181, 48, 54, 140, 116, 223, 16, 163, 3]
const runestone = new Runestone();
runestone.mint = new RuneId(1n, 0);

console.log(Rune.firstRuneHeight('main')); // 840000
console.log(Rune.fromString('ZZZZZFEHUZZZZZ').value); // 67090369340599840949n
console.log(runestone.encipher());
// 6a5d0414011400
// send runestone.encipher() to the blockchain
```

### Spaced Rune
Transfer 10 `UNCOMMON•GOODS` to output 1:

```javascript
import { SpacedRune, Rune } from '@ordjs/runestone';
```typescript
import { Runestone, Edict, RuneId } from '@ordjs/runestone';

const rune = new Rune(67090369340599840949n);
const spacedRune = new SpacedRune(rune, 7967);
const edict = new Edict(new RuneId(1n, 0), 10n, 1);
const runestone = new Runestone();
runestone.edicts = [edict];

console.log('spaced rune:', spacedRune.toString()); // Z•Z•Z•Z•Z•FEHU•Z•Z•Z•Z•Z
console.log(
'rune value:',
SpacedRune.fromString('Z•Z•Z•Z•Z•FEHU•Z•Z•Z•Z•Z').rune.value // 67090369340599840949n
);
console.log(
'rune spacers:',
SpacedRune.fromString('Z•Z•Z•Z•Z•FEHU•Z•Z•Z•Z•Z').spacers // 7967
);
console.log(runestone.encipher());
// 6a5d050001000a01
// send runestone.encipher() to the blockchain
```

## Use in Browser

We provide the output format of ESM bundles for easy use in browsers directly:

```html
<script type="module">
import { Rune } from 'https://esm.sh/@ordjs/runestone@latest/bundle';
const rune = new Rune(1n);
console.log(rune.toString());
import { Runestone } from 'https://esm.sh/@ordjs/runestone/bundle';
const rs = Runestone.decipher({...});
console.log(JSON.stringify(rs));
</script>
```

For more usage, please refer to the [examples](/examples/) directory.

## License

[MIT](./LICENSE)
12 changes: 6 additions & 6 deletions documents/classes/Edict.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#### Defined in

index.d.ts:53
index.d.ts:63

## Properties

Expand All @@ -49,7 +49,7 @@ index.d.ts:53

#### Defined in

index.d.ts:60
index.d.ts:70

___

Expand All @@ -59,7 +59,7 @@ ___

#### Defined in

index.d.ts:63
index.d.ts:73

___

Expand All @@ -69,7 +69,7 @@ ___

#### Defined in

index.d.ts:66
index.d.ts:76

## Methods

Expand All @@ -83,7 +83,7 @@ index.d.ts:66

#### Defined in

index.d.ts:47
index.d.ts:57

___

Expand All @@ -97,4 +97,4 @@ ___

#### Defined in

index.d.ts:57
index.d.ts:67
36 changes: 18 additions & 18 deletions documents/classes/Etching.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,41 @@

### constructor

**new Etching**(`etching?`): [`Etching`](Etching.md)
**new Etching**(`spaced_rune`): [`Etching`](Etching.md)

#### Parameters

| Name | Type |
| :------ | :------ |
| `etching?` | [`Etching`](Etching.md) |
| `spaced_rune` | [`SpacedRune`](SpacedRune.md) |

#### Returns

[`Etching`](Etching.md)

#### Defined in

index.d.ts:75
index.d.ts:85

## Properties

### divisibility

`Readonly` **divisibility**: `undefined` \| `number`
**divisibility**: `number`

#### Defined in

index.d.ts:86
index.d.ts:96

___

### premine

`Readonly` **premine**: `undefined` \| `bigint`
**premine**: `bigint`

#### Defined in

index.d.ts:89
index.d.ts:99

___

Expand All @@ -72,7 +72,7 @@ ___

#### Defined in

index.d.ts:92
index.d.ts:102

___

Expand All @@ -82,37 +82,37 @@ ___

#### Defined in

index.d.ts:95
index.d.ts:105

___

### symbol

`Readonly` **symbol**: `undefined` \| `string`
**symbol**: `string`

#### Defined in

index.d.ts:98
index.d.ts:108

___

### terms

`Readonly` **terms**: `undefined` \| [`Terms`](Terms.md)
**terms**: [`Terms`](Terms.md)

#### Defined in

index.d.ts:101
index.d.ts:111

___

### turbo

`Readonly` **turbo**: `boolean`
**turbo**: `boolean`

#### Defined in

index.d.ts:104
index.d.ts:114

## Methods

Expand All @@ -126,7 +126,7 @@ index.d.ts:104

#### Defined in

index.d.ts:71
index.d.ts:81

___

Expand All @@ -140,7 +140,7 @@ ___

#### Defined in

index.d.ts:79
index.d.ts:89

___

Expand All @@ -154,4 +154,4 @@ ___

#### Defined in

index.d.ts:83
index.d.ts:93
19 changes: 15 additions & 4 deletions documents/classes/Range.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@

### constructor

**new Range**(): [`Range`](Range.md)
**new Range**(`start?`, `end?`): [`Range`](Range.md)

#### Parameters

| Name | Type |
| :------ | :------ |
| `start?` | `bigint` |
| `end?` | `bigint` |

#### Returns

[`Range`](Range.md)

#### Defined in

index.d.ts:124

## Properties

### end
Expand All @@ -35,7 +46,7 @@

#### Defined in

index.d.ts:112
index.d.ts:127

___

Expand All @@ -45,7 +56,7 @@ ___

#### Defined in

index.d.ts:115
index.d.ts:130

## Methods

Expand All @@ -59,4 +70,4 @@ index.d.ts:115

#### Defined in

index.d.ts:109
index.d.ts:119
Loading

0 comments on commit c44b942

Please sign in to comment.